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