text stringlengths 0 828 |
|---|
example if location = '<parent_folder>/<file_prefix>' |
parent_folder/ |
|-file_prefix<sep>singlefile_sub_item1.<ext> |
|-file_prefix<sep>singlefile_sub_item2.<ext> |
|-file_prefix<sep>multifile_sub_item3<sep>singlesub1.<ext> |
|-file_prefix<sep>multifile_sub_item3<sep>singlesub2.<ext> |
example if location = '<parent_folder>/ |
parent_folder/ |
|-singlefile_sub_item1.<ext> |
|-singlefile_sub_item2.<ext> |
|-multifile_sub_item3<sep>singlesub1.<ext> |
|-multifile_sub_item3<sep>singlesub2.<ext> |
:param parent_location: the absolute file prefix of the parent item. It may be a folder (special case of the |
root folder) but typically is just a file prefix |
:param no_errors: |
:return: a dictionary of <item_name>, <item_path> |
"""""" |
if parent_location == '': |
parent_location = '.' |
# (1) Find the base directory and base name |
if isdir(parent_location): # special case: parent location is the root folder where all the files are. |
parent_dir = parent_location |
base_prefix = '' |
start_with = '' |
else: |
parent_dir = dirname(parent_location) |
if parent_dir is '': |
parent_dir = '.' |
# TODO one day we'll rather want to have a uniform definition of 'location' across filemappings |
# Indeed as of today, location is not abstract from the file mapping implementation, since we |
# ""just"" use basename() rather than replacing os separators with our separator: |
base_prefix = basename(parent_location) # --> so it should already include self.separator to be valid |
start_with = self.separator |
# (2) list children files that are singlefiles |
content_files = [content_file for content_file in listdir(parent_dir) |
# -> we are in flat mode : should be a file not a folder : |
if isfile(join(parent_dir,content_file)) |
# -> we are looking for children of a specific item : |
and content_file.startswith(base_prefix) |
# -> we are looking for multifile child items only : |
and content_file != base_prefix |
# -> they should start with the separator (or with nothing in case of the root folder) : |
and (content_file[len(base_prefix):]).startswith(start_with) |
# -> they should have a valid extension : |
and (content_file[len(base_prefix + start_with):]).count(EXT_SEPARATOR) >= 1 |
] |
# (3) build the resulting dictionary of item_name > item_prefix |
item_prefixes = dict() |
for item_file in content_files: |
end_name = item_file.find(self.separator, len(base_prefix + start_with)) |
if end_name == -1: |
end_name = item_file.find(EXT_SEPARATOR, len(base_prefix + start_with)) |
item_name = item_file[len(base_prefix + start_with):end_name] |
item_prefixes[item_name] = join(parent_dir, base_prefix + start_with + item_name) |
return item_prefixes" |
1349,"def is_multifile_object_without_children(self, location: str) -> bool: |
"""""" |
Returns True if an item with this location is present as a multifile object without children. |
For this implementation, this means that there is a file with the appropriate name but without extension |
:param location: |
:return: |
"""""" |
# (1) Find the base directory and base name |
if isdir(location): # special case: parent location is the root folder where all the files are. |
return len(self.find_multifile_object_children(location)) == 0 |
else: |
# TODO same comment than in find_multifile_object_children |
if exists(location): |
# location is a file without extension. We can accept that as being a multifile object without children |
return True |
else: |
return False" |
1350,"def get_multifile_object_child_location(self, parent_location: str, child_name: str): |
"""""" |
Implementation of the parent abstract method. |
In this mode the attribute is a file with the same prefix, separated from the parent object name by |
the character sequence <self.separator> |
:param parent_location: the absolute file prefix of the parent item. |
:param child_name: |
:return: the file prefix for this attribute |
"""""" |
check_var(parent_location, var_types=str, var_name='parent_path') |
check_var(child_name, var_types=str, var_name='item_name') |
# a child location is built by adding the separator between the child name and the parent location |
return parent_location + self.separator + child_name" |
1351,"def find_simpleobject_file_occurrences(self, location) -> Dict[str, str]: |
"""""" |
Implementation of the parent abstract method. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.