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