more robust setup.py for cleanups
[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/elements/v3',
44     'sfa/rspecs/versions',
45     'sfa/client',
46     'sfa/planetlab',
47     'sfa/nitos',
48     'sfa/dummy',
49     'sfa/openstack',
50     'sfa/federica',
51     'sfa/senslab',
52     'sfatables',
53     'sfatables/commands',
54     'sfatables/processors',
55     ]
56
57 initscripts = [ 'sfa' ]
58 if not os.path.isfile('/etc/redhat-release'): initscripts.append('functions.sfa')
59
60 data_files = [ ('/etc/sfa/', [ 'config/aggregates.xml',
61                               'config/registries.xml',
62                               'config/default_config.xml',
63                               'config/api_versions.xml',
64                               'config/sfi_config',
65                               'config/topology',
66                               'sfa/managers/pl/pl.rng',
67                               'sfa/trust/credential.xsd',
68                               'sfa/trust/top.xsd',
69                               'sfa/trust/sig.xsd',
70                               'sfa/trust/xml.xsd',
71                               'sfa/trust/protogeni-rspec-common.xsd',
72                               'flashpolicy/sfa_flashpolicy_config.xml',
73                             ]),
74                ('/etc/sfatables/matches/', glob('sfatables/matches/*.xml')),
75                ('/etc/sfatables/targets/', glob('sfatables/targets/*.xml')),
76                ('/etc/init.d/', [ "init.d/%s"%x for x in initscripts ]),
77                ('/usr/share/sfa/migrations', glob('sfa/storage/migrations/*.*') ),
78                ('/usr/share/sfa/migrations/versions', glob('sfa/storage/migrations/versions/*') ),
79                ('/usr/share/sfa/examples/', glob('sfa/examples/*' ) + [ 'cron.d/sfa.cron' ] ),
80               ]
81
82 # add sfatables processors as data_files
83 processor_files = [f for f in glob('sfatables/processors/*') if os.path.isfile(f)]
84 data_files.append(('/etc/sfatables/processors/', processor_files))
85 processor_subdirs = [d for d in glob('sfatables/processors/*') if os.path.isdir(d)]
86 for d in processor_subdirs:
87     etc_dir = os.path.join("/etc/sfatables/processors", os.path.basename(d))
88     d_files = [f for f in glob(d + '/*') if os.path.isfile(f)]
89     data_files.append((etc_dir, processor_files))
90
91 if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']:
92     python_path = sys.path
93     site_packages_path = [ os.path.join(p,'sfa') for p in python_path if p.endswith('site-packages')]
94     site_packages_path += [ os.path.join(p,'sfatables') for p in python_path if p.endswith('site-packages')]
95     remove_dirs = ['/etc/sfa/', '/etc/sfatables'] + site_packages_path
96     remove_bins = [ '/usr/bin/' + os.path.basename(bin) for bin in scripts ]
97     remove_files = remove_bins + [ "/etc/init.d/%s"%x for x in initscripts ]
98
99     # remove files   
100     for filepath in remove_files:
101         print "removing", filepath, "...",
102         try: 
103             os.remove(filepath)
104             print "success"
105         except: print "failed"
106     # remove directories 
107     for directory in remove_dirs: 
108         print "removing", directory, "...",
109         try: 
110             shutil.rmtree(directory)
111             print "success"
112         except: print "failed"
113 else:
114     # avoid repeating what's in the specfile already
115     setup(name='sfa',
116           packages = packages, 
117           data_files = data_files,
118           scripts = scripts,
119           url="http://svn.planet-lab.org/wiki/SFATutorial",
120           author="Thierry Parmentelat, Tony Mack, Scott Baker",
121           author_email="thierry.parmentelat@inria.fr, tmack@princeton.cs.edu, smbaker@gmail.com",
122           version=version_tag)
123