minor tweaks in version manager embedded tester
[sfa.git] / setup.py
1 #!/usr/bin/env python
2
3 from __future__ import print_function
4
5 """
6 Installation script for the sfa module
7 """
8
9 # as fas as pushing onto pypi, I have been using this page
10 # http://peterdowns.com/posts/first-time-with-pypi.html
11 # for setting up the whole business
12
13 import sys, os, os.path
14 from glob import glob
15 import shutil
16 from distutils.core import setup
17
18 # check for the correct version of python
19 major,minor = sys.version_info [0:2]
20 if (major,minor) != (2,7):
21     print ("Sorry, the SFA package is currently available only with python-2.7")
22     exit(1)
23
24
25 # while cleaning up we might not have this..
26 try:
27     from sfa.util.version import version_tag
28 except:
29     version_tag='cleaningup'
30
31 scripts = glob("clientbin/*.py") + \
32     [
33     'config/sfa-config-tty',
34     'config/sfa-config',
35 #    'config/gen-sfa-cm-config.py',
36     'sfa/server/sfa-start.py',
37 #    'sfa/server/sfa_component_setup.py',
38     'sfatables/sfatables',
39     'keyconvert/keyconvert.py',
40     'flashpolicy/sfa_flashpolicy.py',
41     ]
42
43 packages = [
44     'sfa',
45     'sfa/trust',
46     'sfa/storage',
47     'sfa/util',
48     'sfa/server',
49     'sfa/methods',
50     'sfa/generic',
51     'sfa/managers',
52     'sfa/importer',
53     'sfa/rspecs',
54     'sfa/rspecs/elements',
55     'sfa/rspecs/elements/versions',
56     'sfa/rspecs/versions',
57     'sfa/client',
58     'sfa/planetlab',
59     'sfa/nitos',
60     'sfa/dummy',
61     'sfa/openstack',
62     'sfa/federica',
63     'sfa/iotlab',
64     'sfatables',
65     'sfatables/commands',
66     'sfatables/processors',
67     ]
68
69 initscripts = [ 'sfa' ]
70 if not os.path.isfile('/etc/redhat-release'): initscripts.append('functions.sfa')
71
72 data_files = [ ('/etc/sfa/', [ 'config/aggregates.xml',
73                               'config/registries.xml',
74                               'config/default_config.xml',
75                               'config/api_versions.xml',
76                               'config/sfi_config',
77                               'config/topology',
78                               'sfa/managers/pl/pl.rng',
79                               'sfa/trust/credential.xsd',
80                               'sfa/trust/top.xsd',
81                               'sfa/trust/sig.xsd',
82                               'sfa/trust/xml.xsd',
83                               'sfa/trust/protogeni-rspec-common.xsd',
84                               'flashpolicy/sfa_flashpolicy_config.xml',
85                             ]),
86                ('/etc/sfatables/matches/', glob('sfatables/matches/*.xml')),
87                ('/etc/sfatables/targets/', glob('sfatables/targets/*.xml')),
88                ('/etc/init.d/', [ "init.d/%s"%x for x in initscripts ]),
89                ('/usr/share/sfa/migrations', glob('sfa/storage/migrations/*.*') ),
90                ('/usr/share/sfa/migrations/versions', glob('sfa/storage/migrations/versions/*') ),
91                ('/usr/share/sfa/examples/', glob('sfa/examples/*' ) + [ 'cron.d/sfa.cron' ] ),
92               ]
93
94 # add sfatables processors as data_files
95 processor_files = [f for f in glob('sfatables/processors/*') if os.path.isfile(f)]
96 data_files.append(('/etc/sfatables/processors/', processor_files))
97 processor_subdirs = [d for d in glob('sfatables/processors/*') if os.path.isdir(d)]
98 for d in processor_subdirs:
99     etc_dir = os.path.join("/etc/sfatables/processors", os.path.basename(d))
100     d_files = [f for f in glob(d + '/*') if os.path.isfile(f)]
101     data_files.append((etc_dir, processor_files))
102
103 if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']:
104     python_path = sys.path
105     site_packages_path = [ os.path.join(p,'sfa') for p in python_path if p.endswith('site-packages')]
106     site_packages_path += [ os.path.join(p,'sfatables') for p in python_path if p.endswith('site-packages')]
107     remove_dirs = ['/etc/sfa/', '/etc/sfatables'] + site_packages_path
108     remove_bins = [ '/usr/bin/' + os.path.basename(bin) for bin in scripts ]
109     remove_files = remove_bins + [ "/etc/init.d/%s"%x for x in initscripts ]
110
111     # remove files
112     def feedback (file, msg): print ("removing", file, "...",msg)
113     for filepath in remove_files:
114         try:
115             os.remove(filepath)
116             feedback(filepath,"success")
117         except: 
118             feedback(filepath,"failed")
119     # remove directories
120     for directory in remove_dirs:
121         try:
122             shutil.rmtree(directory)
123             feedback (directory,"success")
124         except: 
125             feedback (directory, "failed")
126 else:
127     # avoid repeating what's in the specfile already
128     try:
129         with open("LICENSE.txt") as l:
130             license = l.read()
131     except:
132         license = "Could not open file LICENSE.txt"
133     try:
134         with open("index.html") as r:
135             long_description = r.read()
136     except:
137         long_description = "Unable to read index.html"
138
139     setup(
140         name             = 'sfa',
141         packages         = packages,
142         data_files       = data_files,
143         version          = version_tag,
144         keywords         = ['federation','testbeds','SFA','SfaWrap'],
145         url              = "http://svn.planet-lab.org/wiki/SFATutorial",
146         author           = "Thierry Parmentelat, Tony Mack, Scott Baker",
147         author_email     = "thierry.parmentelat@inria.fr, tmack@princeton.cs.edu, smbaker@gmail.com",
148         download_url     = "http://build.onelab.eu/sfa/{v}/sfa-{v}.tar.gz".format(v=version_tag),
149         description      = "SFA Wrapper with drivers for PlanetLab and IotLab and others",
150         license          = license,
151         long_description = long_description,
152         scripts          = scripts,
153 )
154