Change the way description strings are handled

pull/14/head
Dan Puttick 2017-03-22 10:28:00 -04:00
parent 3e7b38c5d4
commit 265f32ad6b
1 changed files with 14 additions and 7 deletions

View File

@ -56,7 +56,7 @@ class FileBase(object):
'safety_category': None, 'safety_category': None,
'symlink': False, 'symlink': False,
'copied': False, 'copied': False,
'file_string_set': set(), 'description_string': [], # array of descriptions to be joined
'errors': {}, 'errors': {},
'user_defined': {} 'user_defined': {}
} }
@ -164,7 +164,10 @@ class FileBase(object):
If `prop_string` is part of the file property API, set it to `value`. If `prop_string` is part of the file property API, set it to `value`.
Otherwise, add `prop_string`: `value` to `user_defined` properties. Otherwise, add `prop_string`: `value` to `user_defined` properties.
""" """
if prop_string in self._file_props.keys(): if prop_string is 'description_string':
if prop_string not in self._file_props['description_string']:
self._file_props['description_string'].append(value)
elif prop_string in self._file_props.keys():
self._file_props[prop_string] = value self._file_props[prop_string] = value
else: else:
self._file_props['user_defined'][prop_string] = value self._file_props['user_defined'][prop_string] = value
@ -175,7 +178,6 @@ class FileBase(object):
Returns `None` if `prop_string` cannot be found on the file. Returns `None` if `prop_string` cannot be found on the file.
""" """
# TODO: could probably be refactored
if prop_string in self._file_props: if prop_string in self._file_props:
return self._file_props[prop_string] return self._file_props[prop_string]
elif prop_string in self._file_props['user_defined']: elif prop_string in self._file_props['user_defined']:
@ -191,9 +193,13 @@ class FileBase(object):
"""Add an `error`: `info_string` pair to the file.""" """Add an `error`: `info_string` pair to the file."""
self._file_props['errors'].update({error: info_string}) self._file_props['errors'].update({error: info_string})
def add_file_string(self, file_string): def add_description(self, description_string):
"""Add a file descriptor string to the file.""" """
self._file_props['file_string_set'].add(file_string) Add a description string to the file.
If `description_string` is already present, will prevent duplicates.
"""
self.set_property('description_string', description_string)
def make_dangerous(self, reason_string=None): def make_dangerous(self, reason_string=None):
""" """
@ -203,9 +209,10 @@ class FileBase(object):
to help prevent double-click of death. to help prevent double-click of death.
""" """
if self.is_dangerous: if self.is_dangerous:
self.set_property('description_string', reason_string)
return return
self.set_property('safety_category', 'dangerous') self.set_property('safety_category', 'dangerous')
# LOG: store reason string somewhere and do something with it self.set_property('description_string', reason_string)
path, filename = os.path.split(self.dst_path) path, filename = os.path.split(self.dst_path)
self.dst_path = os.path.join(path, 'DANGEROUS_{}_DANGEROUS'.format(filename)) self.dst_path = os.path.join(path, 'DANGEROUS_{}_DANGEROUS'.format(filename))