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