text
stringlengths
0
828
'extension, but it seems that this is because you have left the '
'extension in the location name. Please remove the file extension '
'from the location name and try again')
else:
return ObjectNotFoundOnFileSystemError('Mandatory object : ' + location + ' could not be found on the file'
' system, either as a multifile or as a singlefile with any '
'extension.')"
1340,"def get_unique_object_contents(self, location: str) -> Tuple[bool, str, Union[str, Dict[str, str]]]:
""""""
Utility method to find a unique singlefile or multifile object.
This method throws
* ObjectNotFoundOnFileSystemError if no file is found
* ObjectPresentMultipleTimesOnFileSystemError if the object is found multiple times (for example with
several file extensions, or as a file AND a folder)
* IllegalContentNameError if a multifile child name is None or empty string.
It relies on the abstract methods of this class (find_simpleobject_file_occurrences and
find_multifile_object_children) to find the various files present.
:param location: a location identifier compliant with the provided file mapping configuration
:return: [True, singlefile_ext, singlefile_path] if a unique singlefile object is present ;
False, MULTIFILE_EXT, complexobject_attributes_found] if a unique multifile object is present, with
complexobject_attributes_found being a dictionary {name: location}
""""""
# First check what is present on the filesystem according to the filemapping
simpleobjects_found = self.find_simpleobject_file_occurrences(location)
complexobject_attributes_found = self.find_multifile_object_children(location, no_errors=True)
# Then handle the various cases
if len(simpleobjects_found) > 1 \
or (len(simpleobjects_found) == 1 and len(complexobject_attributes_found) > 0):
# the object is present several times > error
u = simpleobjects_found
u.update(complexobject_attributes_found)
raise ObjectPresentMultipleTimesOnFileSystemError.create(location, list(u.keys()))
elif len(simpleobjects_found) == 1:
# a singlefile object > create the output
is_single_file = True
ext = list(simpleobjects_found.keys())[0]
singlefile_object_file_path = simpleobjects_found[ext]
return is_single_file, ext, singlefile_object_file_path
elif len(complexobject_attributes_found) > 0:
# a multifile object > create the output
is_single_file = False
ext = MULTIFILE_EXT
if '' in complexobject_attributes_found.keys() or None in complexobject_attributes_found.keys():
raise IllegalContentNameError.create(location, complexobject_attributes_found[MULTIFILE_EXT])
return is_single_file, ext, complexobject_attributes_found
else:
# handle special case of multifile object with no children (if applicable)
if self.is_multifile_object_without_children(location):
is_single_file = False
ext = MULTIFILE_EXT
return is_single_file, ext, dict()
else:
# try if by any chance the issue is that location has an extension
loc_without_ext = splitext(location)[0]
simpleobjects_found = self.find_simpleobject_file_occurrences(loc_without_ext)
complexobject_attributes_found = self.find_multifile_object_children(loc_without_ext, no_errors=True)
# the object was not found in a form that can be parsed
raise ObjectNotFoundOnFileSystemError.create(location, simpleobjects_found,
complexobject_attributes_found)"
1341,"def find_multifile_object_children(self, parent_location: str, no_errors: bool = False) -> Dict[str, str]:
""""""
Implementing classes should return a dictionary of <item_name>, <item_location> containing the named elements
in this multifile object.
:param parent_location: the absolute file prefix of the parent item.
:return: a dictionary of {item_name : item_prefix}
""""""
pass"
1342,"def get_pretty_location(self, blank_parent_part: bool = False, append_file_ext: bool = True,
compact_file_ext: bool = False):
""""""
Utility method to return a string representing the location, mode and extension of this file.
:return:
""""""
if append_file_ext:
if compact_file_ext:
suffix = self.ext if self.is_singlefile else ''
else:
suffix = ' (' + self.get_pretty_file_ext() + ')'
else:
suffix = ''
if blank_parent_part:
# TODO sep should be replaced with the appropriate separator in flat mode
idx = self.location.rfind(sep)
return (' ' * (idx-1-len(sep))) + '|--' + self.location[(idx+1):] + suffix
else:
return self.location + suffix"
1343,"def get_pretty_child_location(self, child_name, blank_parent_part: bool = False):
""""""
Utility method to return a string representation of the location of a child
:param child_name:
:param blank_parent_part: