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
9 PROD_ROOTDIR = '/home/jsoc/cvs/Development'
10 WAYSTATION = 'waystation'
11 WAYSTATION_USER = 'arta'
12
13 RV_SUCCESS = 0
14 RV_ERROR_WRONGUSER = 1
15 RV_ERROR_ARGS = 2
16 RV_ERROR_MAKE = 3
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 arta 1.1 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 # Allow only arta to modify the files in the waystation.
43 arta 1.1 if pwd.getpwuid(os.getuid())[0] != WAYSTATION_USER:
44 sys.exit(RV_ERROR_WRONGUSER)
45
46 # Turn off debug builds.
47 os.environ['JSOC_DEBUG'] = '0'
48
|
55 arta 1.1 try:
56 with Chdir(PROD_ROOTDIR + '/' + WAYSTATION + '/JSOC') as ret:
57 # os.chdir does NOT change the environment variable $PWD. But our make system relies on PWD being the current directory.
58 os.environ['PWD'] = os.path.realpath(os.getcwd())
59
60 cmdList = ['./configure']
61 check_call(cmdList)
62
63 cmdList = ['make']
64 check_call(cmdList)
65 cmdList = ['/usr/bin/make', 'dsds']
66 check_call(cmdList)
67
68 cmdList = ['chgrp', '-R', 'jsoc', '.']
69 check_call(cmdList)
70 cmdList = ['chmod', '-R', 'g-w', '.']
71 check_call(cmdList)
72
73 sys.exit(RV_SUCCESS);
74 except CalledProcessError as exc:
75 if exc.output:
76 arta 1.1 print('Error calling make: ' + exc.output, file=sys.stderr)
77 sys.exit(RV_ERROR_MAKE);
78 except ValueError:
79 print('Bad arguments to make: \n' + '\n'.join(cmdList[1:]))
80 sys.exit(RV_ERROR_MAKE);
81 except Exception as exc:
82 raise # Re-raise
|