From 70a73dc29203481e44741e6ebd3b2e6c8d0ccf86 Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Wed, 21 Dec 2016 21:24:29 -0500 Subject: [PATCH] Move process_file code into its own method --- bin/filecheck.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/bin/filecheck.py b/bin/filecheck.py index e9798b3..610de21 100644 --- a/bin/filecheck.py +++ b/bin/filecheck.py @@ -560,6 +560,19 @@ class KittenGroomerFileCheck(KittenGroomerBase): ####################### + def process_file(self, srcpath, dstpath, relative_path): + self.cur_file = File(srcpath, dstpath) + self.log_name.info('Processing {} ({}/{})', + relative_path, + self.cur_file.main_type, + self.cur_file.sub_type) + if not self.cur_file.is_dangerous(): + self.mime_processing_options.get(self.cur_file.main_type, self.unknown)() + else: + self._safe_copy() + if not self.cur_file.is_recursive: + self._print_log() + def processdir(self, src_dir=None, dst_dir=None): """Main function coordinating file processing.""" if src_dir is None: @@ -574,16 +587,10 @@ class KittenGroomerFileCheck(KittenGroomerBase): self._handle_archivebomb(src_dir) for srcpath in self._list_all_files(src_dir): - self.cur_file = File(srcpath, srcpath.replace(src_dir, dst_dir)) - - self.log_name.info('Processing {} ({}/{})', srcpath.replace(src_dir + '/', ''), - self.cur_file.main_type, self.cur_file.sub_type) - if not self.cur_file.is_dangerous(): - self.mime_processing_options.get(self.cur_file.main_type, self.unknown)() - else: - self._safe_copy() - if not self.cur_file.is_recursive: - self._print_log() + dstpath = srcpath.replace(src_dir, dst_dir) + relative_path = srcpath.replace(src_dir + '/', '') + # which path do we want in the log? + self.process_file(srcpath, dstpath, relative_path) if __name__ == '__main__':