Skip to content

Commit

Permalink
add exclude_years function
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Jun 3, 2024
1 parent 42c16ed commit 8716c45
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
18 changes: 18 additions & 0 deletions py/desitransfer/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import re
import stat
import time
import pytz

MST = pytz.timezone('America/Phoenix')
Expand Down Expand Up @@ -174,3 +175,20 @@ def idle_time(start=8, end=12, tz=None):
return (i - s) // dt.timedelta(seconds=1)
e = dt.datetime(i.year, i.month, i.day, end, 0, 0, tzinfo=tz)
return (e - i) // dt.timedelta(seconds=1)


def exclude_years(start_year):
"""Generate rsync ``--exclude`` statements of the form ``--exclude 2020*``.
Parameters
----------
start_year : :class:`int`
First year to exclude.
Returns
-------
:class:`list`
A list suitable for appending to a command.
"""
return (' '.join([f'--exclude {y:d}*' for y in range(start_year, time.localtime().tm_year)])).split()

10 changes: 9 additions & 1 deletion py/desitransfer/test/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from unittest.mock import patch
from tempfile import TemporaryDirectory
from ..common import (dt, MST, dir_perm, file_perm, empty_rsync, new_exposures, rsync,
stamp, ensure_scratch, yesterday, today, idle_time)
stamp, ensure_scratch, yesterday, today, idle_time, exclude_years)


class FakeDateTime(datetime):
Expand Down Expand Up @@ -174,3 +174,11 @@ def test_idle_time_alt_time_zone(self):
# mock_datetime.return_value = datetime(2021, 7, 3, 13, 0, 0, tzinfo=MST)
i = idle_time(tz='US/Pacific')
self.assertEqual(i, -3600)

def test_exclude_years(self):
"""Test exclude statements for a range of years.
"""
last_year = datetime.now().year - 1
ex = exclude_years(2018)
self.assertEqual(ex[1], '2018*')
self.assertEqual(ex[-1], f'{last_year:d}*')
5 changes: 3 additions & 2 deletions py/desitransfer/tucson.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from logging.handlers import SMTPHandler
import requests
from . import __version__ as dtVersion
from .common import exclude_years
from desiutil.log import get_logger


Expand Down Expand Up @@ -61,8 +62,8 @@
includes = {'engineering/focalplane': ["--exclude", "archive", "--exclude", "hwtables", "--exclude", ".ipynb_checkpoints", "--exclude", "*.ipynb"],
'engineering/focalplane/hwtables': ["--include", "*.csv", "--exclude", "*"],
'spectro/desi_spectro_calib': ["--exclude", ".svn"],
'spectro/data': (' '.join([f'--exclude {y:d}*' for y in range(2018, time.localtime().tm_year)])).split(),
'spectro/nightwatch/kpno': (' '.join([f'--exclude {y:d}*' for y in range(2021, time.localtime().tm_year)])).split(),
'spectro/data': exclude_years(2018),
'spectro/nightwatch/kpno': exclude_years(2021),
'spectro/redux/daily': ["--exclude", "*.tmp", "--exclude", "attic", "--exclude", "exposures", "--exclude", "preproc", "--exclude", "temp", "--exclude", "tiles"],
'spectro/redux/daily/exposures': ["--exclude", "*.tmp"],
'spectro/redux/daily/preproc': ["--exclude", "*.tmp", "--exclude", "preproc-*.fits", "--exclude", "preproc-*.fits.gz"],
Expand Down

0 comments on commit 8716c45

Please sign in to comment.