diff options
author | tlatorre <tlatorre@uchicago.edu> | 2020-05-11 10:30:39 -0500 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2020-05-11 10:30:39 -0500 |
commit | 15fc972c89a4366a06755daeedaac52f91762ecd (patch) | |
tree | 9a5dbea7787cef9946473787e9a3996f24cd2898 /utils/submit-grid-jobs | |
parent | 651cbe5d261a6d29b4dec7c38b65c0eac5431363 (diff) | |
download | sddm-15fc972c89a4366a06755daeedaac52f91762ecd.tar.gz sddm-15fc972c89a4366a06755daeedaac52f91762ecd.tar.bz2 sddm-15fc972c89a4366a06755daeedaac52f91762ecd.zip |
update utils/ folder to make a python package called sddm
This commit adds an sddm python package to the utils/ folder. This allows me to
consolidate code used across all the various scripts. This package is now
installed by default to /home/tlatorre/local/lib/python2.7/site-packages so you
should add the following to your .bashrc file:
export PYTHONPATH=$HOME/local/lib/python2.7/site-packages/:$PYTHONPATH
before using the scripts installed to ~/local/bin.
Diffstat (limited to 'utils/submit-grid-jobs')
-rwxr-xr-x | utils/submit-grid-jobs | 161 |
1 files changed, 2 insertions, 159 deletions
diff --git a/utils/submit-grid-jobs b/utils/submit-grid-jobs index 85cf59a..919f17a 100755 --- a/utils/submit-grid-jobs +++ b/utils/submit-grid-jobs @@ -50,150 +50,11 @@ import subprocess import json import h5py import numpy as np - -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.logger import Logger +from sddm import which, splitext log = Logger() -# Next two functions are a backport of the shutil.which() function from Python -# 3.3 from Lib/shutil.py in the CPython code See -# https://github.com/python/cpython/blob/master/Lib/shutil.py. - -# 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 - CONDOR_TEMPLATE = \ """ # We need the job to run our executable script, with the @@ -230,24 +91,6 @@ INPUT_FILES = ["muE_water_liquid.txt","pmt_response_qoca_d2o_20060216.dat","rsp_ class MyTemplate(string.Template): delimiter = '@' -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 create_submit_file(filename, uuid, run, gtid, dir, dqxx_dir, particle_combo, max_time, priority): """ Creates a submit file and submits a job to the grid. |