forked from PanDAWMS/panda-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·206 lines (194 loc) · 8.22 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/env python
#
# Setup prog for Panda Server
#
#
release_version='0.0.5'
import re
import sys
import socket
import commands
from distutils.core import setup
from distutils.command.install import install as install_org
from distutils.command.install_data import install_data as install_data_org
# get panda specific params
optPanda = {}
newArgv = []
idx = 0
while idx < len(sys.argv):
tmpArg = sys.argv[idx]
if tmpArg.startswith('--panda_'):
# panda params
idx += 1
if len(tmpArg.split('=')) == 2:
# split to par and val if = is contained
tmpVal = tmpArg.split('=')[-1]
tmpArg = tmpArg.split('=')[0]
elif len(tmpArg.split('=')) == 1:
tmpVal = sys.argv[idx]
idx += 1
else:
raise RuntimeError,"invalid panda option : %s" % tmpArg
# get key
tmpKey = re.sub('--panda_','',tmpArg)
# set params
optPanda[tmpKey] = tmpVal
else:
# normal opts
idx += 1
newArgv.append(tmpArg)
# set new argv
sys.argv = newArgv
# set overall prefix for bdist_rpm
class install_panda(install_org):
def initialize_options (self):
install_org.initialize_options(self)
self.prefix = '/data/atlpan/srv'
# generates files using templates and install them
class install_data_panda (install_data_org):
def initialize_options (self):
install_data_org.initialize_options (self)
self.install_purelib = None
self.host_name = socket.getfqdn()
self.python_exec_version = '%s.%s' % sys.version_info[:2]
def finalize_options (self):
# set install_purelib
self.set_undefined_options('install',
('install_purelib','install_purelib'))
# set reaming params
install_data_org.finalize_options(self)
# set hostname
if optPanda.has_key('hostname') and optPanda['hostname'] != '':
self.hostname = optPanda['hostname']
else:
self.hostname = commands.getoutput('hostname -f')
# set user and group
if optPanda.has_key('username') and optPanda['username'] != '':
self.username = optPanda['username']
else:
self.username = commands.getoutput('id -un')
if optPanda.has_key('usergroup') and optPanda['usergroup'] != '':
self.usergroup = optPanda['usergroup']
else:
self.usergroup = commands.getoutput('id -gn')
def run (self):
# remove /usr for bdist/bdist_rpm
match = re.search('(build/[^/]+/dumb)/usr',self.install_dir)
if match != None:
self.install_dir = re.sub(match.group(0),match.group(1),self.install_dir)
# remove /var/tmp/*-buildroot for bdist_rpm
match = re.search('(/var/tmp/.*-buildroot)/usr',self.install_dir)
if match != None:
self.install_dir = re.sub(match.group(0),match.group(1),self.install_dir)
# create tmp area
tmpDir = 'build/tmp'
self.mkpath(tmpDir)
new_data_files = []
for destDir,dataFiles in self.data_files:
newFilesList = []
for srcFile in dataFiles:
# check extension
if not srcFile.endswith('.template'):
raise RuntimeError,"%s doesn't have the .template extension" % srcFile
# dest filename
destFile = re.sub('(\.exe)*\.template$','',srcFile)
destFile = destFile.split('/')[-1]
destFile = '%s/%s' % (tmpDir,destFile)
# open src
inFile = open(srcFile)
# read
filedata=inFile.read()
# close
inFile.close()
# replace patterns
for item in re.findall('@@([^@]+)@@',filedata):
if not hasattr(self,item):
raise RuntimeError,'unknown pattern %s in %s' % (item,srcFile)
# get pattern
patt = getattr(self,item)
# remove build/*/dump for bdist
patt = re.sub('build/[^/]+/dumb','',patt)
# remove /var/tmp/*-buildroot for bdist_rpm
patt = re.sub('/var/tmp/.*-buildroot','',patt)
# replace
filedata = filedata.replace('@@%s@@' % item, patt)
# write to dest
oFile = open(destFile,'w')
oFile.write(filedata)
oFile.close()
# chmod for exe
if srcFile.endswith('.exe.template'):
commands.getoutput('chmod +x %s' % destFile)
# append
newFilesList.append(destFile)
# replace dataFiles to install generated file
new_data_files.append((destDir,newFilesList))
# install
self.data_files = new_data_files
install_data_org.run(self)
# setup for distutils
setup(
name="panda-server",
version=release_version,
description=' PanDA Server Package',
long_description='''This package contains PanDA Server Components''',
license='GPL',
author='Panda Team',
author_email='[email protected]',
url='https://twiki.cern.ch/twiki/bin/view/Atlas/PanDA',
packages=[ 'pandaserver',
'pandaserver.brokerage',
'pandaserver.config',
'pandaserver.dataservice',
'pandaserver.jobdispatcher',
'pandaserver.server',
'pandaserver.taskbuffer',
'pandaserver.test',
'pandaserver.userinterface',
],
data_files=[
# config files
('etc/panda', ['templates/panda_server-httpd.conf.rpmnew.template',
'templates/panda_server-httpd-FastCGI.conf.rpmnew.template',
'templates/panda_server.cfg.rpmnew.template',
'templates/panda_server-grid-env.sh.template',
]
),
# sysconfig
('etc/sysconfig', ['templates/panda_server-sysconfig.rpmnew.template',
]
),
# logrotate
('etc/logrotate.d', ['templates/panda_server-logrotate.template',
]
),
# init script
('etc/init.d', ['templates/panda_server-ctl.exe.template',
]
),
# crons
('usr/bin', ['templates/panda_server-add.sh.exe.template',
'templates/panda_server-priority.sh.exe.template',
'templates/panda_server-copyArchive.sh.exe.template',
'templates/panda_server-copyROOT.sh.exe.template',
'templates/panda_server-vomsrenew.sh.exe.template',
'templates/panda_server-archivelog.sh.exe.template',
'templates/panda_server-tmpwatch.sh.exe.template',
'templates/panda_server-backupJobArch.sh.exe.template',
'templates/panda_server-deleteJobs.sh.exe.template',
'templates/panda_server-merge.sh.exe.template',
'templates/panda_server-datasetManager.sh.exe.template',
'templates/panda_server-evpPD2P.sh.exe.template',
'templates/panda_server-callback.sh.exe.template',
'templates/panda_server-makeSlsXml.exe.template',
'templates/panda_server-boostUser.sh.exe.template',
'templates/panda_server-runRebro.sh.exe.template',
]
),
# var dirs
#('var/log/panda', []),
#('var/cache/pandaserver', []),
],
cmdclass={'install': install_panda,
'install_data': install_data_panda}
)