97309e3bc588c3a3d5bf0095c0ab2ff429c30b9c
[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 import shutil
9 from distutils.core import setup
10
11 bins = [ 'config/sfa-config-tty',
12             'sfa/plc/sfa-import-plc.py', 
13             'sfa/plc/sfa-nuke-plc.py', 
14             'sfa/server/sfa-server.py', 
15             'sfa/client/sfi.py', 
16             'sfa/client/getNodes.py',
17             'sfa/client/getRecord.py',
18             'sfa/client/setRecord.py',
19             'sfa/client/genidump.py',
20             ]
21 remove_bins = [ '/usr/bin/' + os.path.basename(bin) for bin in bins ]
22
23 package_dirs = [ 'sfa', 
24                  'sfa/client',
25                  'sfa/methods',
26                  'sfa/plc',
27                  'sfa/server',
28                  'sfa/trust',
29                  'sfa/util', 
30                  'sfa/rspecs',
31                  'sfa/rspecs/aggregates',
32                  'sfa/rspecs/aggregates/vini'
33                  ]
34 data_files = [ ('/etc/sfa/', [ 'config/aggregates.xml', 
35                                'config/registries.xml', 
36                                'config/sfa_config', 
37                                'config/sfi_config',
38                                ]),
39                ('/etc/init.d/', ['sfa/init.d/sfa']),
40                ]
41 initscripts = [ '/etc/init.d/sfa' ]
42         
43 if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']:
44     python_path = sys.path
45     site_packages_path = [ path + os.sep + 'sfa' for path in python_path if path.endswith('site-packages')]
46     remove_dirs = ['/etc/sfa/'] + site_packages_path
47     remove_files = remove_bins + initscripts
48     
49     # remove files   
50     for filepath in remove_files:
51         print "removing", filepath, "...",
52         try: 
53             os.remove(filepath)
54             print "success"
55         except: print "failed"
56     # remove directories 
57     for directory in remove_dirs: 
58         print "removing", directory, "...",
59         try: 
60             shutil.rmtree(directory)
61             print "success"
62         except: print "failed"
63  
64 else:
65     
66     # avoid repeating what's in the specfile already
67     setup(name='sfa',
68           packages = package_dirs, 
69           data_files = data_files,
70           ext_modules = [],
71           py_modules = [],
72           scripts = bins,   
73           )
74