-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.py
More file actions
117 lines (83 loc) · 3.68 KB
/
Copy pathApp.py
File metadata and controls
117 lines (83 loc) · 3.68 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# /**
# * @author [Jahleel Lacascade]
# * @email [j.lacascade@mail.com]
# * @create date 2021-06-18 10:37:22
# * @modify date 2021-06-18 10:37:22
# */
import platform
import os
import re
import subprocess
import locale
from tools import Mylib
import i18n
class Application():
filesOS = []
i18n = i18n.returnLanguageSystem()
def Initialisation(self):
print("*"*5, self.i18n['START'] , "*"*5)
self.DetectionSysteme()
def DetectionSysteme(self):
"""Détection du system Host et lance le script approprier """
self.ListFileSystemOS()
print("System :", platform.system(), self.i18n['BASE']['detected'])
print("Language:", locale.getdefaultlocale()[0], self.i18n['BASE']['detected'])
if platform.system() == "Linux":
self.LinuxDetecter()
elif platform.system() == "Windows":
self.WindowsDetecter()
else:
print(str(self.i18n['ERROR']['no_charge_sytem']).format(platform.system(), platform.release()))
return False
def LinuxDetecter(self):
"""Vérification du system linux detecter """
choix = str(input("utiliser le Benchmarck par défault y/n: "))
if choix == "y" or choix == "Y":
os_release = dict(Mylib.read_os_releases())
for n, f in enumerate(self.filesOS):
if(re.search(os_release.get('ID')+"_"+os_release.get('VERSION_ID'), f)):
subprocess.run(['python3', f])
else:
print(str(self.i18n['ERROR']['no_benchmarck_system']).format(platform.system(), platform.release()))
restart = str(input(str(self.i18n['INPUT']['restart_script'])))
if restart == "y" or restart == "Y":
self.DetectionSysteme()
else:
return
elif choix == "n" or choix == "N":
for n, f in enumerate(self.filesOS):
print(n, ":", f)
choixBench = int(input("Entre le numero: "))
subprocess.run(['python3', self.filesOS[choixBench]])
def WindowsDetecter(self):
"""Vérification du systeme windows détection"""
choix = str(input(str(self.i18n['INPUT']['choise_benchmarck'])))
if choix == "y" or choix == "Y":
for n,f in enumerate(self.filesOS):
if(re.search(platform.win32_ver()[0], f)):
subprocess.Popen(['powershell',f])
else:
print(str(self.i18n['ERROR']['no_benchmarck_system']).format(platform.system(), platform.release()))
restart = str(input(str(self.i18n['INPUT']['restart_script'])))
if restart == "y" or restart == "Y":
self.DetectionSysteme()
else:
return
elif choix == "n" or choix == "N":
for n, f in enumerate(self.filesOS):
print(n, ":", f)
choixBench = int(input(self.i18n['INPUT']['enter_number']))
subprocess.Popen(['powershell', self.filesOS[choixBench]])
def ListFileSystemOS(self):
"""Liste tout le repertoire lier a la platform (Linux/ Windows)
dans le dossier ./CIS
Returns:
[Array]: [Tableau de type str] chemin absolute des fichiers
"""
for path in os.listdir(os.path.join('CIS', platform.system())):
full_path = os.path.join('CIS', platform.system(), path)
if os.path.isfile(full_path):
self.filesOS.append(full_path)
if __name__ == '__main__':
app = Application()
app.Initialisation()