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