forked from PanDAWMS/panda-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
110 lines (102 loc) · 4.07 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
#
#
# Setup prog for Panda Common
#
#
# set PYTHONPATH to use the current directory first
import sys
sys.path.insert(0,'.')
# get release version
import os
import PandaPkgInfo
release_version = PandaPkgInfo.release_version
if os.environ.has_key('BUILD_NUMBER'):
release_version = '{0}.{1}'.format(release_version,os.environ['BUILD_NUMBER'])
import re
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
# set overall prefix for bdist_rpm
class install_panda(install_org):
def initialize_options (self):
install_org.initialize_options(self)
# generates files using templates and install them
class install_data_panda (install_data_org):
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('\.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 install root, if any
if self.root is not None and patt.startswith(self.root):
patt = patt[len(self.root):]
# 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()
# 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-common",
version=release_version,
description=' PanDA Common Package',
long_description='''This package contains PanDA Common Components''',
license='GPL',
author='Panda Team',
author_email='[email protected]',
url='https://twiki.cern.ch/twiki/bin/view/Atlas/PanDA',
packages=[ 'pandacommon',
'pandacommon.liveconfigparser',
'pandacommon.pandalogger',
'pandacommon.pandautils',
],
data_files=[
('/etc/panda',
['templates/panda_common.cfg.rpmnew.template']
),
],
cmdclass={'install': install_panda,
'install_data': install_data_panda}
)