-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
101 lines (78 loc) · 3.51 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
import csv
import os
import re
BASE_NAME = os.path.abspath('.')
def read_commandes_list(delimiter=','):
with open(os.path.join(BASE_NAME, 'data/commandes.csv'), 'r+', encoding='utf-8') as f:
reader = csv.reader(f, delimiter=delimiter)
return list(reader)
def set_pip_version(o, pip):
return re.sub('pip', pip, o, 1)
class Setup:
__commandes = []
def __init__(self, pip='', python_version='', conda=0, conda_environement='base', gpu=0):
self.read_commandes_list()
commandes = self.get_commandes()
if gpu == 1:
print("**************************Mode GPU************************")
for i in range(5, 12):
commandes[i][0] = re.sub('tensorflow', 'tensorflow-gpu', commandes[i][0], 1)
if conda == 1:
for i in range(len(commandes)):
commandes[i][0] = re.sub('pip install', 'conda install --name '+conda_environement, commandes[i][0], 1)
if len(python_version) != 0:
commandes[1] = [re.sub('python', python_version, commandes[1][0]), '1']
if len(pip) != 0:
for i in range(2, len(commandes)):
commandes[i][0] = set_pip_version(commandes[i][0], pip)
self.__commandes = commandes
print("""
_______. _______ .___________. __ __ .______
/ || ____|| || | | | | _ \
| (----`| |__ `---| |----`| | | | | |_) |
\ \ | __| | | | | | | | ___/
.----) | | |____ | | | `--' | | |
|_______/ |_______| |__| \______/ | _|
""")
def get_commandes(self):
return self.__commandes
def set_commandes(self, new_commandes_list):
self.__commandes = new_commandes_list
def add_command(self, new_command):
new_command = [new_command, 0]
with open(os.path.join(BASE_NAME, 'data/commandes.csv'), 'a+', newline='', encoding='utf-8') as file:
writer = csv.writer(file, delimiter=',')
writer.writerow(new_command)
self.read_commandes_list()
def read_commandes_list(self, delimiter=','):
with open(os.path.join(BASE_NAME, 'data/commandes.csv'), 'r+', encoding='utf-8') as f:
reader = csv.reader(f, delimiter=delimiter)
self.set_commandes(list(reader))
def update_commandes_list(self, file_name=os.path.join(BASE_NAME, 'data/commandes.csv'), delimiter=','):
with open(file_name, 'w+', newline='', encoding='utf-8') as f:
writer = csv.writer(f, delimiter=delimiter)
for p in self.get_commandes():
writer.writerow(p)
def start(self, updtae=0, mac=100):
commandes = list(self.get_commandes())
print(commandes)
for i in range(1, len(commandes)):
os.system(commandes[i][0])
commandes[i][1] = 1
self.__commandes.pop(0)
self.__commandes.insert(0, ['commande', 'status'])
if mac == 1:
print("MAC")
os.system('pip install https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.0.0-py3-none-any.whl')
if updtae == 1:
self.__commandes.pop(0)
self.__commandes.insert(0, ['commande', 'status'])
self.update_commandes_list()
print("""
_______ ______ .__ __. _______
| \ / __ \ | \ | | | ____|
| .--. | | | | | \| | | |__
| | | | | | | | . ` | | __|
| '--' | `--' | | |\ | | |____
|_______/ \______/ |__| \__| |_______|
""")