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