用于同步两个文件夹的库

sync-folders的Python项目详细描述


同步文件夹包

大家好!这是Python“sync folders”上我的包的存储库。在

目录

动机

有一天我做了一个脚本,它根据文件夹的文件日期同步两个文件夹。以后我想在PyPi上创建包。另外,除了syncing之外,我还为处理文件添加了一些新功能。在

生成状态

在这里您可以看到continuous integration/continuous deployment的生成状态:

Python packageLint Code BaseUpload Python PackagePyPI - Downloads

代码样式

我使用Codacy来自动化我的代码质量。在

Codacy Badge

依赖关系

You can see all dependencies from requirements.txthere.

特点

使用我的软件包,您可以sync两个文件夹,manage日志文件,delete空文件夹和旧文件,读取并创建zip存档文件。在

安装

首先安装Python。在

If you don't have pip, install it.

然后输入终端:

pip install sync-folders --upgrade

导入

^{pr2}$

快速使用

此模块的用法示例

同步

main.sync('./test_a','./test_b')# Expected creation of `logs.txt`

文件输出

main.files('./')""" Expected output.gitattributes   Last Modified: 18 Jun 2020, 08 52.gitignore       Last Modified: 10 Jun 2020, 06 39CONTRIBUTING.md  Last Modified: 23 Jun 2020, 12 26LICENSE  Last Modified: 09 Jun 2020, 18 10README.md        Last Modified: 23 Jun 2020, 18 20requirements.txt         Last Modified: 10 Jun 2020, 15 00setup.cfg        Last Modified: 10 Jun 2020, 07 08setup.py         Last Modified: 21 Jun 2020, 14 03_config.yml      Last Modified: 10 Jun 2020, 09 28"""

Dirs输出

main.dirs('./tests')""" Expected output.venvtest_atest_b"""

读取文件数据

print(main.read_file('./index.py'))""" Expected outputfrom sync_folders import main, purgelog, cleanerprint(main.read_file('./index.py'))"""

写入文件

Not an appending

main.write_file('./test.txt','your text')

目录

main.list_dir('./')""" Expected result['.git', '.github', '.venv', 'sync_folders', 'tests', 'util']"""

文件列表

main.get_files('./')""" Expected result[  {'name': 'python-package.yml', 'date': 1592564708.6109703, 'date_str': '19 Jun 2020, 11 05'},   {'name': 'python-publish.yml', 'date': 1591772746.2324488, 'date_str': '10 Jun 2020, 07 05'}]"""

读取zip存档

main.read_zip('./test.zip')""" Expected outputtest_a/            Compress size: 0.0 in KB            Filesize: 0.0 in KBtest_a/test.docx            Compress size: 8.490234375 in KB            Filesize: 11.1572265625 in KBtest_b/            Compress size: 0.0 in KB            Filesize: 0.0 in KB"""

存档

中的元素列表
main.files_in_zip('test.zip')""" Expected result['test_a/', 'test_a/test.docx', 'test_b/']"""

从存档中提取元素

main.extract('test.zip','test_a/test.docx')# Expected creation of `test_a/test.docx`

创建存档

main.create_zip(['_config.yml','LICENSE','setup.py'],'./test.zip')# Expected creation of `test.zip`

清洁剂

cleaner.cleaner(['./test_a','./test_a/test_c','./test_b'],5)# Expected creation of `logs.txt`""" Expected outputSTART TIME: Tue Jun 23 22:01:00 2020Total deleted size: 0.0 MBTotal deleted files: 0Total deleted empty folders: 3FINISH TIME: Tue Jun 23 22:01:00 2020"""

Purgelog

purgelog.purgelog('./logs.txt',5,2)""" Expected outputCopied: logs.txt to 1_logs.txt"""# Expected creation of `1_logs.txt`

美国石油学会

在主同步(路径a,路径b)

NameTypeArgumentDefaultDescription
path_a^{}^{}^{}the path to the directory
path_b^{}^{}^{}the path to the directory

在main.files文件(路径)

^{tb2}$

在主目录(路径)

^{tb2}$

在main.read_文件(路径)

NameTypeArgumentDefaultDescription
path^{}^{}^{}the path to the file

在main.write_文件(路径,数据)

NameTypeArgumentDefaultDescription
path^{}^{}^{}the path to the file
data^{}^{}^{}the content

在主目录(路径)

^{tb2}$

在main.get_文件(路径)

^{tb2}$

在main.read\u邮编(路径)

NameTypeArgumentDefaultDescription
path^{}^{}^{}the path to the archive

在main.files_-zip格式(路径)

NameTypeArgumentDefaultDescription
path^{}^{}^{}the path to the archive

在主要.摘录(path_to_zip,path_to_file)

NameTypeArgumentDefaultDescription
path_to_zip^{}^{}^{}the path to the archive
path_to_file^{}^{}^{}the path to the need file for extracting

在main.create_-zip文件(文件,路径)

NameTypeArgumentDefaultDescription
files^{}^{}^{}the list of pathes to the files for archiving
path^{}^{}^{}the path to the new archive

在清洁工。清洁工(文件夹,限制)

NameTypeArgumentDefaultDescription
folders^{}^{}^{}the array of the folders
limit^{}^{}^{}the limit of the days for comparing

在purgelog.purgelog公司(日志文件,限制,编号)

NameTypeArgumentDefaultDescription
log-file^{}^{}^{}the path to the log-file
limit^{}^{}^{}the limit of the maximum memory
number^{}^{}^{}the number of the maximum available number of the logs file

代码示例

这里你可以看到同步两个文件夹的函数

# Main function for synchronize two foldersdefsync(path_a=None,path_b=None):ifnotpath_aornotpath_b:raiseNameError('Required path to both dirs')logs=''files_in_a=get_files(path_a)files_in_b=get_files(path_b)same_files=[]forfile_ainfiles_in_a:forfile_binfiles_in_b:iffile_b['name']==file_a['name']:# compare datesiffile_b['date']<file_a['date']:# changeshutil.copy2(path_a+'/'+file_a['name'],path_b)logs+=f"Change {file_a['name']} in {path_b}"+'\n'same_files.append(file_b['name'])forfile_ainfiles_in_a:ifnotfile_a['name']insame_files:# move to bshutil.copy2(path_a+'/'+file_a['name'],path_b)logs+=f"Create {file_a['name']} in {path_b}"+'\n'write_file('./logs.txt',logs)

测试

使用pytest进行单元测试

公司名称:微笑:我给你从link到{a49},在那里你可以看到我所有的测试。在

贡献

欢迎拉取请求。对于重大变化,请先打开一个问题,讨论您希望更改的内容。再看看CONTRIBUTING.md。在

学分

链接到帮助我构建此项目的视频和文章:

许可证

GitHub

麻省理工学院mezgoodle

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

推荐PyPI第三方库


热门话题
java如何在href中将struts2文本字段的值作为参数传递?   java检查对象属性是否为空的最佳方法是什么?   java通过Maven使用Junit类别运行Cucumber测试   java如何在selenium Webdriver(Mac)中使用Robot类上传多个文件?   如何用python绘制图形或将python转换为java和Matlab?   java Osgi捆绑包更新和ResourceBundle   java使用流api将流<@Nullable T>转换为流<@NonNull T>   java中EXCEL的平台无关连接字符串   JavaFX中的java表   java Jetty线程池和sun。HttpServer会话   JPA存储库bean的java Spring注入无法工作NullPointerException   java从另一个Kubernetes作业触发Kubernetes   我的java netbeans抽奖计划需要帮助吗   泛型中的java有界类型无法扩展另一个有界类型   如果混合使用全局构建和概要文件构建,java cxfcodegenplugin会生成错误代码   封装SQL平台之间差异的java策略?