0b1a35cb1140e95c2317805fbe3bc6b28c6ecd88
[sfa.git] / setup.py
1 #!/usr/bin/python
2
3 """
4 Installation script for the geniwrapper module
5 """
6
7 from distutils.core import setup, Extension
8 import os, sys
9 import shutil
10
11 version = '0.2'
12 scripts = ['geni/gimport.py', 'geni/plc.py', 'cmdline/sfi.py', 'geni-config-tty']
13 package_dirs = ['geni', 'geni/util', 'geni/methods']
14 data_files = [('/etc/geni/', ['geni/aggregates.xml', 'geni/registries.xml', 'geni/util/geni_config', 'cmdline/configSfi.sh']),
15               ('/etc/init.d/', ['geni/geniwrapper'])
16                 ]
17 symlinks = ['/usr/share/geniwrapper']
18 initscripts = ['/etc/init.d/geniwrapper']
19         
20 if sys.argv[1] in ['uninstall', 'remove', 'delete']:
21     python_path = sys.path
22     site_packages_only = lambda path: path.endswith('site-packages') 
23     site_packages_path = filter(site_packages_only, python_path)
24     add_geni_path = lambda path: path + os.sep + 'geni'
25     site_packages_path = map(add_geni_path, site_packages_path) 
26     remove_dirs = ['/etc/geni/'] + site_packages_path
27     remove_files = ['/usr/bin/gimport.py', '/usr/bin/plc.py', '/usr/bin/sfi.py'] + \
28                     symlinks + initscripts
29     
30     # remove files   
31     for filepath in remove_files:
32         print "removing", filepath, "...",
33         try: 
34             os.remove(filepath)
35             print "success"
36         except: print "failed"
37     # remove directories 
38     for directory in remove_dirs: 
39         print "removing", directory, "...",
40         try: 
41             shutil.rmtree(directory)
42             print "success"
43         except: print "failed"
44  
45 else:
46     setup(name='geniwrapper', 
47       version = version,
48       packages = package_dirs, 
49       data_files = data_files,
50       ext_modules = [],
51       py_modules = [],
52       scripts = scripts,   
53       url = 'http://svn.planet-lab.org/svn/geniwrapper/',
54       description = "Geni API",      
55       long_description = """\
56 Geniwrapper implements the Geni interface which serves 
57 as a layer between the existing PlanetLab interfaces 
58 and the Geni API.
59                     """,
60       license = 'GPL')
61
62     # create symlink to geniwrapper source in /usr/share
63     python_path = sys.path
64     site_packages_only = lambda path: path.endswith('site-packages')
65     site_packages_path = filter(site_packages_only, python_path)
66     add_geni_path = lambda path: path + os.sep + 'geni'
67     site_packages_path = map(add_geni_path, site_packages_path)
68     # python path usualy has /urs/local/lib/ path , filter this out
69     site_packages_path = filter(lambda x: 'local' not in x, site_packages_path) 
70     for src in site_packages_path:
71         for dst in symlinks:
72             try: 
73                 os.symlink(src, dst)
74             except: pass
75     for initscript in initscripts:
76         os.chmod(initscript, 00744)