-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyenv.py
More file actions
99 lines (91 loc) · 3.55 KB
/
Copy pathpyenv.py
File metadata and controls
99 lines (91 loc) · 3.55 KB
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
#!/usr/bin/python3.7
# -*- coding: utf-8 -*-
import argparse
import os
import sys
import time
import traceback
__author__ = "oscar pulido"
parser = argparse.ArgumentParser()
parser.add_argument("-n", "--name",
help="name of virtual environment",
type=str, default="virtual_env")
parser.add_argument("-l", "--list",
help="list of packages to install in virtual"
" environment separated by , "
"for example module1,module2,module3,.......",
type=str, default=None)
parser.add_argument("-d", "--directory",
help="dir where venv will be created, put the directory "
"from your actual path to where venv will be created",
type=str, default=None)
parser.add_argument("-r", "--requirements",
help="file that contain the modules to install is "
"recomenden call it requirements.txt, but feel free to "
"call it whatever you want",
type=str, default=None)
def main(margs=None):
if margs is None:
margs = sys.argv[1:]
parsed_margs = argparse.ArgumentParser(parents=[parser],
add_help=False).parse_args(margs)
pymods = parsed_margs.list
venvname = parsed_margs.name
venvdir = parsed_margs.directory
reqfile = parsed_margs.requirements
spacecmd = "echo -e '\n'"
if parsed_margs.requirements is None:
os.chdir(venvdir)
try:
modl.switch(py27,py34)
print("\nmodule ", py27, "to", py34,"\n")
except Exception as e:
print(e)
traceback.print_exc()
time.sleep(5)
modl.load("python/msdlenv/qa")
time.sleep(5)
msvenv = "msvenv {}\n".format(venvname)
os.system(msvenv)
print("venv {} was created\n".format(venvname))
time.sleep(3)
if parsed_margs.list is not None:
module_inst = "{}_modules_installer.sh".format(venvname)
os.system("touch {}".format(module_inst))
os.system("echo 'source {}/bin/activate' >>"
" {}".format(venvname, module_inst))
pymods = parsed_margs.list.split(',')
for pymod in pymods:
os.system("echo 'msdlpkg install {}' >> "
"{}".format(pymod, module_inst))
os.system("echo {} >> {}".format(spacecmd,module_inst))
os.system("chmod 764 {}".format(module_inst))
os.system(module_inst)
else:
print("/n no modules provided venv {} successfully "
"created".format(venvname))
else:
os.chdir(venvdir)
try:
modl.switch(py27,py34)
print("\nmodule ", py27, "to", py34,"\n")
except Exception as e:
print(e)
traceback.print_exc()
time.sleep(5)
modl.load("python/msdlenv/qa")
time.sleep(3)
module_inst = "{}_modules_installer.sh".format(venvname)
with open(reqfile, 'r') as modfile:
newmods = modfile.read()
newmods = newmods.split()
for newmod in newmods:
os.system("echo 'msdlpkg install {}' >> "
"{}".format(newmod, module_inst))
os.system("echo {} >> {}".format(spacecmd,module_inst))
os.system("*_modules_installer.sh")
if __name__ == "__main__":
try:
sys.exit(main())
except KeyboardInterrupt as k:
print("Forced Exit by user")