-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
82 lines (72 loc) · 2.55 KB
/
run.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
#!/usr/bin/python2
import collections
import argparse
from softwatch import timelog
from softwatch import timenode
import sys
import time
import os
import glob
import traceback
import codecs
import locale
def run1(args):
run(args[0])
def run(args):
try:
#sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout);
if sys.platform == "win32":
class UniStream(object):
__slots__= ("fobj", "softspace",)
def __init__(self, fileobject):
self.fobj = fileobject
#self.fileno = fileobject.fileno()
self.softspace = False
def write(self, text):
try:
fno = self.fobj.fileno()
os.write(fno, text.encode("cp866") if isinstance(text, unicode) else text)
except BaseException as e:
traceback.print_exc()
#self.fobj.write(text)
sys.stdout = UniStream(sys.stdout)
sys.stderr = UniStream(sys.stderr)
print "run "+str(args)
if args.action=='log':
aw = timelog.TimeLog(args)
aw.monitor_active_window()
return 0
if args.action=='report':
args.file = args.file or "*.log"
opts = timenode.TimeQuery(samples=args.samples, tree=args.tree)
opts.tasks = timenode.loadTasks(os.path.join(args.dir, "tasks.cat"))
opts.total = timenode.loadTasks(os.path.join(args.dir, "tasks.cat"))
opts.total.tag = "**ONLINE**"
opts.min_time = int(args.duration*60000)
opts.min_percent = float(args.percent)
opts.relative = args.relative
if args.begin:
opts.min_start = int((time.time()-3600*24*float(args.begin))*1000)
if args.end:
opts.max_start = int((time.time()-3600*24*float(args.end))*1000)
print "directory:"+str(args.dir)+", file:"+args.file
logfiles = [ f for f in glob.glob(os.path.join(args.dir,args.file)) if os.path.isfile(os.path.join(args.file,f)) ]
logfiles = sorted(logfiles)
for f in logfiles:
if (os.path.getmtime(f)*1000-opts.min_start>=0):
print "processing "+f
opts.process_file(f)
# else:
# print "skipped "+f
taglist = args.pattern #[0].split(' ')
print taglist
opts.total.query(set(taglist),opts)
return 0
except BaseException as e:
traceback.print_exc()
var = traceback.format_exc()
f=open("err","w")
f.write(str(e)+"\n"+var)
f.close()
print var
return 1