Refactor FileBase helper methods

pull/8/head
Dan Puttick 2016-12-21 18:04:59 -05:00
parent d4bfe794be
commit f7ab393eb6
1 changed files with 14 additions and 11 deletions

View File

@ -81,7 +81,6 @@ class FileBase(object):
Returns False + updates log if self.main_type or self.sub_type Returns False + updates log if self.main_type or self.sub_type
are not set. are not set.
""" """
if not self.main_type or not self.sub_type: if not self.main_type or not self.sub_type:
self.log_details.update({'broken_mime': True}) self.log_details.update({'broken_mime': True})
return False return False
@ -93,16 +92,22 @@ class FileBase(object):
Returns False + updates self.log_details if self.extension is not set. Returns False + updates self.log_details if self.extension is not set.
""" """
if not self.extension: if self.extension == '':
self.log_details.update({'no_extension': True}) self.log_details.update({'no_extension': True})
return False return False
return True return True
def is_dangerous(self): def is_dangerous(self):
"""Returns True if self.log_details contains 'dangerous'.""" """Returns True if self.log_details contains 'dangerous'."""
if self.log_details.get('dangerous'): return ('dangerous' in self.log_details)
return True
return False def is_unknown(self):
"""Returns True if self.log_details contains 'unknown'."""
return ('unknown' in self.log_details)
def is_binary(self):
"""returns True if self.log_details contains 'binary'."""
return ('binary' in self.log_details)
def is_symlink(self): def is_symlink(self):
"""Returns True and updates log if file is a symlink.""" """Returns True and updates log if file is a symlink."""
@ -120,10 +125,9 @@ class FileBase(object):
Marks a file as dangerous. Marks a file as dangerous.
Prepends and appends DANGEROUS to the destination file name Prepends and appends DANGEROUS to the destination file name
to avoid double-click of death. to help prevent double-click of death.
""" """
if self.is_dangerous(): if self.is_dangerous():
# Already marked as dangerous, do nothing
return return
self.log_details['dangerous'] = True self.log_details['dangerous'] = True
path, filename = os.path.split(self.dst_path) path, filename = os.path.split(self.dst_path)
@ -131,8 +135,7 @@ class FileBase(object):
def make_unknown(self): def make_unknown(self):
"""Marks a file as an unknown type and prepends UNKNOWN to filename.""" """Marks a file as an unknown type and prepends UNKNOWN to filename."""
if self.is_dangerous() or self.log_details.get('binary'): if self.is_dangerous() or self.is_binary():
# Already marked as dangerous or binary, do nothing
return return
self.log_details['unknown'] = True self.log_details['unknown'] = True
path, filename = os.path.split(self.dst_path) path, filename = os.path.split(self.dst_path)
@ -141,7 +144,6 @@ class FileBase(object):
def make_binary(self): def make_binary(self):
"""Marks a file as a binary and appends .bin to filename.""" """Marks a file as a binary and appends .bin to filename."""
if self.is_dangerous(): if self.is_dangerous():
# Already marked as dangerous, do nothing
return return
self.log_details['binary'] = True self.log_details['binary'] = True
path, filename = os.path.split(self.dst_path) path, filename = os.path.split(self.dst_path)
@ -265,6 +267,7 @@ class KittenGroomerBase(object):
def _safe_metadata_split(self, ext): def _safe_metadata_split(self, ext):
"""Create a separate file to hold this file's metadata.""" """Create a separate file to hold this file's metadata."""
# TODO: fix logic in this method
dst = self.cur_file.dst_path dst = self.cur_file.dst_path
try: try:
if os.path.exists(self.cur_file.src_path + ext): # should we check dst_path as well? if os.path.exists(self.cur_file.src_path + ext): # should we check dst_path as well?