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