- make matches and targets loaded w/o making hem python packages
[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
25 package_dirs = [ 'sfa', 
26                  'sfa/client',
27                  'sfa/methods',
28                  'sfa/plc',
29                  'sfa/server',
30                  'sfa/trust',
31                  'sfa/util', 
32                  'sfa/rspecs',
33                  'sfa/rspecs/aggregates',
34                  'sfa/rspecs/aggregates/vini',
35                  'sfatables',
36                  'sfatables/commands',
37                  'sfatables/processors',
38                  ]
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/*.xml')),
46               ('/etc/sfatables/targets/', glob('sfatables/targets/*.xml')),
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 = [ os.path.join(p,'sfa') for p in python_path if p.endswith('site-packages')]
63     site_packages_path += [ os.path.join(p,'sfatables') for p in python_path if p.endswith('site-packages')]
64     remove_dirs = ['/etc/sfa/', '/etc/sfatables'] + site_packages_path
65     remove_bins = [ '/usr/bin/' + os.path.basename(bin) for bin in bins ]
66     remove_files = remove_bins + initscripts
67
68     # remove files   
69     for filepath in remove_files:
70         print "removing", filepath, "...",
71         try: 
72             os.remove(filepath)
73             print "success"
74         except: print "failed"
75     # remove directories 
76     print remove_dirs
77     for directory in remove_dirs: 
78         print "removing", directory, "...",
79         try: 
80             shutil.rmtree(directory)
81             print "success"
82         except: print "failed"
83 else:
84     # avoid repeating what's in the specfile already
85     setup(name='sfa',
86           packages = package_dirs, 
87           data_files = data_files,
88           ext_modules = [],
89           py_modules = [],
90           scripts = bins)
91