the big cleanup: remove unused relating to nitos
[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
86 services = ['sfa-db', 'sfa-aggregate', 'sfa-registry']
87 data_files.append(
88     ('/usr/lib/systemd/system',
89      ['systemd/{}.service'.format(service)
90       for service in services]))
91
92
93 # sfatables processors
94 processor_files = [f for f in glob('sfatables/processors/*')
95                    if os.path.isfile(f)]
96 data_files.append(('/etc/sfatables/processors/', processor_files))
97 processor_subdirs = [d for d in glob('sfatables/processors/*')
98                      if os.path.isdir(d)]
99 for d in processor_subdirs:
100     etc_dir = os.path.join("/etc/sfatables/processors", os.path.basename(d))
101     d_files = [f for f in glob(d + '/*') if os.path.isfile(f)]
102     data_files.append((etc_dir, processor_files))
103
104
105 if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']:
106     python_path = sys.path
107     site_packages_path = [ os.path.join(p, 'sfa') for p in python_path if p.endswith('site-packages')]
108     site_packages_path += [ os.path.join(p, 'sfatables') for p in python_path if p.endswith('site-packages')]
109     remove_dirs = ['/etc/sfa/', '/etc/sfatables'] + site_packages_path
110     remove_bins = [ '/usr/bin/' + os.path.basename(bin) for bin in scripts ]
111     remove_files = (remove_bins
112                     + ["/usr/lib/systemd/system/{}".format(x)
113                        for x in services])
114
115     # remove files
116     def feedback (file, msg):
117         print ("removing", file, "...", msg)
118     for filepath in remove_files:
119         try:
120             os.remove(filepath)
121             feedback(filepath, "success")
122         except:
123             feedback(filepath, "failed")
124     # remove directories
125     for directory in remove_dirs:
126         try:
127             shutil.rmtree(directory)
128             feedback (directory, "success")
129         except:
130             feedback (directory, "failed")
131 else:
132     # avoid repeating what's in the specfile already
133     try:
134         with open("LICENSE.txt") as l:
135             license = l.read()
136     except:
137         license = "Could not open file LICENSE.txt"
138     try:
139         with open("index.html") as r:
140             long_description = r.read()
141     except:
142         long_description = "Unable to read index.html"
143
144     setup(
145         name             = 'sfa',
146         packages         = packages,
147         data_files       = data_files,
148         version          = version_tag,
149         keywords         = ['federation', 'testbeds', 'SFA', 'SfaWrap'],
150         url              = "http://svn.planet-lab.org/wiki/SFATutorial",
151         author           = "Thierry Parmentelat, Tony Mack, Scott Baker",
152         author_email     = "thierry.parmentelat@inria.fr, tmack@princeton.cs.edu, smbaker@gmail.com",
153         download_url     = "http://build.onelab.eu/sfa/{v}/sfa-{v}.tar.gz".format(v=version_tag),
154         description      = "SFA Wrapper with drivers for PlanetLab and IotLab and others",
155         license          = license,
156         long_description = long_description,
157         scripts          = scripts,
158 )