写了我也不知道是什么的东西

This commit is contained in:
2022-08-13 19:28:59 +08:00
parent a8180eef29
commit 8d19ed0373
4 changed files with 48 additions and 0 deletions
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
+48
View File
@@ -0,0 +1,48 @@
# 实现 update、install、upgrade
import os
import sys
import time
import json
import tqdm
import requests
class Internet:
def __init__(self, url) -> None:
self.url = url
# 下载文件(带进度条)
def download(self, path, part = 1024, show = 1, description="") -> None:
file = requests.get(self.url, stream=True)
allSize = int(file.headers["content-length"]) # 文件总大小
progressbar = tqdm.tqdm(total=int(allSize / show))
progressbar.set_description(description)
with open(path, "wb") as filePart:
for chunk in file.iter_content(chunk_size=part):
if chunk:
progressbar.update(int(part / show))
filePart.write(chunk)
##############
#
#############
# oyo update
# 读取配置文件
setFile = "/etc/oyo/sources.list"
listPath = "/etc/oyo/lists"
if sys.argv[1] == "update":
# 读取设置源,按行读取
sourceFile = open(setFile, "r")
listNumber = 0
while True: # 按行读取
line = sourceFile.readline()
if not line: # 如果到末尾
break
# 提取 Url
if "#" in line: # 忽略注释
line = line[:line.index("#")]
line = line.strip()
# 更新本地 applist
Internet(f"{line}/applist.list").download(f"{listPath}/list{listNumber}.list", description=f"List {listNumber}")
sourceFile.close()
pass