-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
81 lines (68 loc) · 2.87 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
import getpass
import re
from setuptools import setup
from setuptools.command.install import install
plugin_name = 'scidbplugin.py'
config_name = 'scidbcluster.config'
config_path = '~/.starcluster'
class RegisterPluginDecorator(install):
def run(self):
install.run(self)
self.ensure_include(config_name, config_path)
self.set_keyname(os.path.join(config_path, config_name))
def ensure_include(self, name, path, root='config'):
filename = os.path.join(path, root)
config = self.get_config(filename)
if not self.already_included(name, config):
print 'Adding include to ' + filename
self.add_include(config, filename)
else:
print 'Root configuration already appears to include ' + config_name
@staticmethod
def get_config(path):
with open(os.path.expanduser(path), 'r') as file:
return file.read()
@staticmethod
def already_included(config_name, config):
return re.search(r'^INCLUDE\w*=\w*.*' + re.escape(os.path.join(config_path, config_name)),
config,
flags=re.IGNORECASE | re.MULTILINE)
@staticmethod
def add_include(config, path):
insertion = 'INCLUDE={}'.format(os.path.join(config_path, config_name))
# No global section
if not '[global]' in config:
config = '[global]\n{}\n{}'.format(insertion, config)
# Global section with existing INCLUDE pair
elif re.search(r'^INCLUDE\w*=\w*', config, flags=re.IGNORECASE | re.MULTILINE):
config = re.sub(r'^INCLUDE\w*=\w*', insertion + ',', config, flags=re.IGNORECASE | re.MULTILINE)
# Global section, no INCLUDE pair
else:
config = config.replace('[global]', '[global]\n' + insertion)
with open(os.path.expanduser(path), 'w') as file:
file.write(config)
@staticmethod
def set_keyname(path):
username = os.getenv("SUDO_USER") or getpass.getuser()
config = RegisterPluginDecorator.get_config(path)
config = config.replace('KEYNAME = AWSKey', 'KEYNAME = {}Key'.format(username))
print 'Default AWS key is {}Key'.format(username)
with open(os.path.expanduser(path), 'w') as file:
file.write(config)
setup(
name='SciDB-Starcluster',
version=1.0,
url='https://github.com/BrandonHaynes/scidb-starcluster',
author='Brandon Haynes',
author_email='[email protected]',
description=('A SciDB source installation plugin for Starcluster.'),
license='BSD',
include_package_data=True,
packages=[],
scripts=[],
data_files=[(os.path.expanduser('~/.starcluster/plugins'), [plugin_name]),
(os.path.expanduser('~/.starcluster'), [config_name])],
install_requires=['StarCluster >= 0.95.6'],
cmdclass={'install': RegisterPluginDecorator},
)