Skip to content

Commit

Permalink
--file option
Browse files Browse the repository at this point in the history
  • Loading branch information
zendorx committed Feb 9, 2017
1 parent fe4ee9b commit 03bf49d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
12 changes: 9 additions & 3 deletions smartlog.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import argparse
from gui import *

# INFO-------------------------
version = "0.4"
version = "0.5"
app_name = "SmartLog"
source_info = "https://github.com/zendorx/smart-logcat"
contacts_info = "[email protected]"
Expand Down Expand Up @@ -41,6 +41,7 @@ parser.add_argument("--command_clean", default="adb logcat -c", help="specifies
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")
#
Expand Down Expand Up @@ -114,13 +115,18 @@ if _args.pid_lookup:
gui.set_pid_lookup(_args.pid_lookup)

app.set_command_exec(_args.command_execute)
app.start_reading()

if _args.file:
app.read_from_file(_args.file)
else:
app.start_reading()

while not gui.is_finished():
app.update()
gui.update()

app.stop_reading()
if not _args.file:
app.stop_reading()

if _args.exit_clean:
app.clear(_args.command_clean)
Expand Down
15 changes: 15 additions & 0 deletions smcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ def can_show(self, filter_words, pid):

return True

class FileReader():
def __init__(self, fname):
self.fname = fname
self.lines = []
with open(fname.decode("utf8"), "r") as f:
for l in f.readlines():
self.lines.append(l.strip())

def update(self):
lines = list(self.lines)
self.lines[:] = []
return lines

class Reader():
def __init__(self, command):
Expand Down Expand Up @@ -251,6 +263,9 @@ def clear(self, command):
def stop_reading(self):
self.reader.stop()

def read_from_file(self, fname):
self.reader = FileReader(fname)

def start_reading(self):
self.reader = Reader(self.command)

Expand Down

0 comments on commit 03bf49d

Please sign in to comment.