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