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