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 # Unset 'GLOBALHSTAGOVERRIDE'
80 del os.environ['GLOBALHSTAGOVERRIDE']
81
|
82 arta 1.1 try:
83 with Chdir(PROD_ROOTDIR + '/' + WAYSTATION + '/JSOC') as ret:
84 # os.chdir does NOT change the environment variable $PWD. But our make system relies on PWD being the current directory.
85 os.environ['PWD'] = os.path.realpath(os.getcwd())
86
|
87 arta 1.6 if optD['full']:
88 cmdList = ['./configure']
89 else:
90 cmdList = ['./configure', '-d']
|
91 arta 1.1 check_call(cmdList)
92
|
93 arta 1.6 cmdList = ['/usr/bin/make']
|
94 arta 1.1 check_call(cmdList)
95 cmdList = ['/usr/bin/make', 'dsds']
96 check_call(cmdList)
|
97 arta 1.6 if optD['full']:
|
98 arta 1.8 cmdList = ['/usr/bin/make', 'globalhs',]
|
99 arta 1.6 check_call(cmdList)
|
100 arta 1.1
|
101 arta 1.5 cmdList = ['chgrp', '-Rh', 'jsoc', '.']
|
102 arta 1.1 check_call(cmdList)
103 cmdList = ['chmod', '-R', 'g-w', '.']
104 check_call(cmdList)
105
106 sys.exit(RV_SUCCESS);
107 except CalledProcessError as exc:
108 if exc.output:
109 print('Error calling make: ' + exc.output, file=sys.stderr)
|
110 arta 1.3 sys.exit(RV_ERROR_MAKE);
|
111 arta 1.1 except ValueError:
112 print('Bad arguments to make: \n' + '\n'.join(cmdList[1:]))
113 sys.exit(RV_ERROR_MAKE);
114 except Exception as exc:
|
115 arta 1.6 if len(exc.args) != 2:
116 raise # Re-raise
117
118 etype = exc.args[0]
119 msg = exc.args[1]
120
121 if etype != 'getArgs':
122 raise # Re-raise
123
124 print(msg, file=sys.stderr)
|