-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.py
143 lines (120 loc) · 4.3 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import os
import pwd
import sys
from urlparse import urlparse
import mbs.version
from setuptools import setup, find_packages
# NOTE: http://bugs.python.org/issue15881#msg170215
try:
import multiprocessing
except ImportError:
pass
###############################################################################
def parse_archive(line):
parts = urlparse(line)
fragment = parts.fragment
# deal with older python versions where urlparse doesnt parse git uris
if not fragment and "#" in line:
fragment = line.split("#")[1]
if not fragment:
raise ValueError('no egg specified')
if fragment.count('-') > 1:
raise ValueError('hyphens in package names should be replaced with '
'underscores')
return line, fragment.split('=')[1].replace('-', '==')
###############################################################################
def requirements():
inst_reqs = []
test_reqs = []
dep_links = []
reqs = inst_reqs
setup_dir = os.path.dirname(os.path.abspath(__file__))
for line in open(os.path.join(setup_dir, 'requirements.txt')):
line = line.strip()
if len(line) == 0:
continue
elif line.startswith('#'):
if 'core' in line.lower():
reqs = inst_reqs
elif 'test' in line.lower():
reqs = test_reqs
continue
if line.startswith('-e'):
raise ValueError('editable mode not supported')
elif '://' in line:
link, req = parse_archive(line)
dep_links.append(link)
reqs.append(req)
else:
reqs.append(line)
return {'links': dep_links, 'core': inst_reqs, 'test': test_reqs}
###############################################################################
def create_default_config():
from mbs.mbs_config import MBS_CONF_PATH
mbs_conf = os.path.expanduser(MBS_CONF_PATH)
# do nothing if conf already exists
print "Checking if configuration '%s' exists..." % mbs_conf
if os.path.exists(mbs_conf):
print "Config '%s' already exists" % mbs_conf
return
print "Configuration '%s' does not exist. Creating default..." % mbs_conf
login = os.getlogin()
conf_dir = os.path.dirname(mbs_conf)
owner = pwd.getpwnam(login)
owner_uid = owner[2]
owner_gid = owner[3]
# if the conf dir does not exist then create it and change owner
# This is needs so when pip install is run with sudo then the owner
# should be logged in user instead of root
if not os.path.exists(conf_dir):
print "Creating conf dir '%s'" % conf_dir
os.makedirs(conf_dir)
print "chown conf dir '%s' to owner uid %s, gid %s" % (conf_dir, owner_uid, owner_gid)
os.chown(conf_dir, owner_uid, owner_gid)
print "Chmod conf dir '%s' to 00755" % conf_dir
os.chmod(conf_dir, 00755)
default_conf = {
"databaseURI": "YOUR DATABASE URI",
"engines":[
{
"_type": "BackupEngine",
"_id": "DEFAULT",
"maxWorkers": 10,
"tempDir": "~/backup_temp",
"commandPort": 8888,
"tags": None
}
]
}
from mbs.utils import document_pretty_string
conf_file = open(mbs_conf, mode="w")
conf_file.write(document_pretty_string(default_conf))
# chown conf file
print "chown conf file '%s' to owner uid %s, gid %s" % (mbs_conf, owner_uid, owner_gid)
os.chown(mbs_conf, owner_uid, owner_gid)
print "Chmod conf file '%s' to 00644" % mbs_conf
os.chmod(mbs_conf, 00644)
print "Successfully created configuration '%s'!" % mbs_conf
setup(
name='mbs',
version=mbs.version.get_mbs_version(),
scripts=[
'bin/mbs',
'bin/st'
],
packages=find_packages(),
package_data={
"mbs.notification": ["*.json"]
},
install_requires=requirements()['core'],
tests_require=requirements()['test'],
dependency_links=requirements()['links'],
test_suite='nose.collector'
)
### execute this block after setup "install" command is complete
if "install" in sys.argv:
try:
create_default_config()
except Exception, e:
print ("WARNING: Error while attempting to create default config."
"Please create it manually.")