Skip to main content

未提供项目描述

项目描述

$正驱动

这个 Python 库旨在更轻松地使用 Google Drive 来备份/恢复您的数据。

安装

pip install posidrive

安装最新的开发版本:

pip install git+https://github.com/Positeral/posidrive

快速开始

让我们编写一个简单的gd.py脚本:

from posidrive.gdrive import GoogleDrive

gdrive = GoogleDrive(folder='test')
gdrive.cli()

从命令行运行它:

python gd.py
Usage: gd.py [OPTIONS] COMMAND [ARGS]...

Options:
  --debug  Enable debug mode.
  --help   Show this message and exit.

Commands:
  auth      Authorize Google account and save credentials.
  status    Show common information.
  list      Show files in current remote folder.
  upload    Upload file to current remote folder.
  download  Download file by ID.
  delete    Delete file by ID.
  clear     Delete all files in folder.
python gd.py status
Service:               Google Drive
Current remote folder: test
Credentials file:      /home/arthur/projects/posidrive/.pgdcredentials
Authorization:         Not authorized (credentials absent)

现在让我们授权应用程序:

python gd.py auth
Please visit this URL to authorize this application: https://[...]
Enter the authorization code: 

点击链接,授权应用程序并粘贴生成的代码。默认情况下,posidrive请求您获得最低权限。检查状态:

python gd.py status
Service:               Google Drive
Current remote folder: test
Credentials file:      /home/arthur/projects/posidrive/.pgdcredentials
Authorization:         Authorized
Account:               af3.inet@gmail.com
Usage:                 11.2G
Limit:                 15G

好的!现在您可以使用listuploaddownload或。不要忘记每个命令都有选项。deleteclear--help

自定义脚本

以下脚本制作压缩存档并将其上传到 Google Drive。然后,它将删除除最后三个文件之外的所有远程文件:

import os
import click
import tarfile

from posidrive.gdrive import GoogleDrive


class MyGoogleDrive(GoogleDrive):
    @GoogleDrive.cli.command('archive')
    @click.argument('path', required=True)
    def cmd_archive(self, path):
        '''Archive directory/file'''
        self.initialize()

        tarname = os.path.basename(path)+'.tar.lzma'
        tarpath = tarname

        tar = tarfile.open(tarpath, 'w:xz')
        tar.add(path)
        tar.close()

        self.cmd_upload(tarpath, tarname)
        self.cmd_clear(keep_last=3, yes=True)


gdrive = MyGoogleDrive(folder='test')
gdrive.cli()

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

posidrive-0.1.1.tar.gz (7.9 kB 查看哈希

已上传 source

内置分布

posidrive-0.1.1-py3-none-any.whl (9.3 kB 查看哈希

已上传 py3