adding PGv2 RSpec support to the vini aggregate manager
[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-ca.py', 
18     'sfa/server/sfa-server.py', 
19     'sfa/server/sfa-clean-peer-records.py', 
20     'sfa/server/sfa_component_setup.py', 
21     'sfa/client/sfi.py', 
22     'sfa/client/getNodes.py',
23     'sfa/client/getRecord.py',
24     'sfa/client/setRecord.py',
25     'sfa/client/sfadump.py',
26     'sfa/client/sfiListNodes.py',
27     'sfa/client/sfiListSlivers.py',
28     'sfa/client/sfiAddSliver.py',
29     'sfa/client/sfiDeleteSliver.py',
30     'sfa/client/sfiAddAttribute.py',
31     'sfa/client/sfiDeleteAttribute.py',
32     'sfatables/sfatables',
33     'keyconvert/keyconvert.py',
34     'flashpolicy/sfa_flashpolicy.py',
35     ]
36
37 package_dirs = [
38     'sfa', 
39     'sfa/client',
40     'sfa/methods',
41     'sfa/plc',
42     'sfa/server',
43     'sfa/trust',
44     'sfa/util', 
45     'sfa/managers',
46     'sfa/managers/vini',
47     'sfa/rspecs',
48     'sfa/rspecs/elements',
49     'sfa/rspecs/versions',
50     'sfatables',
51     'sfatables/commands',
52     'sfatables/processors',
53     'flashpolicy',
54     ]
55
56
57 data_files = [('/etc/sfa/', [ 'config/aggregates.xml',
58                               'config/registries.xml',
59                               'config/default_config.xml',
60                               'config/sfi_config',
61                               'sfa/managers/pl/pl.rng',
62                               'sfa/trust/credential.xsd',
63                               'sfa/trust/top.xsd',
64                               'sfa/trust/sig.xsd',
65                               'sfa/trust/xml.xsd',
66                               'sfa/trust/protogeni-rspec-common.xsd',
67                               'flashpolicy/sfa_flashpolicy_config.xml',
68                             ]),
69               ('/etc/sfatables/matches/', glob('sfatables/matches/*.xml')),
70               ('/etc/sfatables/targets/', glob('sfatables/targets/*.xml')),
71               ('/etc/init.d/', ['sfa/init.d/sfa', 'sfa/init.d/sfa-cm'])]
72
73 # add sfatables processors as data_files
74 processor_files = [f for f in glob('sfatables/processors/*') if os.path.isfile(f)]
75 data_files.append(('/etc/sfatables/processors/', processor_files))
76 processor_subdirs = [d for d in glob('sfatables/processors/*') if os.path.isdir(d)]
77 for d in processor_subdirs:
78     etc_dir = os.path.join("/etc/sfatables/processors", os.path.basename(d))
79     d_files = [f for f in glob(d + '/*') if os.path.isfile(f)]
80     data_files.append((etc_dir, processor_files))
81
82 initscripts = [ '/etc/init.d/sfa', '/etc/init.d/sfa-cm' ]
83
84 if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']:
85     python_path = sys.path
86     site_packages_path = [ os.path.join(p,'sfa') for p in python_path if p.endswith('site-packages')]
87     site_packages_path += [ os.path.join(p,'sfatables') for p in python_path if p.endswith('site-packages')]
88     remove_dirs = ['/etc/sfa/', '/etc/sfatables'] + site_packages_path
89     remove_bins = [ '/usr/bin/' + os.path.basename(bin) for bin in bins ]
90     remove_files = remove_bins + initscripts
91
92     # remove files   
93     for filepath in remove_files:
94         print "removing", filepath, "...",
95         try: 
96             os.remove(filepath)
97             print "success"
98         except: print "failed"
99     # remove directories 
100     for directory in remove_dirs: 
101         print "removing", directory, "...",
102         try: 
103             shutil.rmtree(directory)
104             print "success"
105         except: print "failed"
106 else:
107     # avoid repeating what's in the specfile already
108     setup(name='sfa',
109           packages = package_dirs, 
110           data_files = data_files,
111           ext_modules = [],
112           py_modules = [],
113           scripts = bins)
114