-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstat0.py
More file actions
72 lines (58 loc) · 2.12 KB
/
stat0.py
File metadata and controls
72 lines (58 loc) · 2.12 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
import psutil as pl
import os
import time
import datetime
from random import randrange as rr
class Machine:
def __init__(self):
self.status = 0
def check_if_busy(self):
self.status = 0
for proc in pl.process_iter():
try:
if "safir.exe" in proc.name().lower():
self.status = 1
return "I am busy, McSAFIR is running"
elif "ozone.exe" in proc.name().lower():
self.status = 2
return "I am busy, MulitZone is running"
except (pl.NoSuchProcess, pl.AccessDenied, pl.ZombieProcess):
pass
free_tab = ["Machine is free, let's give it some job to do!", "I'm ready for new challenge!", \
"Waiting for your commands, sir!", "Bored and antsy...", "I'd love to calculate something!", \
"Don't let me wait with the next job", "Is it a vacation or what?", "What about little simulating?",\
"Don't you have some simulations to conduct?"]
return free_tab[rr(len(free_tab))]
def elapsed(self):
pass
def details(self):
stat_tab = [self.check_if_busy()]
if self.status:
pass
def write_stat(self, stat):
os.chdir("C:\MultiZone")
for i in range(5):
try:
with open("stat.txt", "w") as file:
file.write(datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
file.write(' -- ' + stat)
except PermissionError:
time.sleep(1)
print("Warning: Permission denied, trying again")
continue
break
def stat(self):
while True:
for i in range(5):
stat = self.check_if_busy()
print(self.status)
if not self.status:
time.sleep(2)
stat = self.check_if_busy()
else:
time.sleep(10-2*i)
break
self.write_stat(stat)
print(stat)
if __name__ == '__main__':
Machine().stat()