-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmartlog.py
145 lines (109 loc) · 4.8 KB
/
smartlog.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
from gui import *
# INFO-------------------------
version = "0.5"
app_name = "SmartLog"
source_info = "https://github.com/zendorx/smart-logcat"
contacts_info = "[email protected]"
# CONSTS-----------------------
# const_wait = "- waiting for device -"
# const_ignore = "ignore:"
# VARIABLES--------------------
default_file_name = "{t} {uid}.log"
conf_file = "default.cfg"
interrupt_command = "__interrupt_command__"
parser = argparse.ArgumentParser(prog=app_name, # todo: move to description
usage="""1)Install android SDK"
2)Add '{$SDK}\platform-tools\\adb.exe' to the PATH or setup -adb <path>
3)Run program
""",
description="Program prints stream output and provides bunch of useful features like filter, highlight.")
parser.add_argument("-cd", default="",
help="specifies directory where log files will be saved")
parser.add_argument("--command_execute", default="adb logcat", action='store_const', const=True,
help="executes clean command on app close.")
parser.add_argument("--exit_clean", default=False, action='store_const', const=True,
help="executes clean command on app close.")
parser.add_argument("--start_clean", default=False, action='store_const', const=True,
help="executes clean command on startup.")
parser.add_argument("--command_clean", default="adb logcat -c", help="specifies clean command.")
parser.add_argument("--pid_lookup", default="", help="specifies string for looking process id.")
parser.add_argument("--pid_mask", default="\((.*?)\)", help="specifies regex to searching pid in a text line.")
parser.add_argument("--file", default="", help="specifies log file to read.")
# parser.add_argument("-ec", default=exit_commands,
# help="commands that will executed on exit splited by ';' e.g: 'w;q' will write file and open explorer. To see more commands type :h")
#
# parser.add_argument("-cf", default=conf_file,
# help="specifies config file name. By default is '%s'" % (conf_file,))
#
# parser.add_argument("-cd", default=current_dir,
# help="specifies directory where log files will be saved")
#
# parser.add_argument("-cs", default=False,
# action='store_const',
# const=True,
# help="execute clean command on startup. By default %s" % clean_cmd)
#
# parser.add_argument("-pc", default=process_lookup,
# help="specifies process lookup string")
#
# parser.add_argument("--init", default=False,
# action='store_const',
# const=True,
# help="creates default config file in app folder")
#
# parser.add_argument('--version', "-v",
# action='version',
# version="%s %s" % (app_name, version))
#
# parser.add_argument('-execute', default=exec_cmd,
# help="specifies execute command that will output log stream. By default is %s" % exec_cmd)
#
# parser.add_argument('-clean', default=clean_cmd,
# help="specifies clean command e.g. 'adb logcat -c'.")
_args = parser.parse_args()
# IF DEBUG
# _args.command_execute = "netstat -a"
# _args.command_clean = None
file_name = default_file_name
def fix_current_dir(value):
cd = value
if cd == ".":
cd = ""
if cd != "" and not (cd.endswith("\\") or cd.endswith("/")):
cd += "/"
return cd
current_dir = fix_current_dir(_args.cd)
# ---------------------------------------------------------------------------------------------------------------------------------------------
#PID MASKS EXAMPLE:
## LINE: 10-10 15:15:22.500 3002 5003 D WindowManager: Some shit happed there
## MASK: "^(?:\S+\s){3}(\S+)"
## LINE: i/kernel (1234): Some shit happed there
## MASK: "\((.*?)\)"
# ---------------------------------------------------------------------------------------------------------------------------------------------
app = SmartlogApp()
gui = AppGui(app)
gui.set_clean_command(_args.command_clean)
if _args.start_clean:
app.clear()
gui.set_current_file_name(file_name)
gui.set_current_folder(current_dir)
gui.update_title("Smartlog - '" + _args.command_execute + "'")
if _args.pid_lookup:
gui.set_pid_mask(_args.pid_mask)
gui.set_pid_lookup(_args.pid_lookup)
app.set_command_exec(_args.command_execute)
if _args.file:
app.read_from_file(_args.file)
else:
app.start_reading()
while not gui.is_finished():
app.update()
gui.update()
if not _args.file:
app.stop_reading()
if _args.exit_clean:
app.clear(_args.command_clean)
print "Done!"