forked from cloudmesh-cmd3/user-management
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
281 lines (231 loc) · 9.68 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/usr/bin/env python
import os
import shutil
import yaml
from setuptools import setup, find_packages
from setuptools.command.install import install
from cmd3.console import Console
from passlib.hash import sha256_crypt
from cloudmesh_management.user import Users
from cloudmesh_management.base_user import User
from cloudmesh_database.dbconn import get_mongo_db, DBConnFactory
try:
from cloudmesh_base.util import banner
except:
os.system("pip install cloudmesh_base")
from cloudmesh_base.util import banner
from cloudmesh_base.util import path_expand
from cloudmesh_base.Shell import Shell
from cloudmesh_base.util import auto_create_version
from cloudmesh_base.util import auto_create_requirements
from cloudmesh_management.class_generator import SourceCode
from cloudmesh_management.mongo import Mongo
version = "1.1"
def parse_requirements(filename):
""" load requirements from a pip requirements file """
lineiter = (line.strip() for line in open(filename))
return [line for line in lineiter if line and not line.startswith("#")]
requirements = parse_requirements('requirements.txt')
banner("Installing Cloudmesh Base")
home = os.path.expanduser("~")
auto_create_version("cloudmesh_management", version)
auto_create_requirements(requirements)
class SetupYaml(install):
"""Copies a management yaml file to ~/.cloudmesh."""
description = __doc__
def run(self):
banner("Setup the cloudmesh management yaml files ")
yamlfiles = ['cloudmesh_user.yaml', 'cloudmesh_project.yaml']
dir_path = path_expand("~/.cloudmesh/{0}".format("accounts"))
if not os.path.exists(dir_path):
Shell.mkdir(dir_path)
for yamlfile in yamlfiles:
filename = path_expand("~/.cloudmesh/{0}/{1}".format("accounts", yamlfile))
if os.path.isfile(filename):
Console.error("File {0} already exists. If you like to reinstall it, please remove the file".format(yamlfile))
else:
Console.info("Copying file: {0} -> {1} ".format(path_expand("etc/{0}/{1}".format("accounts", yamlfile)), filename))
shutil.copy("etc/{0}/{1}".format("accounts", yamlfile), path_expand("~/.cloudmesh/{0}/{1}".format("accounts", yamlfile)))
class ResetYaml(install):
"""Copies a management yaml file to ~/.cloudmesh."""
description = __doc__
def run(self):
banner("Reset the cloudmesh management yaml files ")
yaml_files = ['cloudmesh_user.yaml', 'cloudmesh_project.yaml']
dir_path = path_expand("~/.cloudmesh/{0}".format("accounts"))
if not os.path.exists(dir_path):
Shell.mkdir(dir_path)
for yaml_file in yaml_files:
filename = path_expand("~/.cloudmesh/{0}/{1}".format("accounts", yaml_file))
if os.path.isfile(filename):
Console.info("Removing file: {0}".format(filename))
Shell.rm(filename)
Console.info("Copying file: {0} -> {1} ".format(path_expand("etc/{0}/{1}".format("accounts", yaml_file)), filename))
shutil.copy("etc/{0}/{1}".format("accounts", yaml_file), path_expand("~/.cloudmesh/{0}/{1}".format("accounts", yaml_file)))
else:
Console.info("Copying file: {0} -> {1} ".format(path_expand("etc/{0}/{1}".format("accounts", yaml_file)), filename))
shutil.copy("etc/{0}/{1}".format("accounts", yaml_file), path_expand("~/.cloudmesh/{0}/{1}".format("accounts", yaml_file)))
class ReGenFile(install):
def run(self):
banner("Regenerate the python code ")
python_files = ['user', 'project']
for item in python_files:
SourceCode.parse(class_type=item)
class SetupSuperUser(install):
def run(self):
obj = Mongo()
obj.check_mongo()
get_mongo_db("manage", DBConnFactory.TYPE_MONGOENGINE)
banner("Adding Super User")
users = Users()
found = User.objects(username='super')
if not found:
data = User(
status="approved",
title="None",
firstname="Super",
lastname="User",
email="laszewski@gmail.com",
username="super",
active=True,
password=sha256_crypt.encrypt("MyPassword"),
phone="555-555-5555",
department="IT",
institution="IU",
institutionrole="Other",
address="IU",
country="United States(US)",
citizenship="United States(US)",
bio="Manage Project Committee",
url="http://cloudmesh.github.io/cloudmesh.html",
advisor="None",
confirm=sha256_crypt.encrypt("MyPassword"),
projects=[],
)
users.add(data)
users.set_role('admin')
users.set_role('reviewer')
# class SetupYaml(install):
# """Copies a management yaml file to ~/.cloudmesh."""
#
# description = __doc__
#
# def run(self):
# banner("Setup the cloudmesh management yaml files ")
#
# yamlfiles = ['country.yaml']
#
# for yamlfile in yamlfiles:
#
# filename = path_expand("~/.cloudmesh/{0}".format(yamlfile))
#
# if os.path.isfile(filename):
# print ("ERROR: the file {0} already exists".format(yamlfile))
# print
# print ("If you like to reinstall it, please remove the file")
# else:
# print ("Copy file: {0} -> {1} ".format(path_expand("etc/{0}".format(yamlfile)), yamlfile))
# Shell.mkdir("~/.cloudmesh")
# shutil.copy("etc/{0}".format(yamlfile), path_expand("~/.cloudmesh/{0}".format(yamlfile)))
class UploadToPypi(install):
"""Upload the package to pypi."""
def run(self):
os.system("Make clean Install")
os.system("python setup.py install")
banner("Build Distribution")
os.system("python setup.py sdist --format=bztar,zip upload")
class RegisterWithPypi(install):
"""Upload the package to pypi."""
def run(self):
banner("Register with Pypi")
os.system("python setup.py register")
class InstallBase(install):
"""Install the package."""
def run(self):
banner("Install Cloudmesh Management")
obj = Mongo()
obj.check_mongo()
get_mongo_db("manage", DBConnFactory.TYPE_MONGOENGINE)
install.run(self)
banner("Adding Super User")
users = Users()
found = User.objects(username='super')
if not found:
data = User(
status="approved",
title="None",
firstname="Super",
lastname="User",
email="laszewski@gmail.com",
username="super",
active=True,
password=sha256_crypt.encrypt("MyPassword"),
phone="555-555-5555",
department="IT",
institution="IU",
institutionrole="Other",
address="IU",
country="United States(US)",
citizenship="United States(US)",
bio="Manage Project Committee",
url="http://cloudmesh.github.io/cloudmesh.html",
advisor="None",
confirm=sha256_crypt.encrypt("MyPassword"),
projects=[],
)
users.add(data)
class InstallRequirements(install):
"""Install the requirements."""
def run(self):
banner("Install Cloudmesh Base Requirements")
os.system("pip install -r requirements.txt")
class InstallAll(install):
"""Install requirements and the package."""
def run(self):
banner("Install Cloudmesh Base Requirements")
os.system("pip install -r requirements.txt")
banner("Install Cloudmesh Base")
install.run(self)
setup(
name='cloudmesh_management',
version=version,
description='User management for cloudmesh',
# description-file =
# README.rst
author='The Cloudmesh Team',
author_email='laszewski@gmail.com',
url='http://github.org/cloudmesh/management',
classifiers=[
'Intended Audience :: Developers',
'Intended Audience :: Education',
'Intended Audience :: Science/Research',
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.7.9',
'Topic :: Database',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Scientific/Engineering',
'Topic :: System :: Clustering',
'Topic :: System :: Distributed Computing',
'Topic :: System :: Boot',
'Topic :: System :: Systems Administration',
'Framework :: Flask',
'Environment :: OpenStack',
],
packages=find_packages(),
install_requires=requirements,
cmdclass={
'install': InstallBase,
'requirements': InstallRequirements,
'all': InstallAll,
'pypi': UploadToPypi,
'pypiregister': RegisterWithPypi,
'yaml': SetupYaml,
'resetyaml': ResetYaml,
'regenfile': ReGenFile,
'setupsuperuser': SetupSuperUser,
},
)