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