d1_onedrive.impl package

Subpackages

Submodules

d1_onedrive.impl.attributes module

Hold the size and other attributes for a file or folder.

class d1_onedrive.impl.attributes.Attributes(size=0, date=None, is_dir=False)

Bases: object

size()
date()
is_dir()

d1_onedrive.impl.cache_memory module

Cache Python objects in memory.

Cache Python objects with a limit on how many objects can be cached. When the cache reaches a configured size, adding a new object causes the oldest object to be removed. The oldest object is the object that was added first of the objects still in the cache.

class d1_onedrive.impl.cache_memory.Cache(max_items)

Bases: dict

keys() → a set-like object providing a view on D's keys
copy() → a shallow copy of D
log_dump()

d1_onedrive.impl.directory module

Hold the list of files and folders for a directory.

class d1_onedrive.impl.directory.Directory(init_list=None, disable_cache=False)

Bases: collections.abc.MutableSequence

insert(i, v)

S.insert(index, value) – insert value before index

d1_onedrive.impl.disk_cache module

Cache Python objects on disk.

Cache Python objects with a limit on how many objects can be cached. When the cache reaches a configured size, adding a new object causes the oldest object to be removed. The oldest object is the object that was added first of the objects still in the cache.

class d1_onedrive.impl.disk_cache.DiskCache(max_items, cache_directory_path)

Bases: dict

clear() → None. Remove all items from D.

d1_onedrive.impl.log_decorator module

class d1_onedrive.impl.log_decorator.log_func

Bases: object

d1_onedrive.impl.object_tree module

Object Tree.

Based on a source tree that contains only PIDs and queries, maintain the object tree that is browsed through the ONEDrive filesystem.

Cache the information on disk between runs of ONEDrive.

class d1_onedrive.impl.object_tree.ObjectTree(options, source_tree)

Bases: object

refresh()

Synchronize the local tree of Solr records for DataONE identifiers and queries with the reference tree.

get_folder(path, root=None)

Get the contents of an object tree folder.

get_object_tree_folder_name(object_tree_folder)
get_object_record(pid)

Get an object that has already been cached in the object tree.

Caching happens when the object tree is refreshed.

get_object_record_with_sync(pid)

Get an object that may not currently be in the cache.

If the object is not in the cache, an attempt is made to retrieve the record from a CN on the fly. If the object is found, it is cached before being returned to the user. This allows the object tree caching system to be used for objects that are not in the object tree. ONEDrive uses this functionality for the FlatSpace folder.

add_object_to_cache(pid)

Attempt to add a specific object to the cache.

Objects are normally only added to the object tree during refresh. This method is used by the FlatSpace resolver.

get_science_object(pid)
get_system_metadata(pid)
get_source_tree_folder(path)
sync_cache_with_source_tree()

d1_onedrive.impl.onedrive_exceptions module

Type that gets raised as exception for invalid paths.

exception d1_onedrive.impl.onedrive_exceptions.PathException(message)

Bases: Exception

exception d1_onedrive.impl.onedrive_exceptions.ONEDriveException(message)

Bases: Exception

exception d1_onedrive.impl.onedrive_exceptions.NoResultException(message='')

Bases: Exception

d1_onedrive.impl.os_escape module

OS specific escaping.

Escape DataONE identifiers, so that they follow the filesystem conventions and restrictions for valid file- and folder names on a given OS.

Unescape the escaped file- and folder names to arrive at the original DataONE identifiers.

DataONE supports identifiers containing characters that cannot (or should not) be represented directly within the file- and folder names in a filesystem, such as the path separator character (“/” on *nix). This module contains functions for converting between DataONE identifiers and names that are suitable for use as file- and folder names on the operating systems that are supported by ONEDrive.

It is necessary to be able to get the original DataONE identifier given an escaped name, so the escaping must be reversible. This is because the filesystem driver (e.g., FUSE), passes the escaped name back to ONEDrive when the user interacts with the file or folder.

The current implementation simply uses URL percent-encoding of an utf-8 encoding of the Unicode strings.

Quote and unquote are somewhat borrowed from python urllib standard library.

d1_onedrive.impl.os_escape.unquote('abc%20def') → 'abc def'.
d1_onedrive.impl.os_escape.quote(s, unsafe='/')

Pass in a dictionary that has unsafe characters as the keys, and the percent encoded value as the value.

d1_onedrive.impl.os_escape.posix_filename_from_identifier(identifier)
d1_onedrive.impl.os_escape.posix_identifier_from_filename(filename)
d1_onedrive.impl.os_escape.windows_filename_from_identifier(identifier)

On Windows, the following characters are not allowed:

/ : * ? ” < > |

d1_onedrive.impl.os_escape.windows_identifier_from_filename(filename)
d1_onedrive.impl.os_escape.identifier_from_filename(filename)
d1_onedrive.impl.os_escape.filename_from_identifier(identifier)

d1_onedrive.impl.util module

Misc utilities that don’t fit anywhere else.

d1_onedrive.impl.util.log_dump(s)
d1_onedrive.impl.util.ensure_dir_exists(path)
d1_onedrive.impl.util.string_from_path_elements(path)
d1_onedrive.impl.util.is_root(path)
d1_onedrive.impl.util.os_format(txt)