8000 Add --sync-mp option for ACA-related mission planning files by taldcroft · Pull Request #23 · sot/ska_sync · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add --sync-mp option for ACA-related mission planning files #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 75 additions & 4 deletions ska_sync/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"""
import os
import getpass
import time
import textwrap
from pathli 10000 b import Path

import yaml

Expand All @@ -34,6 +37,14 @@ def get_opt():
action='store_true',
help='Force overwrite of sync config file')

parser.add_argument('--sync-mp',
action='store_true',
help='Sync mission planning files relevant to ACA for current year')

parser.add_argument('--fix-mp-links',
action='store_true',
help='Fix mission planning ofls symlinks')

opt = parser.parse_args()
return opt

Expand All @@ -51,7 +62,7 @@ def install(opt):
print('Wrote ska sync config file to {}'.format(out_path))


def file_sync(packages, user, host):
def file_sync(packages, user, host, sync_mp=False):
"""
Sync files for packages assuming location in $SKA/data/<package>/.
"""
Expand All @@ -67,25 +78,85 @@ def file_sync(packages, user, host):

print('\n'
'COPY and PASTE the following at your terminal command line prompt:\n\n'
' rsync -arzv --progress --files-from="{sync_files_path}" \\\n'
' {user}@{host}:/proj/sot/ska/ "{ska_path}/"\n'
'rsync -arzv --progress --files-from="{sync_files_path}" \\\n'
' {user}@{host}:/proj/sot/ska/ "{ska_path}/"\n'
.format(user=user, host=host, ska_path=ska_path(), sync_files_path=sync_files_path))

year = time.localtime().tm_year
if sync_mp:
cmd = f"""\
rsync -arzv --prune-empty-dirs \\
--include "*/" \\
--include "ofls" \\
--include="CR*.tlr" \\
--include="CR*.backstop" \\
--include="starcheck.txt" \\
--include="*.pkl.gz" \\
--include="mps/md*.dot" \\
--include="mps/or/*.or" \\
--include="mps/ode/characteristics/CHARACTERIS_*" \\
--include="mps/m*.sum" \\
--include="output/*_ManErr.txt" \\
--include="output/*_dynamical_offsets.txt" \\
--include="output/TEST_mechcheck.txt" \\
--include="History/DITHER.txt" \\
--include="History/FIDSEL.txt" \\
--include="History/RADMON.txt" \\
--include="History/SIMFOCUS.txt" \\
--include="History/SIMTRANS.txt" \\
--exclude="*" \\
{user}@{host}:/data/mpcrit1/mplogs/{year}/ \\
{ska_path()}/data/mpcrit1/mplogs/{year}/"""
cmd = textwrap.dedent(cmd)
print(cmd)
print()
print('ska_sync --fix-mp-links')
print()


def fix_mp_links():
"""Fix SOT MP ofls -> oflsa link

SOT MP uses absolute links like::

APR0620/ofls -> /data/mpcrit1/mplogs/2020/APR0620/oflsa

There is no obvious reason to do this but there you go.
"""
mp_dir = Path(ska_path()) / 'data' / 'mpcrit1' / 'mplogs'

# Oddly, mp_dir.glob('????/???????/ofls') does not return anything, so we
# need mp_dir.glob('????/???????/ofls*') and then filter results.
ofls_links = mp_dir.glob('????/???????/ofls*')
for ofls_link in ofls_links:
if ofls_link.name != 'ofls':
continue
link = os.readlink(ofls_link)
if link.startswith('/data'):
link = Path(link)
print(f'Linking {ofls_link} -> {link.name}')
ofls_link.unlink()
ofls_link.symlink_to(link.name)


def main():
opt = get_opt()
if opt.install:
install(opt)
return

if opt.fix_mp_links:
fix_mp_links()
return

config_path = SKA_CONFIG_PATH or PACKAGE_CONFIG_PATH
config = yaml.safe_load(open(config_path, 'r'))
print('Loaded config from {}'.format(config_path))

# Remote user name
user = opt.user or config.get('user') or getpass.getuser()

file_sync(config['file_sync'], user, config['host'])
file_sync(config['file_sync'], user, config['host'], opt.sync_mp)


if __name__ == '__main__':
Expand Down
0