From 159bc9cee2191f4d64a41c4414fbb655c64158a6 Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Thu, 20 Jul 2017 17:47:23 -0400 Subject: [PATCH] Add __repr__s to File and KittenGroomerFileCheck --- bin/filecheck.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/bin/filecheck.py b/bin/filecheck.py index 4a8e545..c33339b 100644 --- a/bin/filecheck.py +++ b/bin/filecheck.py @@ -124,7 +124,7 @@ class File(FileBase): filetype-specific processing methods. """ - def __init__(self, src_path, dst_path, logger): + def __init__(self, src_path, dst_path, logger=None): super(File, self).__init__(src_path, dst_path) self.is_archive = False self.logger = logger @@ -162,6 +162,9 @@ class File(FileBase): 'inode': self.inode, } + def __repr__(self): + return "".format(self.filename) + def _check_dangerous(self): if not self.has_mimetype: self.make_dangerous('File has no mimetype') @@ -248,13 +251,16 @@ class File(FileBase): def write_log(self): """Pass information about the file to self.logger""" - props = self.get_all_props() - if not self.is_archive: - if os.path.exists(self.tempdir_path): - # FIXME: in_tempdir is a hack to make images appear at the correct tree depth in log - self.logger.add_file(self.src_path, props, in_tempdir=True) - return - self.logger.add_file(self.src_path, props) + if self.logger: + props = self.get_all_props() + if not self.is_archive: + if os.path.exists(self.tempdir_path): + # FIXME: in_tempdir is a hack to make images appear at the correct tree depth in log + self.logger.add_file(self.src_path, props, in_tempdir=True) + return + self.logger.add_file(self.src_path, props) + else: + raise Warning("No logger associated with this File") # ##### Helper functions ##### def _make_method_dict(self, list_of_tuples): @@ -676,6 +682,11 @@ class KittenGroomerFileCheck(KittenGroomerBase): self.max_recursive_depth = max_recursive_depth self.logger = GroomerLogger(root_src, root_dst, debug) + def __repr__(self): + return "filecheck.KittenGroomerFileCheck object: {{{}}}".format( + os.path.basename(self.src_root_path) + ) + def process_dir(self, src_dir, dst_dir): """Process a directory on the source key.""" for srcpath in self.list_files_dirs(src_dir):