protect for cases where index.html and/or LICENSE.txt are not found (like on the...
[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 # while cleaning up we might not have this..
19 try:
20     from sfa.util.version import version_tag
21 except:
22     version_tag='cleaningup'
23
24 scripts = glob("clientbin/*.py") + \
25     [
26     'config/sfa-config-tty',
27     'config/sfa-config',
28 #    'config/gen-sfa-cm-config.py',
29     'sfa/server/sfa-start.py',
30 #    'sfa/server/sfa_component_setup.py',
31     'sfatables/sfatables',
32     'keyconvert/keyconvert.py',
33     'flashpolicy/sfa_flashpolicy.py',
34     ]
35
36 packages = [
37     'sfa',
38     'sfa/trust',
39     'sfa/storage',
40     'sfa/util',
41     'sfa/server',
42     'sfa/methods',
43     'sfa/generic',
44     'sfa/managers',
45     'sfa/importer',
46     'sfa/rspecs',
47     'sfa/rspecs/elements',
48     'sfa/rspecs/elements/versions',
49     'sfa/rspecs/versions',
50     'sfa/client',
51     'sfa/planetlab',
52     'sfa/nitos',
53     'sfa/dummy',
54     'sfa/openstack',
55     'sfa/federica',
56     'sfa/iotlab',
57     'sfa/cortexlab',
58     'sfatables',
59     'sfatables/commands',
60     'sfatables/processors',
61     ]
62
63 initscripts = [ 'sfa' ]
64 if not os.path.isfile('/etc/redhat-release'): initscripts.append('functions.sfa')
65
66 data_files = [ ('/etc/sfa/', [ '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                               'flashpolicy/sfa_flashpolicy_config.xml',
79                             ]),
80                ('/etc/sfatables/matches/', glob('sfatables/matches/*.xml')),
81                ('/etc/sfatables/targets/', glob('sfatables/targets/*.xml')),
82                ('/etc/init.d/', [ "init.d/%s"%x for x in initscripts ]),
83                ('/usr/share/sfa/migrations', glob('sfa/storage/migrations/*.*') ),
84                ('/usr/share/sfa/migrations/versions', glob('sfa/storage/migrations/versions/*') ),
85                ('/usr/share/sfa/examples/', glob('sfa/examples/*' ) + [ 'cron.d/sfa.cron' ] ),
86               ]
87
88 # add sfatables processors as data_files
89 processor_files = [f for f in glob('sfatables/processors/*') if os.path.isfile(f)]
90 data_files.append(('/etc/sfatables/processors/', processor_files))
91 processor_subdirs = [d for d in glob('sfatables/processors/*') if os.path.isdir(d)]
92 for d in processor_subdirs:
93     etc_dir = os.path.join("/etc/sfatables/processors", os.path.basename(d))
94     d_files = [f for f in glob(d + '/*') if os.path.isfile(f)]
95     data_files.append((etc_dir, processor_files))
96
97 if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']:
98     python_path = sys.path
99     site_packages_path = [ os.path.join(p,'sfa') for p in python_path if p.endswith('site-packages')]
100     site_packages_path += [ os.path.join(p,'sfatables') for p in python_path if p.endswith('site-packages')]
101     remove_dirs = ['/etc/sfa/', '/etc/sfatables'] + site_packages_path
102     remove_bins = [ '/usr/bin/' + os.path.basename(bin) for bin in scripts ]
103     remove_files = remove_bins + [ "/etc/init.d/%s"%x for x in initscripts ]
104
105     # remove files
106     def feedback (file, msg): print ("removing", file, "...",msg)
107     for filepath in remove_files:
108         try:
109             os.remove(filepath)
110             feedback(filepath,"success")
111         except: 
112             feedback(filepath,"failed")
113     # remove directories
114     for directory in remove_dirs:
115         try:
116             shutil.rmtree(directory)
117             feedback (directory,"success")
118         except: 
119             feedback (directory, "failed")
120 else:
121     # avoid repeating what's in the specfile already
122     try:
123         with open("LICENSE.txt") as l:
124             license = l.read()
125     except:
126         license = "Could not open file LICENSE.txt"
127     try:
128         with open("index.html") as r:
129             long_description = r.read()
130     except:
131         long_description = "Unable to read index.html"
132
133     setup(name='sfa',
134           packages = packages,
135           data_files = data_files,
136           version=version_tag,
137           keywords = ['federation','testbeds','SFA','SfaWrap'],
138           url="http://svn.planet-lab.org/wiki/SFATutorial",
139           author="Thierry Parmentelat, Tony Mack, Scott Baker",
140           author_email="thierry.parmentelat@inria.fr, tmack@princeton.cs.edu, smbaker@gmail.com",
141           download_url = "http://build.onelab.eu/sfa/{v}/sfa-{v}.tar.gz".format(v=version_tag),
142           description="SFA Wrapper with drivers for PlanetLab and IotLab and others",
143           license = license,
144           long_description = long_description,
145           scripts = scripts,
146 )
147