From 03bf49d0c6e9e7a4f023db12820247b302eedd3d Mon Sep 17 00:00:00 2001 From: Denis Sachkov Date: Thu, 9 Feb 2017 13:18:08 +0300 Subject: [PATCH] --file option --- smartlog.pyw | 12 +++++++++--- smcore.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/smartlog.pyw b/smartlog.pyw index 0f3f035..b86d40f 100644 --- a/smartlog.pyw +++ b/smartlog.pyw @@ -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 = "zendorx@gmail.com" @@ -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") # @@ -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) diff --git a/smcore.py b/smcore.py index 5757df8..67f7d9d 100644 --- a/smcore.py +++ b/smcore.py @@ -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): @@ -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)