oops, the cm cleanup was not complete
[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 scripts = glob("clientbin/*.py") + \
13     [ 
14     'config/sfa-config-tty',
15     'config/sfa-config',
16 #    'config/gen-sfa-cm-config.py',
17     'sfa/server/sfa-start.py', 
18 #    'sfa/server/sfa_component_setup.py', 
19     'sfatables/sfatables',
20     'keyconvert/keyconvert.py',
21     'flashpolicy/sfa_flashpolicy.py',
22     ]
23
24 packages = [
25     'sfa', 
26     'sfa/trust',
27     'sfa/storage',
28     'sfa/util', 
29     'sfa/server',
30     'sfa/methods',
31     'sfa/generic',
32     'sfa/managers',
33     'sfa/importer',
34     'sfa/rspecs',
35     'sfa/rspecs/elements',
36     'sfa/rspecs/elements/versions',
37     'sfa/rspecs/versions',
38     'sfa/client',
39     'sfa/planetlab',
40     'sfa/nitos',
41     'sfa/dummy',
42     'sfa/openstack',
43     'sfa/federica',
44     'sfatables',
45     'sfatables/commands',
46     'sfatables/processors',
47     ]
48
49 initscripts = [ 'sfa', 
50 #                'sfa-cm',
51                 ]
52
53 data_files = [ ('/etc/sfa/', [ 'config/aggregates.xml',
54                               'config/registries.xml',
55                               'config/default_config.xml',
56                               'config/sfi_config',
57                               'config/topology',
58                               'sfa/managers/pl/pl.rng',
59                               'sfa/trust/credential.xsd',
60                               'sfa/trust/top.xsd',
61                               'sfa/trust/sig.xsd',
62                               'sfa/trust/xml.xsd',
63                               'sfa/trust/protogeni-rspec-common.xsd',
64                               'flashpolicy/sfa_flashpolicy_config.xml',
65                             ]),
66                ('/etc/sfatables/matches/', glob('sfatables/matches/*.xml')),
67                ('/etc/sfatables/targets/', glob('sfatables/targets/*.xml')),
68                ('/etc/init.d/', [ "init.d/%s"%x for x in initscripts ]),
69                ('/usr/share/sfa/migrations', glob('sfa/storage/migrations/*.*') ),
70                ('/usr/share/sfa/migrations/versions', glob('sfa/storage/migrations/versions/*') ),
71                ('/usr/share/sfa/examples/', glob('sfa/examples/*' ) + [ 'cron.d/sfa.cron' ] ),
72               ]
73
74 # add sfatables processors as data_files
75 processor_files = [f for f in glob('sfatables/processors/*') if os.path.isfile(f)]
76 data_files.append(('/etc/sfatables/processors/', processor_files))
77 processor_subdirs = [d for d in glob('sfatables/processors/*') if os.path.isdir(d)]
78 for d in processor_subdirs:
79     etc_dir = os.path.join("/etc/sfatables/processors", os.path.basename(d))
80     d_files = [f for f in glob(d + '/*') if os.path.isfile(f)]
81     data_files.append((etc_dir, processor_files))
82
83 if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']:
84     python_path = sys.path
85     site_packages_path = [ os.path.join(p,'sfa') for p in python_path if p.endswith('site-packages')]
86     site_packages_path += [ os.path.join(p,'sfatables') for p in python_path if p.endswith('site-packages')]
87     remove_dirs = ['/etc/sfa/', '/etc/sfatables'] + site_packages_path
88     remove_bins = [ '/usr/bin/' + os.path.basename(bin) for bin in scripts ]
89     remove_files = remove_bins + [ "/etc/init.d/%s"%x for x in initscripts ]
90
91     # remove files   
92     for filepath in remove_files:
93         print "removing", filepath, "...",
94         try: 
95             os.remove(filepath)
96             print "success"
97         except: print "failed"
98     # remove directories 
99     for directory in remove_dirs: 
100         print "removing", directory, "...",
101         try: 
102             shutil.rmtree(directory)
103             print "success"
104         except: print "failed"
105 else:
106     # avoid repeating what's in the specfile already
107     setup(name='sfa',
108           packages = packages, 
109           data_files = data_files,
110           scripts = scripts)
111