-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from lsst-camera-dh/LSSTTD-1527_bot-data_py_re…
…tries Lssttd 1527 bot data py retries
- Loading branch information
Showing
2 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |