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