def _get_directory(self, object_tree_folder, path): dir = directory.Directory() merged_region_tree = self._get_merged_region_tree(object_tree_folder) region_tree_item, unconsumed_path = self._get_region_tree_item_and_unconsumed_path( merged_region_tree, path ) if self._region_tree_item_is_pid(region_tree_item): # If there is an unconsumed path section, the path exits through a valid # PID (any other exit would have raised an exception). #if len(unconsumed_path): return self._resource_map_resolver.get_directory( object_tree_folder, [region_tree_item] + unconsumed_path ) #else: # # The user has attempted to "dir" a PID. # raise onedrive_exceptions.PathException('not a directory') # The whole path was consumed and a folder within the tree was returned. dir = directory.Directory() #if self._has_readme_entry(path): # dir.append(self._get_readme_filename()) for r in region_tree_item: dir.append(r) # Add readme.txt to root. if not path: dir.append('readme.txt') return dir
def _resolve_taxa_root(self, object_tree_folder): d = directory.Directory() for g in self._classifications: if g in object_tree_folder['items']: d.append(g) break return d
def _resolve_objects_in_year(self, year, object_tree_folder): dir = directory.Directory() for pid in object_tree_folder['items']: record = self._object_tree.get_object_record(pid) if 'beginDate' in record and 'endDate' in record: if self._is_year_in_date_range(year, record['beginDate'], record['endDate']): dir.append(record['id']) self._raise_exception_if_empty_directory(dir) return dir
def _resolve_author_root(self, object_tree_folder): d = directory.Directory() authors = set() for pid in object_tree_folder['items']: try: authors.add( self._object_tree.get_object_record(pid)[u'author']) except KeyError: pass d.extend(authors) return d
def _resolve_decades(self, object_tree_folder): dir = directory.Directory() sites = set() for pid in object_tree_folder['items']: record = self._object_tree.get_object_record(pid) if 'beginDate' in record and 'endDate' in record: for decade in self._decade_ranges_in_date_range( record['beginDate'], record['endDate']): sites.add(decade) dir.extend(sites) return dir
def _resolve_author(self, author, object_tree_folder): d = directory.Directory() for pid in object_tree_folder['items']: try: record = self._object_tree.get_object_record(pid) if record['author'] == author: d.append(record['id']) except KeyError: pass # As each author folder in the root has at least one object, an empty folder # here can only be due to an invalid path. if not d: raise onedrive_exceptions.PathException(u'Invalid author') return d
def _resolve_years_in_decade(self, decade, object_tree_folder): first_year_in_decade = self._validate_and_split_decade_range(decade)[0] dir = directory.Directory() sites = set() for pid in object_tree_folder['items']: record = self._object_tree.get_object_record(pid) if 'beginDate' in record and 'endDate' in record: for year in self._years_in_date_range_within_decade( first_year_in_decade, record['beginDate'], record['endDate']): sites.add(str(year)) dir.extend(sites) self._raise_exception_if_empty_directory(dir) return dir
def _resolve_taxa_classification_value(self, classification, value, object_tree_folder): d = directory.Directory() for pid in object_tree_folder.get_records['items']: record = self._object_tree.get_object_record(pid) try: if value in record[classification]: d.append(record['id']) except KeyError: pass # As empty folders in the taxa tree are pruned in the root and first level, # an empty folder here can only be due to an invalid path. if not len(d): raise onedrive_exceptions.PathException( u'Invalid taxonomic classification value') return d
def _resolve_object_tree_folder(self, object_tree_folder): dir = directory.Directory() self._append_folders(dir, object_tree_folder) dir.extend(self._resolvers.keys()) return dir
def _escape_directory_entries(self, dir): return directory.Directory( os_escape.filename_from_identifier(d) for d in dir )
def _resolve_root(self): dir = directory.Directory() dir.extend(self._resolvers.keys()) return dir
def _get_directory(self, object_tree_root, path): d = directory.Directory() d.append(self._get_readme_filename()) d.extend(object_tree_root['items']) return d