未知
dsmsfilepackager的Python项目详细描述
将选定的文件或目录添加到文件包中,生成清单, 以及从sftp服务器上传或下载。用于DSM。
请注意,文件包不是线程安全的。由你来确保 只有一个进程在任何时间点操作包。为了这个 原因,建议您使用uuid(如芹菜任务id)来 确保每个流程都有自己的空间。
编写新包时如何使用:
from dsmsfilepackager.filepackage import DSMSFilePackage import uuid fpack = DSMSFilePackage(target_id=111, job_id=13244, uid=uuid.uuid4(), hostname="remote_sagenth.example.com", hostport="1222", username="theuser", priv_key="/home/theuser/.sagenth/key", local_root="/tmp/cache", remote_root="/upload_target") # register in manifest fpack.add("myfile.txt") fpack.add_dir("docs/") fpack.finish_and_upload() # generate a manifest and upload
一旦包生成完成,文件都将在本地 /tmp/cache/111/13244/[uuid],以及ftp服务器上 /上传目标/111/13244/[uuid]。
现在,其他进程可以访问本地缓存的文件 可用,或者它们将通过sftp获取并移动到本地缓存中,如果 不是。
如何提取以前存储的包:
# auto-get remote files, reading from cache when available >>> fpack = filepackage.fetch(target_id=111, job_id=13244, uid=uuid.uuid4(), host="remote_sagenth.example.com", hostport="1222", username="theuser", priv_key="/home/theuser/.sagenth/key", local_root="/tmp/cache", remote_root="/upload_target") >>> print fpack.manifest.files ["myfile.txt", "docs/readme.txt", "docs/2.py"] >>> file_info = fpack.manifest.get("myfile.txt") >>> file_info.size 1246 >>> file_info.sha256 "d8d5d29645ce8552646ad236244304892bb9e0df633e2603a1fa616682e1c431" >>> file_info.type "Python script, ASCII text executable" >> fh = fpack.open("myfile.txt") # will be made available locally