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