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