diff --git a/harnessed_jobs/BOT_acq/v0/producer_BOT_acq.py b/harnessed_jobs/BOT_acq/v0/producer_BOT_acq.py index 2732b8c..7fa79dc 100755 --- a/harnessed_jobs/BOT_acq/v0/producer_BOT_acq.py +++ b/harnessed_jobs/BOT_acq/v0/producer_BOT_acq.py @@ -13,7 +13,7 @@ import subprocess import pathlib import siteUtils - +from bot_acq_retry import copy_exposure_symlinks def copy_sequencer_files(): """ @@ -27,7 +27,7 @@ def copy_sequencer_files(): subprocess.check_call(command, shell=True) with open(json_file, 'r') as fd: seq_paths = json.load(fd) - for key, value in seq_paths.items(): + for _, value in seq_paths.items(): command = f'scp {value} .' print(command) subprocess.check_call(command, shell=True) @@ -49,9 +49,11 @@ def copy_sequencer_files(): shutil.copy(bot_eo_acq_cfg, os.path.join('.', outfile)) copy_sequencer_files() +skip = copy_exposure_symlinks() + +command = (f'/home/ccs/bot-data.py --symlink . --skip {skip} ' + f'--run {run_number} {bot_eo_acq_cfg}') -command = '/home/ccs/bot-data.py --symlink . --run {} {}'\ - .format(run_number, bot_eo_acq_cfg) subprocess.check_call(command, shell=True) pathlib.Path('PRESERVE_SYMLINKS').touch() diff --git a/python/bot_acq_retry.py b/python/bot_acq_retry.py new file mode 100644 index 0000000..6b62527 --- /dev/null +++ b/python/bot_acq_retry.py @@ -0,0 +1,28 @@ +import os +import glob + +def copy_exposure_symlinks(copy_links=True): + """ + If the current job execution is a retry, there will be a previous + working directory with symlinks to the successful BOT exposures. + This function finds the last working directory by sorting on the + activityId directory names, copies the exposure symlinks to the + current directory and returns the number of symlinks it made. + + If there is no previous working directory, zero is returned. + """ + current_dir = os.path.abspath('.').split('/')[-1] + try: + last_dir = sorted([_ for _ in glob.glob('../*') + if current_dir not in _])[-1] + except IndexError: + return 0 + + num_symlinks = 0 + for item in glob.glob(os.path.join(last_dir, '*_[0-9]*')): + if os.path.islink(item): + exposure_name = os.path.basename(item) + num_symlinks += 1 + if copy_links and not os.path.islink(exposure_name): + os.symlink(os.path.realpath(item), exposure_name) + return num_symlinks