1 arta 1.1 #!/usr/bin/env python
2
3 from __future__ import print_function
4 import sys
5 import os
6 import pwd
7 from subprocess import check_output, check_call, call, Popen, CalledProcessError
|
8 arta 1.6 sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../base/libs/py'))
9 from drmsCmdl import CmdlParser
|
10 arta 1.1
|
11 arta 1.4 PROD_ROOTDIR = '/home/jsoc/cvs/Development'
12 # PROD_ROOTDIR = '/tmp/arta'
|
13 arta 1.1 WAYSTATION = 'waystation'
14 WAYSTATION_USER = 'arta'
15
16 RV_SUCCESS = 0
17 RV_ERROR_WRONGUSER = 1
18 RV_ERROR_ARGS = 2
19 RV_ERROR_MAKE = 3
20
21 # This class changes the current working directory, and restores the original working directory when
22 # the context is left.
23 class Chdir:
24 """Context manager for changing the current working directory"""
25 def __init__(self, newPath):
26 self.newPath = os.path.realpath(newPath)
27
28 def __enter__(self):
29 self.savedPath = os.path.realpath(os.getcwd())
30 os.chdir(self.newPath)
31 cdir = os.path.realpath(os.getcwd())
32 if cdir == self.newPath:
33 return 0
34 arta 1.1 else:
35 return 1
36
37 def __exit__(self, etype, value, traceback):
38 os.chdir(self.savedPath)
39 cdir = os.path.realpath(os.getcwd())
40 if cdir == self.savedPath:
41 return 0
42 else:
43 return 1
|
44 arta 1.6
45 optD = {}
46
47 try:
48 parser = CmdlParser(usage='%(prog)s [ -f ]')
49
50 # Optional
51 parser.add_argument('-f', '--full', help='Create/re-create all links and create/re-create all localization parameter files.', dest='full', action='store_true', default=False)
52
53 args = parser.parse_args()
54
55 optD['full'] = args.full
56
57 except Exception as exc:
58 if len(exc.args) != 2:
59 raise # Re-raise
60
61 etype = exc.args[0]
62 msg = exc.args[1]
63
64 if etype == 'CmdlParser-ArgUnrecognized' or etype == 'CmdlParser-ArgBadformat' or etype == 'CmdlParser':
65 arta 1.6 raise Exception('getArgs', 'cl', 'Unable to parse command-line arguments. ' + msg + '\n' + parser.format_help())
66 else:
67 raise # Re-raise.
|
68 arta 1.1
69 # Allow only arta to modify the files in the waystation.
70 if pwd.getpwuid(os.getuid())[0] != WAYSTATION_USER:
71 sys.exit(RV_ERROR_WRONGUSER)
72
73 # Turn off debug builds.
74 os.environ['JSOC_DEBUG'] = '0'
75
|
76 arta 1.2 # Make sure the JSOCROOT is PROD_ROOTDIR + '/JSOC'
77 os.environ['JSOCROOT'] = PROD_ROOTDIR + '/JSOC'
78
|
79 arta 1.1 try:
80 with Chdir(PROD_ROOTDIR + '/' + WAYSTATION + '/JSOC') as ret:
81 # os.chdir does NOT change the environment variable $PWD. But our make system relies on PWD being the current directory.
82 os.environ['PWD'] = os.path.realpath(os.getcwd())
|
83 arta 1.10
84 # Set 'GLOBALHSTAGOVERRIDE'
85 if 'GLOBALHSTAGOVERRIDE' in os.environ:
86 del os.environ['GLOBALHSTAGOVERRIDE']
87 os.environ['GLOBALHSTAGOVERRIDE'] = 'globalhs'
|
88 arta 1.1
|
89 arta 1.6 if optD['full']:
90 cmdList = ['./configure']
91 else:
92 cmdList = ['./configure', '-d']
|
93 arta 1.1 check_call(cmdList)
94
|
95 arta 1.6 cmdList = ['/usr/bin/make']
|
96 arta 1.1 check_call(cmdList)
97 cmdList = ['/usr/bin/make', 'dsds']
98 check_call(cmdList)
|
99 arta 1.6 if optD['full']:
|
100 arta 1.10 # Unset 'GLOBALHSTAGOVERRIDE'
101 if 'GLOBALHSTAGOVERRIDE' in os.environ:
102 del os.environ['GLOBALHSTAGOVERRIDE']
103
|
104 arta 1.8 cmdList = ['/usr/bin/make', 'globalhs',]
|
105 arta 1.6 check_call(cmdList)
|
106 arta 1.1
|
107 arta 1.5 cmdList = ['chgrp', '-Rh', 'jsoc', '.']
|
108 arta 1.1 check_call(cmdList)
109 cmdList = ['chmod', '-R', 'g-w', '.']
110 check_call(cmdList)
111
112 sys.exit(RV_SUCCESS);
113 except CalledProcessError as exc:
114 if exc.output:
115 print('Error calling make: ' + exc.output, file=sys.stderr)
|
116 arta 1.3 sys.exit(RV_ERROR_MAKE);
|
117 arta 1.1 except ValueError:
118 print('Bad arguments to make: \n' + '\n'.join(cmdList[1:]))
119 sys.exit(RV_ERROR_MAKE);
120 except Exception as exc:
|
121 arta 1.6 if len(exc.args) != 2:
122 raise # Re-raise
123
124 etype = exc.args[0]
125 msg = exc.args[1]
126
127 if etype != 'getArgs':
128 raise # Re-raise
129
130 print(msg, file=sys.stderr)
|