Skip to content

Commit 2f07011

Browse files
committed
Cylc Review: support alternate home dir.
1 parent e43ea02 commit 2f07011

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed

bin/cylc-review

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ logs via an HTTP interface.
2323
2424
With no arguments, the status of the ad-hoc web service server is printed.
2525
26-
For 'cylc review start', if 'PORT' is not specified, port 8080 is used."""
27-
26+
For 'cylc review start', if 'PORT' is not specified, port 8080 is used.
27+
28+
If $CYLC_REVIEW_HOME is defined, look there for run directories instead of
29+
in user home directories. This can be used to view symlinked run directories
30+
directly when home directories are private. For example with symlinking as:
31+
/home/USER/cylc-run/WORKFLOW -> /project/PROJECT/USER/cylc-run/WORKFLOW
32+
set the environment variable as:
33+
CYLC_REVIEW_HOME=/project/PROJECT
34+
"""
2835

2936
import sys
3037

lib/cylc/review.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@
2323
2424
With no arguments, the status of the ad-hoc web service server is printed.
2525
26-
For 'cylc review start', if 'PORT' is not specified, port 8080 is used."""
26+
For 'cylc review start', if 'PORT' is not specified, port 8080 is used.
27+
28+
If $CYLC_REVIEW_HOME is defined, look there for run directories instead of
29+
in user home directories. This can be used to view symlinked run directories
30+
directly when home directories are private. For example with symlinking as:
31+
/home/USER/cylc-run/WORKFLOW -> /project/PROJECT/USER/cylc-run/WORKFLOW
32+
set the environment variable as:
33+
CYLC_REVIEW_HOME=/project/PROJECT
34+
"""
2735

2836
import cherrypy
2937
from fnmatch import fnmatch
@@ -883,14 +891,21 @@ def _check_dir_access(cls, path):
883891

884892
@staticmethod
885893
def _get_user_home(user):
886-
"""Return, e.g. ~/cylc-run/ for a cylc suite.
894+
"""Return user home dir.
895+
896+
If $CYLC_REVIEW_HOME is defined, use that; else normal home dir.
887897
888898
N.B. os.path.expanduser does not fail if ~user is invalid.
889899
890900
Raises:
891901
cherrypy.HTTPError(404)
892902
893903
"""
904+
if os.environ['CYLC_REVIEW_HOME']:
905+
return os.path.join(
906+
os.environ['CYLC_REVIEW_HOME'],
907+
str(user)
908+
)
894909
try:
895910
return pwd.getpwnam(user).pw_dir
896911
except KeyError:

lib/cylc/review_dao.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@
2929
"""Provide data access object to the suite runtime database for Cylc Review."""
3030

3131

32+
def get_prefix(user_name):
33+
"""Return user "home" dir under $CYLC_REVIEW_HOME, or else ~user_name."""
34+
if os.environ.get('CYLC_REVIEW_HOME', False) and user_name:
35+
prefix = os.path.join(
36+
os.environ['CYLC_REVIEW_HOME'],
37+
str(user_name)
38+
)
39+
else:
40+
prefix = "~"
41+
if user_name:
42+
prefix += user_name
43+
return prefix
44+
45+
3246
class CylcReviewDAO(object):
3347
"""Cylc Review data access object to the suite runtime database."""
3448

@@ -108,12 +122,11 @@ def _db_init(self, user_name, suite_name):
108122
"""Initialise a named CylcSuiteDAO database connection."""
109123
key = (user_name, suite_name)
110124
if key not in self.daos:
111-
prefix = "~"
112-
if user_name:
113-
prefix += user_name
114125
for name in [os.path.join("log", "db"), "cylc-suite.db"]:
115126
db_f_name = os.path.expanduser(os.path.join(
116-
prefix, os.path.join("cylc-run", suite_name, name)))
127+
get_prefix(user_name),
128+
os.path.join("cylc-run",
129+
suite_name, name)))
117130
self.daos[key] = CylcSuiteDAO(db_f_name, is_public=True)
118131
if os.path.exists(db_f_name):
119132
break
@@ -382,11 +395,8 @@ def _get_job_logs(self, user_name, suite_name, entries, entry_of):
382395
relevant entries of that cycle.
383396
Modify each entry in entries.
384397
"""
385-
prefix = "~"
386-
if user_name:
387-
prefix += user_name
388398
user_suite_dir = os.path.expanduser(os.path.join(
389-
prefix, os.path.join("cylc-run", suite_name)))
399+
get_prefix(user_name), os.path.join("cylc-run", suite_name)))
390400
try:
391401
fs_log_cycles = os.listdir(
392402
os.path.join(user_suite_dir, "log", "job"))
@@ -519,11 +529,8 @@ def get_suite_cycles_summary(
519529
integer_mode = row[0].isdigit()
520530
break
521531

522-
prefix = "~"
523-
if user_name:
524-
prefix += user_name
525532
user_suite_dir = os.path.expanduser(os.path.join(
526-
prefix, os.path.join("cylc-run", suite_name)))
533+
get_prefix(user_name), os.path.join("cylc-run", suite_name)))
527534
targzip_log_cycles = []
528535
try:
529536
for item in os.listdir(os.path.join(user_suite_dir, "log")):

0 commit comments

Comments
 (0)