git annex 特殊远程简化
项目描述
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 查看哈希值)
关闭
annexremote-1.6.6.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 5f78d0753c0763d95fc4c52050bd6212bb32457d32f6575dc66a83178e0283a7 |
|
MD5 | e7cc65ff1744af569056b0f562927dcc |
|
BLAKE2b-256 | 5f04d7a39a2ab1de54fd7bfbb26feb4487baa71be4e10f9c677ee5ee6fade89b |
关闭
annexremote-1.6.6-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | dee4efa33c3bd9514928af5c57c82599ca9dc0a5535121ee234ed1833a98f93e |
|
MD5 | ea78440430044df51eb85563acdefe71 |
|
BLAKE2b-256 | 91b60d74517d0b33dfe372b47b2ef5781a2231e891f8fe8edea74a447a7f7380 |