(file) Return to buildprod.py CVS log (file) (dir) Up to [Development] / JSOC / build

 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           
49           try:
50               with Chdir(PROD_ROOTDIR + '/' + WAYSTATION + '/JSOC') as ret:
51                   # os.chdir does NOT change the environment variable $PWD. But our make system relies on PWD being the current directory.
52                   os.environ['PWD'] = os.path.realpath(os.getcwd())
53           
54                   cmdList = ['./configure']
55                   check_call(cmdList)
56                   
57                   cmdList = ['make']
58                   check_call(cmdList)
59                   cmdList = ['/usr/bin/make', 'dsds']
60                   check_call(cmdList)
61           
62                   cmdList = ['chgrp', '-R', 'jsoc', '.']
63                   check_call(cmdList)
64 arta  1.1         cmdList = ['chmod', '-R', 'g-w', '.']
65                   check_call(cmdList)
66           
67                   sys.exit(RV_SUCCESS);
68           except CalledProcessError as exc:
69               if exc.output:
70                   print('Error calling make: ' + exc.output, file=sys.stderr)
71                   sys.exit(RV_ERROR_MAKE);
72           except ValueError:
73               print('Bad arguments to make: \n' + '\n'.join(cmdList[1:]))
74               sys.exit(RV_ERROR_MAKE);
75           except Exception as exc:
76               raise # Re-raise

Karen Tian
Powered by
ViewCVS 0.9.4