Move safe_copy to FileBase

pull/12/head
Dan Puttick 2017-03-09 13:48:07 -05:00
parent e73721e95f
commit 59cde8cfd5
2 changed files with 15 additions and 17 deletions

View File

@ -499,7 +499,7 @@ class KittenGroomerFileCheck(KittenGroomerBase):
if file.is_recursive:
self.process_archive(file)
elif file.should_copy:
self.safe_copy(file.src_path, file.dst_path)
file.safe_copy()
file.set_property('copied', True)
file.write_log()
if hasattr(file, 'tempdir_path'):

View File

@ -201,6 +201,20 @@ class FileBase(object):
path, filename = os.path.split(self.dst_path)
self.dst_path = os.path.join(path, '{}.bin'.format(filename))
def safe_copy(self, src=None, dst=None):
"""Copy a file and create directory if needed."""
if src is None:
src = self.src_path
if dst is None:
dst = self.dst_path
try:
dst_path, filename = os.path.split(dst)
if not os.path.exists(dst_path):
os.makedirs(dst_path)
shutil.copy(src, dst)
except Exception as e:
self.add_error(e, '')
def force_ext(self, ext):
"""If dst_path does not end in ext, changes it and edits _file_props."""
if not self.dst_path.endswith(ext):
@ -281,9 +295,6 @@ class GroomerLogger(object):
# return a sublog for the file
pass
def add_event(self, event, log_level):
pass
class KittenGroomerBase(object):
"""Base object responsible for copy/sanitization process."""
@ -311,19 +322,6 @@ class KittenGroomerBase(object):
if not os.path.exists(directory):
os.makedirs(directory)
def safe_copy(self, src=None, dst=None):
"""Copy a file and create directory if needed."""
if src is None:
src = self.cur_file.src_path
if dst is None:
dst = self.cur_file.dst_path
try:
dst_path, filename = os.path.split(dst)
self.safe_mkdir(dst_path)
shutil.copy(src, dst)
except Exception as e:
self.add_error(e, '')
def list_all_files(self, directory):
"""Generator yielding path to all of the files in a directory tree."""
for root, dirs, files in os.walk(directory):