Skip to content

Commit

Permalink
Drop logic for non-installed use case (#1311)
Browse files Browse the repository at this point in the history
  • Loading branch information
wil93 authored Dec 26, 2024
1 parent c87fea7 commit 5c809ec
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 64 deletions.
39 changes: 8 additions & 31 deletions cms/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,37 +162,14 @@ def __init__(self):
self.max_jobs_per_user = 10
self.pdf_printing_allowed = False

# Installed or from source?
# We declare we are running from installed if the program was
# NOT invoked through some python flavor, and the file is in
# the prefix (or real_prefix to accommodate virtualenvs).
bin_path = os.path.join(os.getcwd(), sys.argv[0])
bin_name = os.path.basename(bin_path)
bin_is_python = bin_name in ["ipython", "python", "python3"]
bin_in_installed_path = bin_path.startswith(sys.prefix) or (
hasattr(sys, 'real_prefix')
and bin_path.startswith(sys.real_prefix))
self.installed = bin_in_installed_path and not bin_is_python

if self.installed:
self.log_dir = os.path.join("/", "var", "local", "log", "cms")
self.cache_dir = os.path.join("/", "var", "local", "cache", "cms")
self.data_dir = os.path.join("/", "var", "local", "lib", "cms")
self.run_dir = os.path.join("/", "var", "local", "run", "cms")
paths = [os.path.join("/", "usr", "local", "etc", "cms.conf"),
os.path.join("/", "etc", "cms.conf")]
else:
self.log_dir = "log"
self.cache_dir = "cache"
self.data_dir = "lib"
self.run_dir = "run"
paths = [os.path.join(".", "config", "cms.conf")]
if '__file__' in globals():
paths += [os.path.abspath(os.path.join(
os.path.dirname(__file__),
'..', 'config', 'cms.conf'))]
paths += [os.path.join("/", "usr", "local", "etc", "cms.conf"),
os.path.join("/", "etc", "cms.conf")]
self.log_dir = os.path.join("/", "var", "local", "log", "cms")
self.cache_dir = os.path.join("/", "var", "local", "cache", "cms")
self.data_dir = os.path.join("/", "var", "local", "lib", "cms")
self.run_dir = os.path.join("/", "var", "local", "run", "cms")
paths = [
os.path.join("/", "usr", "local", "etc", "cms.conf"),
os.path.join("/", "etc", "cms.conf"),
]

# Allow user to override config file path using environment
# variable 'CMS_CONFIG'.
Expand Down
5 changes: 0 additions & 5 deletions cms/service/ResourceService.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,6 @@ def _restart_services(self):
logger.info("Restarting (%s, %s)...",
service.name, service.shard)
command = os.path.join(BIN_PATH, "cms%s" % service.name)
if not config.installed:
command = os.path.join(
".",
"scripts",
"cms%s" % service.name)
args = [command, "%d" % service.shard]
if self.contest_id is not None:
args += ["-c", str(self.contest_id)]
Expand Down
3 changes: 0 additions & 3 deletions cmscontrib/loaders/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ def get_task(self, get_statement=True):
os.path.dirname(checker_src), "checker")
testlib_path = "/usr/local/include/cms"
testlib_include = os.path.join(testlib_path, "testlib.h")
if not config.installed:
testlib_path = os.path.join(os.path.dirname(__file__),
"polygon")
code = subprocess.call(["g++", "-x", "c++", "-O2", "-static",
"-DCMS", "-I", testlib_path,
"-include", testlib_include,
Expand Down
31 changes: 6 additions & 25 deletions cmsranking/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,13 @@ def __init__(self):
# Buffers
self.buffer_size = 100 # Needs to be strictly positive.

# File system.
# TODO: move to cmscommon as it is used both here and in cms/conf.py
bin_path = os.path.join(os.getcwd(), sys.argv[0])
bin_name = os.path.basename(bin_path)
bin_is_python = bin_name in ["ipython", "python", "python3"]
bin_in_installed_path = bin_path.startswith(sys.prefix) or (
hasattr(sys, 'real_prefix')
and bin_path.startswith(sys.real_prefix))
self.installed = bin_in_installed_path and not bin_is_python

self.web_dir = pkg_resources.resource_filename("cmsranking", "static")
if self.installed:
self.log_dir = os.path.join("/", "var", "local", "log",
"cms", "ranking")
self.lib_dir = os.path.join("/", "var", "local", "lib",
"cms", "ranking")
self.conf_paths = [os.path.join("/", "usr", "local", "etc",
"cms.ranking.conf"),
os.path.join("/", "etc", "cms.ranking.conf")]
else:
self.log_dir = os.path.join("log", "ranking")
self.lib_dir = os.path.join("lib", "ranking")
self.conf_paths = [os.path.join(".", "config", "cms.ranking.conf"),
os.path.join("/", "usr", "local", "etc",
"cms.ranking.conf"),
os.path.join("/", "etc", "cms.ranking.conf")]
self.log_dir = os.path.join("/", "var", "local", "log", "cms", "ranking")
self.lib_dir = os.path.join("/", "var", "local", "lib", "cms", "ranking")
self.conf_paths = [
os.path.join("/", "usr", "local", "etc", "cms.ranking.conf"),
os.path.join("/", "etc", "cms.ranking.conf"),
]

# Allow users to override config file path using environment
# variable 'CMS_RANKING_CONFIG'.
Expand Down

0 comments on commit 5c809ec

Please sign in to comment.