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 arta 1.4 PROD_ROOTDIR = '/home/jsoc/cvs/Development'
10 # PROD_ROOTDIR = '/tmp/arta'
|
11 arta 1.1 WAYSTATION = 'waystation'
12 WAYSTATION_USER = 'arta'
13
14 RV_SUCCESS = 0
15 RV_ERROR_WRONGUSER = 1
16 RV_ERROR_ARGS = 2
17 RV_ERROR_MAKE = 3
18
19 # This class changes the current working directory, and restores the original working directory when
20 # the context is left.
21 class Chdir:
22 """Context manager for changing the current working directory"""
23 def __init__(self, newPath):
24 self.newPath = os.path.realpath(newPath)
25
26 def __enter__(self):
27 self.savedPath = os.path.realpath(os.getcwd())
28 os.chdir(self.newPath)
29 cdir = os.path.realpath(os.getcwd())
30 if cdir == self.newPath:
31 return 0
32 arta 1.1 else:
33 return 1
34
35 def __exit__(self, etype, value, traceback):
36 os.chdir(self.savedPath)
37 cdir = os.path.realpath(os.getcwd())
38 if cdir == self.savedPath:
39 return 0
40 else:
41 return 1
42
43 # Allow only arta to modify the files in the waystation.
44 if pwd.getpwuid(os.getuid())[0] != WAYSTATION_USER:
45 sys.exit(RV_ERROR_WRONGUSER)
46
47 # Turn off debug builds.
48 os.environ['JSOC_DEBUG'] = '0'
49
|
50 arta 1.2 # Make sure the JSOCROOT is PROD_ROOTDIR + '/JSOC'
51 os.environ['JSOCROOT'] = PROD_ROOTDIR + '/JSOC'
52
53 # Unset 'GLOBALHSTAGOVERRIDE'
54 del os.environ['GLOBALHSTAGOVERRIDE']
55
|
56 arta 1.1 try:
57 with Chdir(PROD_ROOTDIR + '/' + WAYSTATION + '/JSOC') as ret:
58 # os.chdir does NOT change the environment variable $PWD. But our make system relies on PWD being the current directory.
59 os.environ['PWD'] = os.path.realpath(os.getcwd())
60
|
61 arta 1.4 cmdList = ['./configure', '-d']
|
62 arta 1.1 check_call(cmdList)
63
64 cmdList = ['make']
65 check_call(cmdList)
66 cmdList = ['/usr/bin/make', 'dsds']
67 check_call(cmdList)
68
69 cmdList = ['chgrp', '-R', 'jsoc', '.']
70 check_call(cmdList)
71 cmdList = ['chmod', '-R', 'g-w', '.']
72 check_call(cmdList)
73
74 sys.exit(RV_SUCCESS);
75 except CalledProcessError as exc:
76 if exc.output:
77 print('Error calling make: ' + exc.output, file=sys.stderr)
|
78 arta 1.3 sys.exit(RV_ERROR_MAKE);
|
79 arta 1.1 except ValueError:
80 print('Bad arguments to make: \n' + '\n'.join(cmdList[1:]))
81 sys.exit(RV_ERROR_MAKE);
82 except Exception as exc:
83 raise # Re-raise
|