Write basic log to log file

pull/14/head
Dan Puttick 2017-03-22 12:07:15 -04:00
parent 6f9e36a578
commit 52bb566cc3
1 changed files with 15 additions and 2 deletions

View File

@ -292,6 +292,7 @@ class GroomerLogger(object):
def __init__(self, root_dir_path, debug=False): def __init__(self, root_dir_path, debug=False):
self._root_dir_path = root_dir_path self._root_dir_path = root_dir_path
self._log_dir_path = self._make_log_dir(root_dir_path) self._log_dir_path = self._make_log_dir(root_dir_path)
# LOG: rename logfile to something more descriptive
self.log_path = os.path.join(self._log_dir_path, 'log.txt') self.log_path = os.path.join(self._log_dir_path, 'log.txt')
# twiggy.quick_setup(file=self.log_processing) # twiggy.quick_setup(file=self.log_processing)
# self.log = twiggy.log.name('files') # self.log = twiggy.log.name('files')
@ -311,7 +312,7 @@ class GroomerLogger(object):
def tree(self, base_dir, padding=' '): def tree(self, base_dir, padding=' '):
"""Write a graphical tree to the log for `base_dir`.""" """Write a graphical tree to the log for `base_dir`."""
with open(self.log_path, 'ab') as lf: with open(self.log_path, mode='ab') as lf:
lf.write(bytes('#' * 80 + '\n', 'UTF-8')) lf.write(bytes('#' * 80 + '\n', 'UTF-8'))
lf.write(bytes('{}+- {}/\n'.format(padding, os.path.basename(os.path.abspath(base_dir)).encode()), 'utf8')) lf.write(bytes('{}+- {}/\n'.format(padding, os.path.basename(os.path.abspath(base_dir)).encode()), 'utf8'))
padding += '| ' padding += '| '
@ -336,9 +337,21 @@ class GroomerLogger(object):
s.update(buf) s.update(buf)
return s.hexdigest() return s.hexdigest()
def _write_file_to_disk(self, file_string):
with open(self.log_path, mode='a', encoding='utf-8') as lf:
lf.write(file_string)
def add_file(self, file_props): def add_file(self, file_props):
"""Add a file to the log. Takes a dict of file properties.""" """Add a file to the log. Takes a dict of file properties."""
pass props = file_props
description_string = ', '.join(props['description_string'])
file_string = "{}: {}/{}, {}: {}\n".format(props['filename'],
props['maintype'],
props['subtype'],
props['safety_category'],
description_string
)
self._write_file_to_disk(file_string)
class KittenGroomerBase(object): class KittenGroomerBase(object):