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