-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatusList.py
55 lines (50 loc) · 2.07 KB
/
statusList.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
__author__ = 'Dan'
import time
import datetime
class StatusList:
def __init__(self, log_folder_path):
self.__log_folder_path = log_folder_path
# Status_Log.txt writing function
def write_status_log(self, new_process_list, stopped_process_list):
filename = self.__log_folder_path + '\\Status_Log.txt'
separator = "-" * 80
format = "%16s (%s) %30s, %10d %30s"
format2 = "(%s) %30s, %10d %30s"
with open(filename, "a") as f:
f.write(separator + "\n")
f.write(time.ctime() + "\n")
print(separator)
print(time.ctime() + "\n")
if new_process_list:
f.write("New processes:\n")
print "New Processes:\n"
for p in new_process_list:
start_time = datetime.datetime.fromtimestamp(p.create_time()).strftime("%Y-%m-%d %H:%M:%S")
with p.oneshot():
try:
exe = p.exe()
uname = p.username()
except:
exe = ""
uname = "-"
pass
print(format % (start_time, uname, p.name(), p.pid, exe))
f.write(format % (start_time, uname, p.name(), p.pid, exe))
f.write("\n")
print "\n"
if stopped_process_list:
f.write("Stopped processes:\n")
print "Stopped processes:\n"
for p in stopped_process_list:
with p.oneshot():
try:
exe = p.exe()
uname = p.username()
except:
exe = ""
uname = "-"
pass
print(format2 % (uname, p.name(), p.pid, exe))
f.write(format2 % (uname, p.name(), p.pid, exe))
f.write("\n")
print(separator)