跳转到主要内容

git annex 特殊远程简化

项目描述

Tests PyPI version Code style: black

AnnexRemote

git annex开发特殊远程的辅助模块。AnnexRemote为您处理所有协议相关的事情,让您可以专注于远程本身。它实现了完整的外部特殊远程协议并满足有关空白等所有规范。这是通过大量的测试套件确保的。

文档

(也可以看看示例和基于AnnexRemote的git-annex-remote-googledrive。))

入门

先决条件

您需要在您的系统上安装python3。

安装

pip3 install annexremote

运行测试

如果您想运行测试,请将tests文件夹的内容复制到与annexremote.py相同的目录。然后使用像pytest这样的测试发现工具来运行它们。

用法

导入必要的类

from annexremote import Master
from annexremote import SpecialRemote
from annexremote import RemoteError

现在创建您自己的特殊远程类。它必须派生自SpecialRemote并实现至少6个基本方法

class MyRemote(SpecialRemote):
    def initremote(self):
        # initialize the remote, eg. create the folders
        # raise RemoteError if the remote couldn't be initialized

    def prepare(self):
        # prepare to be used, eg. open TCP connection, authenticate with the server etc.
        # raise RemoteError if not ready to use

    def transfer_store(self, key, filename):
        # store the file in `filename` to a unique location derived from `key`
        # raise RemoteError if the file couldn't be stored

    def transfer_retrieve(self, key, filename):
        # get the file identified by `key` and store it to `filename`
        # raise RemoteError if the file couldn't be retrieved

    def checkpresent(self, key):
        # return True if the key is present in the remote
        # return False if the key is not present
        # raise RemoteError if the presence of the key couldn't be determined, eg. in case of connection error
        
    def remove(self, key):
        # remove the key from the remote
        # raise RemoteError if it couldn't be removed
        # note that removing a not existing key isn't considered an error

在您的main函数中,将远程对象链接到主类并初始化协议

def main():
    master = Master()
    remote = MyRemote(master)
    master.LinkRemote(remote)
    master.Listen()

if __name__ == "__main__":
    main()

现在将您的程序保存为git-annex-remote-$something并使其可执行。

chmod +x git-annex-remote-$something(您需要sheebang行#!/usr/bin/env python3

就是这样。现在您已经创建了您的特殊远程。

导出远程对象

导入并派生自ExportRemote而不是SpecialRemote

# ...
from annexremote import ExportRemote

class MyRemote(ExportRemote):
    # implement the remote methods just like in the above example and then additionally:
    
    def transferexport_store(self, key, local_file, remote_file):
        # store the file located at `local_file` to `remote_file` on the remote
        # raise RemoteError if the file couldn't be stored

    def transferexport_retrieve(self, key, local_file, remote_file):
        # get the file located at `remote_file` from the remote and store it to `local_file`
        # raise RemoteError if the file couldn't be retrieved

    def checkpresentexport(self, key, remote_file):
        # return True if the file `remote_file` is present in the remote
        # return False if not
        # raise RemoteError if the presence of the file couldn't be determined, eg. in case of connection error

    def removeexport(self, key, remote_file):
        # remove the file in `remote_file` from the remote
        # raise RemoteError if it couldn't be removed
        # note that removing a not existing key isn't considered an error

    def removeexportdirectory(self, remote_directory):
        # remove the directory `remote_directory` from the remote
        # raise RemoteError if it couldn't be removed
        # note that removing a not existing directory isn't considered an error

    def renameexport(self, key, filename, new_filename):
        # move the remote file in `name` to `new_name`
        # raise RemoteError if it couldn't be moved

日志记录

此模块包括一个StreamHandler,用于将日志记录发送到git annex通过特殊远程协议(使用DEBUG)。您可以使用它这样

...
import logging
...

def main():
    master = Master()
    remote = MyRemote(master)
    master.LinkRemote(remote)

    logger = logging.getLogger()
    logger.addHandler(master.LoggingHandler())

    master.Listen()

if __name__ == "__main__":
    main()

许可协议

本软件项目采用GPLv3许可 - 请参阅LICENSE文件以获取详细信息

项目详情


下载文件

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

源分布

annexremote-1.6.6.tar.gz (62.6 kB 查看哈希值

上传时间

构建分布

annexremote-1.6.6-py3-none-any.whl (25.9 kB 查看哈希值

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面