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