-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutility.py
84 lines (71 loc) · 1.84 KB
/
utility.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
import os
import logging
import re
log = logging.getLogger(__name__)
def export_config(config):
file=os.path.join(os.getcwd(),'monitor_tool_config')
log.info("Export configuration into file : %s" % file)
try:
fo = open(file,"w")
fo.truncate()
for i in config:
fo.write(i)
fo.write("\n")
fo.close
log.info("Export configuration successfully")
return True
except Exception, e:
log.error ("%s" % str(e))
def load_config():
file=os.path.join(os.getcwd(),'monitor_tool_config')
log.info("Load configuration from file %s" % file)
try:
fo = open(file,"r")
config = fo.readlines()
fo.close
log.info("Load configuration successfully")
return config
except Exception, e:
log.error ("%s" % str(e))
def time2sec(sTime):
if len(sTime.split(':')) == 2:
sTime = '00:' + sTime
p = "^(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$"
cp = re.compile(p)
try:
mTime = cp.match(sTime)
except TypeError:
return "[InModuleError]:time2itv(sTime) invalid argument type"
if mTime:
t = map(int,mTime.group(1,2,3))
return 3600*t[0]+60*t[1]+t[2]
else:
return "[InModuleError]:time2itv(sTime) invalid argument value"
def parseTime(stdout):
if len(stdout.rsplit()) == 2:
x = stdout.rsplit()
pid_start_time = x[0]
y = x[1]
if len(y.split('-')) == 2:
z = y.split('-')
pid_run_time_str = "%s days %s " % (z[0], z[1])
sec = time2sec(z[1])
pid_run_time_sec = 3600 * 24 * int(z[0]) + int(sec)
elif len(y.split('-')) == 1:
z = y.split('-')
pid_run_time_str = "%s" % (z[0])
pid_run_time_sec = time2sec(z[0])
else:
return None
return (pid_start_time, pid_run_time_str, pid_run_time_sec)
else:
return None
flag = 1
def getmovie(string):
global flag
if flag:
string = string + '...'
flag = 0
else:
flag = 1
return string