mirror of https://github.com/CIRCL/PyCIRCLean
Adjust order of property initialization
Tests were failing due to values being set before file_props dict was createdpull/12/head
parent
0038d3ef66
commit
3fe8c7c223
|
@ -180,12 +180,6 @@ class File(FileBase):
|
||||||
"""Print the logs related to the current file being processed."""
|
"""Print the logs related to the current file being processed."""
|
||||||
# LOG: move to helpers.py GroomerLogger and modify
|
# LOG: move to helpers.py GroomerLogger and modify
|
||||||
tmp_log = self.logger.log.fields(**self._file_props)
|
tmp_log = self.logger.log.fields(**self._file_props)
|
||||||
if self.is_dangerous():
|
|
||||||
tmp_log.warning(self.log_string)
|
|
||||||
elif self.is_unknown() or self.is_binary():
|
|
||||||
tmp_log.info(self.log_string)
|
|
||||||
else:
|
|
||||||
tmp_log.debug(self.log_string)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def has_metadata(self):
|
def has_metadata(self):
|
||||||
|
|
|
@ -42,28 +42,29 @@ class FileBase(object):
|
||||||
self.src_path = src_path
|
self.src_path = src_path
|
||||||
self.dst_path = dst_path
|
self.dst_path = dst_path
|
||||||
self.filename = os.path.basename(self.src_path)
|
self.filename = os.path.basename(self.src_path)
|
||||||
self.log_string = ''
|
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
self.symlink = None
|
|
||||||
self.extension = self._determine_extension()
|
|
||||||
self.mimetype = self._determine_mimetype()
|
|
||||||
self.should_copy = True
|
|
||||||
if self.mimetype:
|
|
||||||
self.main_type, self.sub_type = self._split_subtypes(self.mimetype)
|
|
||||||
self._file_props = {
|
self._file_props = {
|
||||||
'filepath': self.src_path,
|
'filepath': self.src_path,
|
||||||
'filename': self.filename,
|
'filename': self.filename,
|
||||||
'maintype': self.main_type,
|
|
||||||
'subtype': self.sub_type,
|
|
||||||
'extension': self.extension,
|
|
||||||
'file_size': self.size,
|
'file_size': self.size,
|
||||||
|
'maintype': None,
|
||||||
|
'subtype': None,
|
||||||
|
'extension': None,
|
||||||
'safety_category': None,
|
'safety_category': None,
|
||||||
'symlink': self.symlink,
|
'symlink': False,
|
||||||
'copied': False,
|
'copied': False,
|
||||||
'file_string_set': set(),
|
'file_string_set': set(),
|
||||||
'errors': {},
|
'errors': {},
|
||||||
'user_defined': {}
|
'user_defined': {}
|
||||||
}
|
}
|
||||||
|
self.extension = self._determine_extension()
|
||||||
|
self.set_property('extension', self.extension)
|
||||||
|
self.mimetype = self._determine_mimetype()
|
||||||
|
self.should_copy = True
|
||||||
|
if self.mimetype:
|
||||||
|
self.main_type, self.sub_type = self._split_subtypes(self.mimetype)
|
||||||
|
self.set_property('maintype', self.main_type)
|
||||||
|
self.set_property('subtype', self.sub_type)
|
||||||
|
|
||||||
def _determine_extension(self):
|
def _determine_extension(self):
|
||||||
_, ext = os.path.splitext(self.src_path)
|
_, ext = os.path.splitext(self.src_path)
|
||||||
|
@ -76,13 +77,14 @@ class FileBase(object):
|
||||||
if os.path.islink(self.src_path):
|
if os.path.islink(self.src_path):
|
||||||
# magic will throw an IOError on a broken symlink
|
# magic will throw an IOError on a broken symlink
|
||||||
mimetype = 'inode/symlink'
|
mimetype = 'inode/symlink'
|
||||||
self.symlink = os.readlink(self.src_path)
|
self.set_property('symlink', os.readlink(self.src_path))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
mt = magic.from_file(self.src_path, mime=True)
|
mt = magic.from_file(self.src_path, mime=True)
|
||||||
# Note: magic will always return something, even if it's just 'data'
|
# Note: magic will always return something, even if it's just 'data'
|
||||||
except UnicodeEncodeError as e:
|
except UnicodeEncodeError as e:
|
||||||
# FIXME: The encoding of the file is broken (possibly UTF-16)
|
# FIXME: The encoding of the file is broken (possibly UTF-16)
|
||||||
|
# One of the Travis files will trigger this.
|
||||||
self.add_error(e, '')
|
self.add_error(e, '')
|
||||||
mt = None
|
mt = None
|
||||||
try:
|
try:
|
||||||
|
@ -134,7 +136,7 @@ class FileBase(object):
|
||||||
|
|
||||||
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."""
|
||||||
if self._file_props['symlink'] is None:
|
if self._file_props['symlink'] is False:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue