将系统调用包装到rsync的python模块

sysrsync的Python项目详细描述


系统同步

将系统调用包装到rsync的python模块

要求

  • rsync
  • Python3.6+

开发

  • pipenv(确保pipenv和pip都升级到最新版本)

用法

  • 基本文件同步
importsysrsyncsysrsync.run(source='/home/user/foo.txt',destination='/home/server/bar')# runs 'rsync /home/users/foo.txt /home/server/files'
  • 带有选项的ssh
importsysrsyncsysrsync.run(source='/home/user/files',destination='/home/server/files',destination_ssh='myserver',options=['-a'])# runs 'rsync -a /home/users/files/ myserver:/home/server/files'
  • 除外条款
importsysrsyncsysrsync.run(source='/home/user/files',destination='/home/server/files',destination_ssh='myserver',options=['-a'],exclusions=['file_to_exclude','unwanted_file'])# runs 'rsync -a /home/users/files/ myserver:/home/server/files --exclude file_to_exclude --exclude unwanted_file'

API

sysrsync.run

argumenttypedefaultdescription
cwdstr^{}working directory in which subprocess will run the rsync command
strictbool^{}raises ^{} when rsync return code is different than 0
verbosebool^{}verbose mode: currently prints rsync command before executing
**kwargsdictNot Applicablearguments that will be forwarded to call to ^{}

返回subprocess.CompletedProcess

strict = True和rsync返回代码不同于0(Success)时引发RsyncError

sysrsync.get_rsync_command

argumenttypedefaultdescription
sourcestr-Source folder or file
destinationstr-Destination folder
source_sshOptional[str]NoneRemote ssh client where source is located
destination_sshOptional[str]NoneRemote ssh client where destination is located
exclusionsIterable[str][]List of excluded patterns as in rsync's ^{}
sync_source_contentsboolTrueAbstracts the elusive trailing slash behaviour that ^{} normally has when using rsync directly, i.e. when a trailing slash is present in ^{}, the folder's content is synchronized with destination. When no trailing slash is present, the folder itself is synchronized with destination.
optionsIterable[str][]List of options to be used right after rsync call, e.g. ^{} translates to ^{}

返回List[str]->;要直接在subprocess.run中使用的命令的编译列表

在同时设置source_sshtarget_ssh时引发RemotesError。通常linux rsync发行版不允许源和目标同时是远程的。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java窗口。位置和窗口。公开问题   java如何从存储在ArrayList<Node>中的动态生成的文本字段中获取文本?   java如何立即关闭InputStream?   如何重新启动Java程序以激活环境变量   java搜索字符串是否相差一个字符   java CFB模式输出与CTR输出相同;我做错什么了吗?   java如何在javaFX中将实例化对象添加到Stage   java如何在jtextarea上打印来自不同类的文本消息   java以编程方式确定IOException的原因?   限制Java NIO通道(文件或socket)中的可用内容   javajaxb与JDOM:是否可以使用JAXB更新xml文件   批处理文件到java测试   JavaFX:stage的作用是什么。可设置大小(false)是否会导致额外的页边距?   java有没有办法告诉IntelliJ按需堆叠参数?   java Seam会话范围的组件在下一个请求中消失   java Google Web Toolkit对开发复杂的java脚本有用吗?   安卓 studio java ArrayList正在检索最高值   java为什么递归地用随机数填充LinkedList时会出现StackOverflowException?