the big cleanup: remove unused code relating to openstack/nova
[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     'config/sfa-config-tty',
33     'config/sfa-config',
34     'sfa/server/sfa-start.py',
35     'systemd/sfa-setup.sh',
36     'sfatables/sfatables',
37     'keyconvert/keyconvert.py',
38 ]
39
40 packages = [
41     'sfa',
42     'sfa/trust',
43     'sfa/storage',
44     'sfa/util',
45     'sfa/server',
46     'sfa/methods',
47     'sfa/generic',
48     'sfa/managers',
49     'sfa/importer',
50     'sfa/rspecs',
51     'sfa/rspecs/elements',
52     'sfa/rspecs/elements/versions',
53     'sfa/rspecs/versions',
54     'sfa/client',
55     'sfa/planetlab',
56     'sfa/nitos',
57     'sfa/dummy',
58     'sfa/iotlab',
59     'sfatables',
60     'sfatables/commands',
61     'sfatables/processors',
62     ]
63
64 data_files = [
65     ('/etc/sfa/',
66      [  'config/aggregates.xml',
67         'config/registries.xml',
68         'config/default_config.xml',
69         'config/api_versions.xml',
70         'config/sfi_config',
71         'config/topology',
72         'sfa/managers/pl/pl.rng',
73         'sfa/trust/credential.xsd',
74         'sfa/trust/top.xsd',
75         'sfa/trust/sig.xsd',
76         'sfa/trust/xml.xsd',
77         'sfa/trust/protogeni-rspec-common.xsd',
78     ]),
79     ('/etc/sfatables/matches/', glob('sfatables/matches/*.xml')),
80     ('/etc/sfatables/targets/', glob('sfatables/targets/*.xml')),
81     ('/usr/share/sfa/migrations', glob('sfa/storage/migrations/*.*') ),
82     ('/usr/share/sfa/migrations/versions', glob('sfa/storage/migrations/versions/*') ),
83     ('/usr/share/sfa/examples/', glob('sfa/examples/*' ) + [ 'cron.d/sfa.cron' ] ),
84 ]
85
86
87 services = ['sfa-db', 'sfa-aggregate', 'sfa-registry']
88 data_files.append(
89     ('/usr/lib/systemd/system',
90      ['systemd/{}.service'.format(service)
91       for service in services]))
92
93
94 # sfatables processors
95 processor_files = [f for f in glob('sfatables/processors/*')
96                    if os.path.isfile(f)]
97 data_files.append(('/etc/sfatables/processors/', processor_files))
98 processor_subdirs = [d for d in glob('sfatables/processors/*')
99                      if os.path.isdir(d)]
100 for d in processor_subdirs:
101     etc_dir = os.path.join("/etc/sfatables/processors", os.path.basename(d))
102     d_files = [f for f in glob(d + '/*') if os.path.isfile(f)]
103     data_files.append((etc_dir, processor_files))
104
105
106 if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']:
107     python_path = sys.path
108     site_packages_path = [ os.path.join(p, 'sfa') for p in python_path if p.endswith('site-packages')]
109     site_packages_path += [ os.path.join(p, 'sfatables') for p in python_path if p.endswith('site-packages')]
110     remove_dirs = ['/etc/sfa/', '/etc/sfatables'] + site_packages_path
111     remove_bins = [ '/usr/bin/' + os.path.basename(bin) for bin in scripts ]
112     remove_files = (remove_bins
113                     + ["/usr/lib/systemd/system/{}".format(x)
114                        for x in services])
115
116     # remove files
117     def feedback (file, msg):
118         print ("removing", file, "...", msg)
119     for filepath in remove_files:
120         try:
121             os.remove(filepath)
122             feedback(filepath, "success")
123         except:
124             feedback(filepath, "failed")
125     # remove directories
126     for directory in remove_dirs:
127         try:
128             shutil.rmtree(directory)
129             feedback (directory, "success")
130         except:
131             feedback (directory, "failed")
132 else:
133     # avoid repeating what's in the specfile already
134     try:
135         with open("LICENSE.txt") as l:
136             license = l.read()
137     except:
138         license = "Could not open file LICENSE.txt"
139     try:
140         with open("index.html") as r:
141             long_description = r.read()
142     except:
143         long_description = "Unable to read index.html"
144
145     setup(
146         name             = 'sfa',
147         packages         = packages,
148         data_files       = data_files,
149         version          = version_tag,
150         keywords         = ['federation', 'testbeds', 'SFA', 'SfaWrap'],
151         url              = "http://svn.planet-lab.org/wiki/SFATutorial",
152         author           = "Thierry Parmentelat, Tony Mack, Scott Baker",
153         author_email     = "thierry.parmentelat@inria.fr, tmack@princeton.cs.edu, smbaker@gmail.com",
154         download_url     = "http://build.onelab.eu/sfa/{v}/sfa-{v}.tar.gz".format(v=version_tag),
155         description      = "SFA Wrapper with drivers for PlanetLab and IotLab and others",
156         license          = license,
157         long_description = long_description,
158         scripts          = scripts,
159 )