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