asynchronous generic cloud drive library
Project description
wcpan.drive
Asynchronous generic cloud drive library.
This package needs a driver to actually work with a cloud drive.
Example Usage
from wcpan.drive.core.drive import (
DriveFactory, download_to_local, upload_from_local,
)
async def simple_demo():
# Load config and data from default locations.
factory = DriveFactory()
factory.load_config()
async with factory() as drive:
# Check for authorization.
if not await drive.is_authorized():
# Start OAuth 2.0 process
url = await drive.get_oauth_url()
# ... The user visits the url ...
# Get tokens from the user.
token = ...
# Finish OAuth 2.0 process.
await drive.set_oauth_token(token)
# It is important to keep cache in sync.
async for change in drive.sync():
print(change)
# Get the root node.
root_node = await drive.get_root_node()
# Get a node.
node = await drive.get_node_by_path('/path/to/drive/file')
# List children.
children = await drive.get_children(root_node)
# Make a folder.
new_folder = await drive.create_folder(root_node, 'folder_name')
# Download file.
await download_to_local(drive, node, '/tmp')
# Upload file.
new_file = await upload_from_local(drive, root_node, '/path/to/local/file')
# Traverse drive.
async for root, folders, files in drive.walk(root_node):
print(root, folders, files)
async def config_demo():
factory = DriveFactory()
# Read config files from here.
# The default is $HOME/.config/wcpan.drive.
# These files are what you want to keep and backup.
factory.config_path = '/tmp/config'
# Put generated files here.
# The default is $HOME/.local/share/wcpan.drive.
# These files should be safely deleted.
factory.data_path = '/tmp/data'
# Setup cache database, will write to data folder.
factory.database = 'nodes.sqlite'
# Setup driver class.
factory.driver = 'some.random.driver.RandomDriver'
# load config file from config folder
# this will not overwrite the above given values
factory.load_config()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
wcpan.drive.core-3.0.1.tar.gz
(19.1 kB
view hashes)
Built Distribution
Close
Hashes for wcpan.drive.core-3.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6477834e55e0a66dfd76610dcaf2d4859117172311a8af2f43740f91e87c2679 |
|
MD5 | c8c0b42c5da5d5f63f1a41113d0aefc8 |
|
BLAKE2b-256 | 0264cb1f40a391b106864d8f447ab252f7132ca44053c48981fdf7095a49a0f2 |