test
[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     ]
35
36 package_dirs = [
37     'sfa', 
38     'sfa/client',
39     'sfa/methods',
40     'sfa/plc',
41     'sfa/server',
42     'sfa/trust',
43     'sfa/util', 
44     'sfa/managers',
45     'sfa/rspecs',
46     'sfa/rspecs/aggregates',
47     'sfatables',
48     'sfatables/commands',
49     'sfatables/processors',
50     ]
51
52
53 data_files = [('/etc/sfa/', [ 'config/aggregates.xml',
54                               'config/registries.xml',
55                               'config/default_config.xml',
56                               'config/sfi_config',
57                               'sfa/managers/pl/pl.rng',
58                               'sfa/trust/credential.xsd',
59                               'sfa/trust/top.xsd',
60                               'sfa/trust/sig.xsd',
61                               'sfa/trust/xml.xsd',
62                               'sfa/trust/protogeni-rspec-common.xsd',
63                             ]),
64               ('/etc/sfatables/matches/', glob('sfatables/matches/*.xml')),
65               ('/etc/sfatables/targets/', glob('sfatables/targets/*.xml')),
66               ('/etc/init.d/', ['sfa/init.d/sfa', 'sfa/init.d/sfa-cm'])]
67
68 # add sfatables processors as data_files
69 processor_files = [f for f in glob('sfatables/processors/*') if os.path.isfile(f)]
70 data_files.append(('/etc/sfatables/processors/', processor_files))
71 processor_subdirs = [d for d in glob('sfatables/processors/*') if os.path.isdir(d)]
72 for d in processor_subdirs:
73     etc_dir = os.path.join("/etc/sfatables/processors", os.path.basename(d))
74     d_files = [f for f in glob(d + '/*') if os.path.isfile(f)]
75     data_files.append((etc_dir, processor_files))
76
77 initscripts = [ '/etc/init.d/sfa', '/etc/init.d/sfa-cm' ]
78
79 if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']:
80     python_path = sys.path
81     site_packages_path = [ os.path.join(p,'sfa') for p in python_path if p.endswith('site-packages')]
82     site_packages_path += [ os.path.join(p,'sfatables') for p in python_path if p.endswith('site-packages')]
83     remove_dirs = ['/etc/sfa/', '/etc/sfatables'] + site_packages_path
84     remove_bins = [ '/usr/bin/' + os.path.basename(bin) for bin in bins ]
85     remove_files = remove_bins + initscripts
86
87     # remove files   
88     for filepath in remove_files:
89         print "removing", filepath, "...",
90         try: 
91             os.remove(filepath)
92             print "success"
93         except: print "failed"
94     # remove directories 
95     for directory in remove_dirs: 
96         print "removing", directory, "...",
97         try: 
98             shutil.rmtree(directory)
99             print "success"
100         except: print "failed"
101 else:
102     # avoid repeating what's in the specfile already
103     setup(name='sfa',
104           packages = package_dirs, 
105           data_files = data_files,
106           ext_modules = [],
107           py_modules = [],
108           scripts = bins)
109