mirror of https://github.com/CIRCL/PyCIRCLean
Move safe_copy to FileBase
parent
e73721e95f
commit
59cde8cfd5
|
@ -499,7 +499,7 @@ class KittenGroomerFileCheck(KittenGroomerBase):
|
||||||
if file.is_recursive:
|
if file.is_recursive:
|
||||||
self.process_archive(file)
|
self.process_archive(file)
|
||||||
elif file.should_copy:
|
elif file.should_copy:
|
||||||
self.safe_copy(file.src_path, file.dst_path)
|
file.safe_copy()
|
||||||
file.set_property('copied', True)
|
file.set_property('copied', True)
|
||||||
file.write_log()
|
file.write_log()
|
||||||
if hasattr(file, 'tempdir_path'):
|
if hasattr(file, 'tempdir_path'):
|
||||||
|
|
|
@ -201,6 +201,20 @@ class FileBase(object):
|
||||||
path, filename = os.path.split(self.dst_path)
|
path, filename = os.path.split(self.dst_path)
|
||||||
self.dst_path = os.path.join(path, '{}.bin'.format(filename))
|
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):
|
def force_ext(self, ext):
|
||||||
"""If dst_path does not end in ext, changes it and edits _file_props."""
|
"""If dst_path does not end in ext, changes it and edits _file_props."""
|
||||||
if not self.dst_path.endswith(ext):
|
if not self.dst_path.endswith(ext):
|
||||||
|
@ -281,9 +295,6 @@ class GroomerLogger(object):
|
||||||
# return a sublog for the file
|
# return a sublog for the file
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def add_event(self, event, log_level):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class KittenGroomerBase(object):
|
class KittenGroomerBase(object):
|
||||||
"""Base object responsible for copy/sanitization process."""
|
"""Base object responsible for copy/sanitization process."""
|
||||||
|
@ -311,19 +322,6 @@ class KittenGroomerBase(object):
|
||||||
if not os.path.exists(directory):
|
if not os.path.exists(directory):
|
||||||
os.makedirs(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):
|
def list_all_files(self, directory):
|
||||||
"""Generator yielding path to all of the files in a directory tree."""
|
"""Generator yielding path to all of the files in a directory tree."""
|
||||||
for root, dirs, files in os.walk(directory):
|
for root, dirs, files in os.walk(directory):
|
||||||
|
|
Loading…
Reference in New Issue