extract/separate binary clients in sfa/clientbin
[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 bins = glob("sfa/clientbin/*.py") + \
13     [ 
14     'config/sfa-config-tty',
15     'config/gen-sfa-cm-config.py',
16     'sfa/importer/sfa-import-plc.py', 
17     'sfa/importer/sfa-nuke-plc.py', 
18     'sfa/server/sfa-ca.py', 
19     'sfa/server/sfa-start.py', 
20     'sfa/server/sfa-clean-peer-records.py', 
21     'sfa/server/sfa_component_setup.py', 
22     'sfatables/sfatables',
23     'keyconvert/keyconvert.py',
24     'flashpolicy/sfa_flashpolicy.py',
25     ]
26
27 package_dirs = [
28     'sfa', 
29     'sfa/trust',
30     'sfa/storage',
31     'sfa/util', 
32     'sfa/client',
33     'sfa/server',
34     'sfa/methods',
35     'sfa/generic',
36     'sfa/managers',
37     'sfa/importer',
38     'sfa/plc',
39     'sfa/rspecs',
40     'sfa/rspecs/elements',
41     'sfa/rspecs/elements/versions',
42     'sfa/rspecs/versions',
43     'sfatables',
44     'sfatables/commands',
45     'sfatables/processors',
46     ]
47
48 initscripts = [ 'sfa', 'sfa-cm' ]
49
50 data_files = [('/etc/sfa/', [ 'config/aggregates.xml',
51                               'config/registries.xml',
52                               'config/default_config.xml',
53                               'config/sfi_config',
54                               'config/topology',
55                               'sfa/managers/pl/pl.rng',
56                               'sfa/trust/credential.xsd',
57                               'sfa/trust/top.xsd',
58                               'sfa/trust/sig.xsd',
59                               'sfa/trust/xml.xsd',
60                               'sfa/trust/protogeni-rspec-common.xsd',
61                               'flashpolicy/sfa_flashpolicy_config.xml',
62                             ]),
63               ('/etc/sfatables/matches/', glob('sfatables/matches/*.xml')),
64               ('/etc/sfatables/targets/', glob('sfatables/targets/*.xml')),
65               ('/etc/init.d/', [ "init.d/%s"%x for x in initscripts ]),
66               ('/usr/share/sfa/', [ 'sfa/storage/sfa.sql' ] ),
67               ]
68
69 # add sfatables processors as data_files
70 processor_files = [f for f in glob('sfatables/processors/*') if os.path.isfile(f)]
71 data_files.append(('/etc/sfatables/processors/', processor_files))
72 processor_subdirs = [d for d in glob('sfatables/processors/*') if os.path.isdir(d)]
73 for d in processor_subdirs:
74     etc_dir = os.path.join("/etc/sfatables/processors", os.path.basename(d))
75     d_files = [f for f in glob(d + '/*') if os.path.isfile(f)]
76     data_files.append((etc_dir, processor_files))
77
78 if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']:
79     python_path = sys.path
80     site_packages_path = [ os.path.join(p,'sfa') for p in python_path if p.endswith('site-packages')]
81     site_packages_path += [ os.path.join(p,'sfatables') for p in python_path if p.endswith('site-packages')]
82     remove_dirs = ['/etc/sfa/', '/etc/sfatables'] + site_packages_path
83     remove_bins = [ '/usr/bin/' + os.path.basename(bin) for bin in bins ]
84     remove_files = remove_bins + [ "/etc/init.d/%s"%x for x in initscripts ]
85
86     # remove files   
87     for filepath in remove_files:
88         print "removing", filepath, "...",
89         try: 
90             os.remove(filepath)
91             print "success"
92         except: print "failed"
93     # remove directories 
94     for directory in remove_dirs: 
95         print "removing", directory, "...",
96         try: 
97             shutil.rmtree(directory)
98             print "success"
99         except: print "failed"
100 else:
101     # avoid repeating what's in the specfile already
102     setup(name='sfa',
103           packages = package_dirs, 
104           data_files = data_files,
105           ext_modules = [],
106           py_modules = [],
107           scripts = bins)
108