aboutsummaryrefslogtreecommitdiff
path: root/utils/cat-grid-jobs
diff options
context:
space:
mode:
Diffstat (limited to 'utils/cat-grid-jobs')
-rwxr-xr-xutils/cat-grid-jobs157
1 files changed, 2 insertions, 155 deletions
diff --git a/utils/cat-grid-jobs b/utils/cat-grid-jobs
index 62dcd42..0755774 100755
--- a/utils/cat-grid-jobs
+++ b/utils/cat-grid-jobs
@@ -35,164 +35,11 @@ from datetime import datetime
import h5py
from os.path import join, split
from subprocess import check_call
-
-DEBUG = 0
-VERBOSE = 1
-NOTICE = 2
-WARNING = 3
-
-class Logger(object):
- """
- Simple logger class that I wrote for the SNO+ DAQ. Very easy to use:
-
- log = Logger()
- log.set_logfile("test.log")
- log.notice("blah")
- log.warn("foo")
-
- The log file format is taken from the Redis log file format which is really
- nice since it shows the exact time and severity of each log message.
- """
- def __init__(self):
- self.logfile = sys.stdout
- # by default, we log everything
- self.verbosity = DEBUG
-
- def set_verbosity(self, level):
- if isinstance(level, int):
- self.verbosity = level
- elif isinstance(level, basestring):
- if level == 'debug':
- self.verbosity = DEBUG
- elif level == 'verbose':
- self.verbosity = VERBOSE
- elif level == 'notice':
- self.verbosity = NOTICE
- elif level == 'warning':
- self.verbosity = WARNING
- else:
- raise ValueError("unknown loglevel '%s'" % level)
- else:
- raise TypeError("level must be a string or integer")
-
- def set_logfile(self, filename):
- self.logfile = open(filename, 'a')
-
- def debug(self, msg):
- self.log(DEBUG, msg)
-
- def verbose(self, msg):
- self.log(VERBOSE, msg)
-
- def notice(self, msg):
- self.log(NOTICE, msg)
-
- def warn(self, msg):
- self.log(WARNING, msg)
-
- def log(self, level, msg):
- if level < self.verbosity:
- return
-
- c = '.-*#'
- pid = os.getpid()
- now = datetime.now()
- buf = now.strftime('%d %b %H:%M:%S.%f')[:-3]
-
- self.logfile.write('%d:%s %c %s\n' % (pid, buf, c[level], msg))
- self.logfile.flush()
+from sddm import splitext, which
+from sddm.logger import Logger
log = Logger()
-# Check that a given file can be accessed with the correct mode.
-# Additionally check that `file` is not a directory, as on Windows
-# directories pass the os.access check.
-def _access_check(fn, mode):
- return (os.path.exists(fn) and os.access(fn, mode) and not os.path.isdir(fn))
-
-def which(cmd, mode=os.F_OK | os.X_OK, path=None):
- """Given a command, mode, and a PATH string, return the path which
- conforms to the given mode on the PATH, or None if there is no such
- file.
- `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
- of os.environ.get("PATH"), or can be overridden with a custom search
- path.
- """
- # If we're given a path with a directory part, look it up directly rather
- # than referring to PATH directories. This includes checking relative to the
- # current directory, e.g. ./script
- if os.path.dirname(cmd):
- if _access_check(cmd, mode):
- return cmd
- return None
-
- if path is None:
- path = os.environ.get("PATH", None)
- if path is None:
- try:
- path = os.confstr("CS_PATH")
- except (AttributeError, ValueError):
- # os.confstr() or CS_PATH is not available
- path = os.defpath
- # bpo-35755: Don't use os.defpath if the PATH environment variable is
- # set to an empty string
-
- # PATH='' doesn't match, whereas PATH=':' looks in the current directory
- if not path:
- return None
-
- path = path.split(os.pathsep)
-
- if sys.platform == "win32":
- # The current directory takes precedence on Windows.
- curdir = os.curdir
- if curdir not in path:
- path.insert(0, curdir)
-
- # PATHEXT is necessary to check on Windows.
- pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
- # See if the given file matches any of the expected path extensions.
- # This will allow us to short circuit when given "python.exe".
- # If it does match, only test that one, otherwise we have to try
- # others.
- if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
- files = [cmd]
- else:
- files = [cmd + ext for ext in pathext]
- else:
- # On other platforms you don't have things like PATHEXT to tell you
- # what file suffixes are executable, so just pass on cmd as-is.
- files = [cmd]
-
- seen = set()
- for dir in path:
- normdir = os.path.normcase(dir)
- if not normdir in seen:
- seen.add(normdir)
- for thefile in files:
- name = os.path.join(dir, thefile)
- if _access_check(name, mode):
- return name
- return None
-
-def splitext(path):
- """
- Like os.path.splitext() except it returns the full extension if the
- filename has multiple extensions, for example:
-
- splitext('foo.tar.gz') -> 'foo', '.tar.gz'
- """
- full_root, full_ext = os.path.splitext(path)
- while True:
- root, ext = os.path.splitext(full_root)
- if ext:
- full_ext = ext + full_ext
- full_root = root
- else:
- break
-
- return full_root, full_ext
-
def cat_grid_jobs(conn, output_dir):
zdab_cat = which("zdab-cat")