-
Notifications
You must be signed in to change notification settings - Fork 25
/
setup.py
159 lines (134 loc) · 5.88 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# The MIT License
# Copyright (c) 2012 ObjectLabs Corporation
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
###############################################################################
# Imports
###############################################################################
import os
import shutil
import pwd
import sys
import inspect
from setuptools import setup, find_packages
import mongoctl.version
###############################################################################
# CONSTANTS
###############################################################################
SAMPLE_CONF_FILE_NAMES = ["mongoctl.config",
"servers.config",
"clusters.config"]
###############################################################################
# Calculating sample_conf_files
###############################################################################
def get_sample_conf_dir():
this_dir = os.path.dirname(
inspect.getfile(inspect.currentframe()))
return os.path.join(this_dir, "mongoctl/sample_conf")
###############################################################################
def copy_sample_configs():
# create the dot_mongoctl_dir if it does not exist
# mode of folder is user RW and R for group and others
try:
login = os.getlogin()
home_dir = os.path.expanduser( "~%s" % login)
dot_mongoctl_dir = os.path.join(home_dir, ".mongoctl")
owner = pwd.getpwnam(login)
owner_uid = owner[2]
owner_gid = owner[3]
if not os.path.exists(dot_mongoctl_dir):
os.makedirs(dot_mongoctl_dir)
else:
return True
os.chown(dot_mongoctl_dir, owner_uid, owner_gid)
os.chmod(dot_mongoctl_dir, 00755)
sample_conf_dir = get_sample_conf_dir()
for fname in SAMPLE_CONF_FILE_NAMES:
data_file_path = os.path.join(dot_mongoctl_dir, fname)
if not os.path.exists(data_file_path):
src_file = os.path.join(sample_conf_dir, fname)
# copy file
print ("Creating sample configuration file '%s' in '%s' " %
(fname,dot_mongoctl_dir))
shutil.copyfile(src_file, data_file_path)
# make file writable
os.chown(data_file_path, owner_uid, owner_gid)
os.chmod(data_file_path, 00644)
except Exception, e:
print ("Error while copying sample config files. "
"This is not harmful. The error happened while trying to "
"determine owner/mode of sample config files: %s" % e)
###############################################################################
def install_latest_mongodb():
try:
from mongoctl.commands.misc.install import install_mongodb
install_mongodb(None)
except Exception, e:
#print "Unable to install latest mongodb. Cause: '%s' " % e
pass
###############################################################################
# mongoct post install
def mongoctl_post_install():
configs_exists = copy_sample_configs()
if not configs_exists:
install_latest_mongodb()
###############################################################################
install_requires = [
"boto==2.45.0",
"dargparse>=0.2.5",
"psutil==1.2.1",
"pymo==0.2.0",
"pymongo==3.6.1",
"distutils2==1.0a4",
"JSON-minify==0.3.0"
]
###############################################################################
#TODO XXX and force python version to be 2.7.10+ ?
try:
version_info = sys.version_info
if version_info[0] == 2 and version_info[2] < 10:
install_requires.append('certifi==2016.2.28')
except:
pass
###############################################################################
# Setup
###############################################################################
setup(
name='mongoctl',
version=mongoctl.version.MONGOCTL_VERSION,
author='MongoLab team',
author_email='team@mongolab.com',
description='MongoDB command line utility',
long_description="mongoctl is a lightweight command line utility that simplifies the"
" installation of MongoDB and management of MongoDB servers and replica set clusters. It is"
" particularly useful if you maintain many MongoDB environments with"
" lots of configurations to manage.",
packages=find_packages(),
package_data = {'mongoctl.tests.testing_conf':
['*.config'],
'mongoctl.sample_conf':
['*.config']},
test_suite="mongoctl.tests.test_suite",
include_package_data=True,
scripts=['bin/mongoctl'],
url='https://github.com/mongolab/mongoctl',
license='MIT',
install_requires=install_requires,
)
### execute this block after setup "install" command is complete
if "install" in sys.argv:
mongoctl_post_install()