a first step towards publishing on pypi (so that one can install this using pip insta...
[sfa.git] / setup.py
1 #!/usr/bin/python
2
3 """
4 Installation script for the sfa module
5 """
6
7 # as fas as pushing onto pypi, I have been using this page
8 # http://peterdowns.com/posts/first-time-with-pypi.html
9 # for setting up the whole business
10
11 import sys, os, os.path
12 from glob import glob
13 import shutil
14 from distutils.core import setup
15
16 # while cleaning up we might not have this..
17 try:
18     from sfa.util.version import version_tag
19 except:
20     version_tag='cleaningup'
21
22 scripts = glob("clientbin/*.py") + \
23     [
24     'config/sfa-config-tty',
25     'config/sfa-config',
26 #    'config/gen-sfa-cm-config.py',
27     'sfa/server/sfa-start.py',
28 #    'sfa/server/sfa_component_setup.py',
29     'sfatables/sfatables',
30     'keyconvert/keyconvert.py',
31     'flashpolicy/sfa_flashpolicy.py',
32     ]
33
34 packages = [
35     'sfa',
36     'sfa/trust',
37     'sfa/storage',
38     'sfa/util',
39     'sfa/server',
40     'sfa/methods',
41     'sfa/generic',
42     'sfa/managers',
43     'sfa/importer',
44     'sfa/rspecs',
45     'sfa/rspecs/elements',
46     'sfa/rspecs/elements/versions',
47     'sfa/rspecs/versions',
48     'sfa/client',
49     'sfa/planetlab',
50     'sfa/nitos',
51     'sfa/dummy',
52     'sfa/openstack',
53     'sfa/federica',
54     'sfa/iotlab',
55     'sfa/cortexlab',
56     'sfatables',
57     'sfatables/commands',
58     'sfatables/processors',
59     ]
60
61 initscripts = [ 'sfa' ]
62 if not os.path.isfile('/etc/redhat-release'): initscripts.append('functions.sfa')
63
64 data_files = [ ('/etc/sfa/', [ 'config/aggregates.xml',
65                               'config/registries.xml',
66                               'config/default_config.xml',
67                               'config/api_versions.xml',
68                               'config/sfi_config',
69                               'config/topology',
70                               'sfa/managers/pl/pl.rng',
71                               'sfa/trust/credential.xsd',
72                               'sfa/trust/top.xsd',
73                               'sfa/trust/sig.xsd',
74                               'sfa/trust/xml.xsd',
75                               'sfa/trust/protogeni-rspec-common.xsd',
76                               'flashpolicy/sfa_flashpolicy_config.xml',
77                             ]),
78                ('/etc/sfatables/matches/', glob('sfatables/matches/*.xml')),
79                ('/etc/sfatables/targets/', glob('sfatables/targets/*.xml')),
80                ('/etc/init.d/', [ "init.d/%s"%x for x in initscripts ]),
81                ('/usr/share/sfa/migrations', glob('sfa/storage/migrations/*.*') ),
82                ('/usr/share/sfa/migrations/versions', glob('sfa/storage/migrations/versions/*') ),
83                ('/usr/share/sfa/examples/', glob('sfa/examples/*' ) + [ 'cron.d/sfa.cron' ] ),
84               ]
85
86 # add sfatables processors as data_files
87 processor_files = [f for f in glob('sfatables/processors/*') if os.path.isfile(f)]
88 data_files.append(('/etc/sfatables/processors/', processor_files))
89 processor_subdirs = [d for d in glob('sfatables/processors/*') if os.path.isdir(d)]
90 for d in processor_subdirs:
91     etc_dir = os.path.join("/etc/sfatables/processors", os.path.basename(d))
92     d_files = [f for f in glob(d + '/*') if os.path.isfile(f)]
93     data_files.append((etc_dir, processor_files))
94
95 if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']:
96     python_path = sys.path
97     site_packages_path = [ os.path.join(p,'sfa') for p in python_path if p.endswith('site-packages')]
98     site_packages_path += [ os.path.join(p,'sfatables') for p in python_path if p.endswith('site-packages')]
99     remove_dirs = ['/etc/sfa/', '/etc/sfatables'] + site_packages_path
100     remove_bins = [ '/usr/bin/' + os.path.basename(bin) for bin in scripts ]
101     remove_files = remove_bins + [ "/etc/init.d/%s"%x for x in initscripts ]
102
103     # remove files
104     for filepath in remove_files:
105         print "removing", filepath, "...",
106         try:
107             os.remove(filepath)
108             print "success"
109         except: print "failed"
110     # remove directories
111     for directory in remove_dirs:
112         print "removing", directory, "...",
113         try:
114             shutil.rmtree(directory)
115             print "success"
116         except: print "failed"
117 else:
118     # avoid repeating what's in the specfile already
119     setup(name='sfa',
120           packages = packages,
121           data_files = data_files,
122           version=version_tag,
123           keywords = ['federation','testbeds','SFA','SfaWrap'],
124           url="http://svn.planet-lab.org/wiki/SFATutorial",
125           author="Thierry Parmentelat, Tony Mack, Scott Baker",
126           author_email="thierry.parmentelat@inria.fr, tmack@princeton.cs.edu, smbaker@gmail.com",
127           download_url = "http://build.onelab.eu/sfa/{v}/sfa-{v}.tar.gz".format(v=version_tag),
128           scripts = scripts,
129 )
130