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