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