1 |
#!/usr/bin/env python |
2 |
|
3 |
from __future__ import print_function |
4 |
import sys |
5 |
import os |
6 |
import re |
7 |
from subprocess import check_output, check_call, CalledProcessError |
8 |
import smtplib |
9 |
from datetime import datetime |
10 |
|
11 |
# Hard code a bunch of stuff since I don't have time to do this correctly. |
12 |
PROD_ROOTDIR = '/home/jsoc/cvs/Development' |
13 |
# PROD_ROOTDIR = '/tmp/arta' |
14 |
WAYSTATION = 'waystation' |
15 |
|
16 |
RV_SUCCESS = 0 |
17 |
|
18 |
# This class changes the current working directory, and restores the original working directory when |
19 |
# the context is left. |
20 |
class Chdir: |
21 |
"""Context manager for changing the current working directory""" |
22 |
def __init__(self, newPath): |
23 |
self.newPath = os.path.realpath(newPath) |
24 |
|
25 |
def __enter__(self): |
26 |
self.savedPath = os.path.realpath(os.getcwd()) |
27 |
os.chdir(self.newPath) |
28 |
cdir = os.path.realpath(os.getcwd()) |
29 |
if cdir == self.newPath: |
30 |
return 0 |
31 |
else: |
32 |
return 1 |
33 |
|
34 |
def __exit__(self, etype, value, traceback): |
35 |
os.chdir(self.savedPath) |
36 |
cdir = os.path.realpath(os.getcwd()) |
37 |
if cdir == self.savedPath: |
38 |
return 0 |
39 |
else: |
40 |
return 1 |
41 |
|
42 |
msg = None |
43 |
rv = RV_SUCCESS |
44 |
|
45 |
try: |
46 |
with Chdir(PROD_ROOTDIR) as ret: |
47 |
if ret == 0: |
48 |
cmdList = ['rsync', '-alu', WAYSTATION + '/JSOC/', 'JSOC.new/JSOC'] |
49 |
check_call(cmdList) |
50 |
cmdList = ['chgrp', '-Rh', 'jsoc', 'JSOC.new/JSOC'] |
51 |
check_call(cmdList) |
52 |
cmdList = ['chmod', '-R', 'g-w', 'JSOC.new/JSOC'] |
53 |
check_call(cmdList) |
54 |
cmdList = ['mv', 'JSOC', 'JSOC_' + datetime.now().strftime('%Y%m%d_%H%M%S')] |
55 |
check_call(cmdList) |
56 |
cmdList = ['mv', 'JSOC.new/JSOC', 'JSOC'] |
57 |
check_call(cmdList) |
58 |
|
59 |
except CalledProcessError as exc: |
60 |
if exc.output: |
61 |
print('Error calling rsync: ' + exc.output, file=sys.stderr) |
62 |
except ValueError: |
63 |
print('Bad arguments to rsync: \n' + '\n'.join(cmdList[1:])) |
64 |
except Exception as exc: |
65 |
raise # Re-raise |