|
@ -7,15 +7,13 @@ from time import strftime |
|
|
|
|
|
|
|
|
import wx |
|
|
import wx |
|
|
|
|
|
|
|
|
from .utils import ( |
|
|
|
|
|
check_path, |
|
|
|
|
|
fix_path |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
from .utils import check_path |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LogManager(object): |
|
|
class LogManager(object): |
|
|
|
|
|
|
|
|
''' |
|
|
''' |
|
|
|
|
|
OUT_OF_DATE |
|
|
Simple log manager for youtube-dlG. |
|
|
Simple log manager for youtube-dlG. |
|
|
|
|
|
|
|
|
Params |
|
|
Params |
|
@ -23,7 +21,7 @@ class LogManager(object): |
|
|
add_time: If True LogManager will also log the time. |
|
|
add_time: If True LogManager will also log the time. |
|
|
|
|
|
|
|
|
Accessible Methods |
|
|
Accessible Methods |
|
|
size() |
|
|
|
|
|
|
|
|
log_size() |
|
|
Params: None |
|
|
Params: None |
|
|
|
|
|
|
|
|
Return: Log file size in Bytes |
|
|
Return: Log file size in Bytes |
|
@ -42,17 +40,18 @@ class LogManager(object): |
|
|
log_file: Absolute path to log file. |
|
|
log_file: Absolute path to log file. |
|
|
''' |
|
|
''' |
|
|
|
|
|
|
|
|
LOG_FILENAME = 'log' |
|
|
|
|
|
MAX_FILESIZE = 524288 # 524288B = 512kB |
|
|
|
|
|
|
|
|
LOG_FILENAME = "log" |
|
|
|
|
|
TIME_TEMPLATE = "[{time}] {error_msg}" |
|
|
|
|
|
MAX_LOGSIZE = 524288 # 524288B = 512kB |
|
|
|
|
|
|
|
|
def __init__(self, config_path, add_time=False): |
|
|
def __init__(self, config_path, add_time=False): |
|
|
self.config_path = config_path |
|
|
self.config_path = config_path |
|
|
self.add_time = add_time |
|
|
self.add_time = add_time |
|
|
self.log_file = fix_path(config_path) + self.LOG_FILENAME |
|
|
|
|
|
|
|
|
self.log_file = os.path.join(config_path, self.LOG_FILENAME) |
|
|
self._init_log() |
|
|
self._init_log() |
|
|
self._auto_clear_log() |
|
|
self._auto_clear_log() |
|
|
|
|
|
|
|
|
def size(self): |
|
|
|
|
|
|
|
|
def log_size(self): |
|
|
''' Return log file size in Bytes. ''' |
|
|
''' Return log file size in Bytes. ''' |
|
|
if not os.path.exists(self.log_file): |
|
|
if not os.path.exists(self.log_file): |
|
|
return 0 |
|
|
return 0 |
|
@ -71,12 +70,13 @@ class LogManager(object): |
|
|
''' Write data to log file using mode. ''' |
|
|
''' Write data to log file using mode. ''' |
|
|
check_path(self.config_path) |
|
|
check_path(self.config_path) |
|
|
|
|
|
|
|
|
with open(self.log_file, mode) as log_file: |
|
|
|
|
|
if self.add_time: |
|
|
|
|
|
time = '[%s] ' % strftime('%c') |
|
|
|
|
|
log_file.write(time) |
|
|
|
|
|
|
|
|
with open(self.log_file, mode) as log: |
|
|
|
|
|
if mode == 'a' and self.add_time: |
|
|
|
|
|
msg = self.TIME_TEMPLATE.format(time=strftime('%c'), error_msg=data) |
|
|
|
|
|
else: |
|
|
|
|
|
msg = data |
|
|
|
|
|
|
|
|
log_file.write(data) |
|
|
|
|
|
|
|
|
log.write(msg) |
|
|
|
|
|
|
|
|
def _init_log(self): |
|
|
def _init_log(self): |
|
|
''' Init log file if not exist. ''' |
|
|
''' Init log file if not exist. ''' |
|
@ -85,7 +85,7 @@ class LogManager(object): |
|
|
|
|
|
|
|
|
def _auto_clear_log(self): |
|
|
def _auto_clear_log(self): |
|
|
''' Auto clear log file. ''' |
|
|
''' Auto clear log file. ''' |
|
|
if self.size() > self.MAX_FILESIZE: |
|
|
|
|
|
|
|
|
if self.log_size() > self.MAX_LOGSIZE: |
|
|
self.clear() |
|
|
self.clear() |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -101,16 +101,16 @@ class LogGUI(wx.Frame): |
|
|
Return: None |
|
|
Return: None |
|
|
''' |
|
|
''' |
|
|
|
|
|
|
|
|
TITLE = 'Log Viewer' |
|
|
|
|
|
|
|
|
TITLE = "Log Viewer" |
|
|
|
|
|
FRAME_SIZE = (650, 200) |
|
|
|
|
|
|
|
|
def __init__(self, parent=None): |
|
|
def __init__(self, parent=None): |
|
|
wx.Frame.__init__(self, parent, -1, self.TITLE, size=(650, 200)) |
|
|
|
|
|
|
|
|
wx.Frame.__init__(self, parent, title=self.TITLE, size=self.FRAME_SIZE) |
|
|
|
|
|
|
|
|
panel = wx.Panel(self) |
|
|
panel = wx.Panel(self) |
|
|
|
|
|
|
|
|
self._text_area = wx.TextCtrl( |
|
|
self._text_area = wx.TextCtrl( |
|
|
panel, |
|
|
panel, |
|
|
-1, |
|
|
|
|
|
style=wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL |
|
|
style=wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|