写了我也不知道是什么的东西
This commit is contained in:
Regular → Executable
Regular → Executable
+48
@@ -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
|
||||||
Reference in New Issue
Block a user