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