Commit 2f490c3e authored by James Clark's avatar James Clark
Browse files

flake8 and pylinted

parent 276523e3
Pipeline #83300 passed with stages
in 57 seconds
......@@ -44,6 +44,7 @@ MAX_CACHE_TRIES = 5
LOGGER = logging.getLogger('user')
def gps(unixtime):
"""
convert the unix time unix to GPS so we only have to register files which
......@@ -53,6 +54,7 @@ def gps(unixtime):
"""
return unixtime - EPOCH_DIFFERENCE
def setup_logger(logger):
"""
Configures logging information. Lifted from `rucio`.
......@@ -82,14 +84,15 @@ def setup_logger(logger):
color = '\033[36;1m'
else:
color = '\033[0m'
#pylint: disable=line-too-long
formatter = logging.Formatter('{0}%(asctime)s\t%(levelname)s\t%(message)s\033[0m'.format(color))
# pylint: disable=line-too-long
formatter = logging.Formatter('{0}%(asctime)s\t%(levelname)s\t%(message)s\033[0m'.format(color)) # noqa: E501
hdlr.setFormatter(formatter)
return fnc(*args)
return func
hdlr.emit = emit_decorator(hdlr.emit)
logger.addHandler(hdlr)
setup_logger(LOGGER)
......@@ -97,11 +100,12 @@ def signal_handler(sig, frame):
"""
Catch INTERRUPTs
"""
#pylint: disable=unused-argument
# pylint: disable=unused-argument
LOGGER.error('Interrupt received')
# Do some cleanup?
sys.exit(1)
def get_parser():
"""
Command line parser
......@@ -128,7 +132,8 @@ def get_parser():
"--allow-uploads",
default=False,
required=False,
help="""Test for file existence and attempt uploads""")
help="""Test for file existence and attempt
uploads""")
oparser.add_argument("--dry-run",
default=False,
......@@ -155,10 +160,15 @@ def get_parser():
To register a pair of files:
$ gwrucio_register_data -r H_HOFT_ER13.yml add-files H-H1_HOFT_C00-1164353536-4096.gwf H-H1_HOFT_C00-1164353536-4096.gwf
$ gwrucio_register_data -r H_HOFT_ER13.yml add-files H-H1_HOFT_C00.txt
H_HOFT_ER13.yml is a YAML file with:
where H-H1_HOFT_C00.txt looks something like,
```
/archive/frames/H-H1_HOFT_C00-1164353536-4096.gwf
/archive/frames/H-H1_HOFT_C00-1164353536-4096.gwf
```
H_HOFT_ER13.yml is a YAML file with
- dataset-name (section name, required)
- scope (required)
- RSE (required)
......@@ -182,13 +192,14 @@ Note: register a list of files from a text file:
add_files_parser.add_argument(dest="files",
nargs='+',
help="""Files for
registration""")
registration (text file list)""")
add_files_parser.add_argument("--file-infos",
type=str,
default=None,
required=False,
help="""File list with bytes, adler32, md5""")
help="""File list with bytes, adler32,
md5""")
add_files_parser.add_argument("--rset",
type=str,
......@@ -301,7 +312,8 @@ def list_file_infos(filename):
with open(filename, 'r') as finfo:
for line in finfo.readlines():
elem = line.split()
fileinfos[elem[0]] = {'bytes':int(elem[1]), 'adler32':elem[2], 'md5':elem[3]}
fileinfos[elem[0]] = {'bytes': int(elem[1]), 'adler32': elem[2],
'md5': elem[3]}
return fileinfos
......@@ -407,13 +419,15 @@ def daemon(aparser):
LOGGER.error('Max retries reached, aborting')
sys.exit(1)
else:
LOGGER.debug('Retry in %d s (%d/%d)', cache_try_interval,
ntry+1, MAX_CACHE_TRIES)
LOGGER.debug('Retry in %d s (%d/%d)',
cache_try_interval, ntry+1,
MAX_CACHE_TRIES)
time.sleep(cache_try_interval)
cache_try_interval *= 2
# If check enabled or if diskcache has updated, heck for new data
if force_check_cache or rsets[rset]['diskcache'].mtime() > last_check:
if force_check_cache or \
rsets[rset]['diskcache'].mtime() > last_check:
LOGGER.info("%s: looking for new data", rset)
......@@ -443,7 +457,8 @@ def daemon(aparser):
return SUCCESS
def inject_data(dataset_name, rset, rse_info, allow_uploads=False, dry_run=False):
def inject_data(dataset_name, rset, rse_info, allow_uploads=False,
dry_run=False):
"""
Execute the main registration loop
......@@ -503,7 +518,8 @@ def main():
command = commands.get(args.which)
# Print PID and write to file
LOGGER.info("%s lauched with PID %d", os.path.basename(__file__), os.getpid())
LOGGER.info("%s lauched with PID %d", os.path.basename(__file__),
os.getpid())
with open("{0}_pid".format(os.path.basename(__file__)), 'w') as pidfile:
pidfile.write(str(os.getpid()))
......@@ -514,5 +530,6 @@ def main():
LOGGER.info("total uptime: %-0.4f sec.", (time.time() - global_start_time))
return result
if __name__ == "__main__":
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment