轻量级无依赖更新软件

rupdater的Python项目详细描述


Codacy Badge

rupdater是一个超轻量级且无依赖关系的更新程序,它提供 远程版本解析、下载并获取更新的哈希和。

安装

rupdater可以通过运行以下命令从pypi安装:

pip install rupdater

用法

首先,创建updater的新实例。它需要两个参数: 当前本地版本和远程版本数据文件的URL:

fromrupdaterimportUpdaterupdater=Updater('1.0.0a0','https://example.com/remote_version.json',use_json=True)

现在您可以通过调用check()方法来检查更新:

ifupdater.check():print('Update found!')

检查后,您可能需要下载更新。这是可以做到的 使用download()方法,返回类似文件的对象(字节模式) 下载的更新(存储在临时文件中)。 您应该只在上下文管理器中使用它。

withupdater.download()asupdate_file,open('update.zip','w+b')asf:f.write(update_file.read())

此示例将从update_文件读取数据并将其写入update.zip。

更复杂的逐块读/写示例:

withupdater.download()asupdate_file,open('update.zip','w+b')asf:forchunkiniter(lambda:update_file.read(1024*16),b''):f.write(chunk)

rupdater还有hash static方法,该方法接受2个必需参数和1个可选参数: 类文件对象、散列算法(字符串)和块大小,即 默认为1024*16。下面是用法示例:

withupdater.download()asupdate_file:hashes_match=Updater.hash_file(update_file,updater.hash_algo)==updater.hash

警告!如果要重用更新文件,必须seek(0)。示例:

withupdater.download()asupdate_file,open('update.zip','w+b')asf:forchunkiniter(lambda:update_file.read(1024*16),b''):f.write(chunk)f.seek(0)assertUpdater.hash_file(f,updater.hash_algo)==updater.hash

您还可以通过调用get_version_data()再次手动解析版本数据。

便携性

rupdater.py目前绝对独立于任何事物。 python标准库是唯一的需求。所以如果你需要, 您只需复制此文件并像单个模块一样使用它。

异常处理

rupdater不会发现任何错误,你必须按照自己的意愿去做。 此外,当输入数据不正确时,rupdater可能会产生值错误。 (版本数据文件格式不正确,哈希算法未知等)。

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

推荐PyPI第三方库


热门话题
JSON对象字段中的java MongoDB JSON数组删除   java Spring Boot@Autowired对象空指针异常   java什么时候出现内存不足?   安卓三星健康:解决java。lang.IllegalArgumentException:心率(读取)无效   tomcat java重定向301但浏览器未正确打开新url   java对象数组重复擦除   整数的JavaSpringbean注入失败   对于重复查询,JDBCforMySQL的java性能非常慢   java Entitymanager,连接太多   使用RequestDispatcher发送变量值时出现java问题   java如何禁用GWT RichTextArea拖动调整大小   JavaEclipse插件开发:如何通过代码添加默认VM参数?   java如何使用时间戳构造函数   java将两个活动JPanel层叠在一起