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