Difficult-Rocket/.github/workflows/dsm.py
shenjack f9eeafe322
好活!
readme update

看起来更像 Dear ImGui 一些(looks more like Dear ImGui

and some intersting feature to the button

remove debug

确认一下action

404 修改

writing theme

looks good

better?

a ?

alpha=255 not 256

looks better

try new pyglet first

看起来好一些

sync pyglet

水一手

这波必须得水一手了,要不然commit太少了(确信

丢点正经东西上去

顺手继承一下Options

补充docs

坏了,忘记水commit了(

至少我能早睡了(

这里还能水一点来着(

试试再说

reee

保证能跑(

同步lib not dr 的修改

忘记带上 None了

还是加上一个额外的判断参数吧

刷点commit也不错

先更新一下依赖版本

水commit啦

理论可行,实践开始!

构建参数喜加一

reeeee

更新一下 pyproject 的依赖

fix typing

looks better

水一个(

测试?

sync pyglet to master

A | Try use rust-cache

looks good?

what?

C | sync pyglet

A | 添加了一个 Button Draw Theme

A | Magic Number (确信)

A | 尽量不继承Options

sync pyglet

A | Add theme

A | Add more Theme information

Enhance | Theme

sync pyglet

Add | add unifont

Enhance | use os.walk in font loading

Enhance | Use i18n in font loading

Enhance | doc

sync pyglet

Add | add 3.12 build option to build_rs

Fix | Button position have a z

sync pyglet

A | Logger.py 启动!

sync pyglet

Changed | Bump pyo3 to 0.20.0

add logger.py update

logger!

Add | more logger!

Add | lib-not-dr

some lib-not-dr
2023-11-20 20:12:56 +08:00

117 lines
4.5 KiB
Python

# -------------------------------
# Difficult Rocket
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
# All rights reserved
# -------------------------------
import os
import time
from pprint import pprint
from synology_api import filestation
class DSM:
def __init__(self, docs_path: str, dsm_path: str):
self.docs_path = docs_path
self.dsm_path = dsm_path
self.token = os.environ['DSM_TOKEN']
self.fl = filestation.FileStation(ip_address='hws.shenjack.top',
port=5000,
username='github',
password=self.token,
secure=False,
cert_verify=False,
dsm_version=7,
debug=True,
interactive_output=False)
def list_files(self):
# 输出 文档构建目录 的内容
print(f'==========输出 {self.docs_path} 的内容==========')
for root, dirs, files in os.walk(self.docs_path):
print(root, dirs)
print('==========就这些==========')
def clear_dsm(self):
# 清空 DSM 的 /web/dr 目录
delete_task = self.fl.start_delete_task(self.dsm_path, recursive=True)
delete_task_id = delete_task['taskid']
time.sleep(1) # 等待 1 秒 保证任务已经完成
pprint(self.fl.get_delete_status(delete_task_id)['data']['finished'])
def check_md5(self, local_md5: str) -> bool:
"""
检查本地构建的文档和 DSM 上的文档的 md5 是否一致
:param local_md5:
:return: True: 一致 False: 不一致
"""
# 打开提供的md5文件
try:
with open(local_md5, 'r', encoding='utf-8') as f:
md5 = f.read()
except FileNotFoundError:
print(f'文件 {local_md5} 不存在')
return False
# 检测是否存在 dsm 上的 md5.txt
dsm_files = self.fl.get_file_list(folder_path='/web/dr')
if dsm_files.get('error'):
print(dsm_files['error'])
return False
dsm_files = dsm_files['data']['files']
if '/web/dr/md5.txt' not in [file['path'] for file in dsm_files]:
print('dsm md5.txt 不存在')
return False
# 下载 dsm 上的 md5.txt
try:
self.fl.get_file(path='/web/dr/md5.txt', mode='download', dest_path='./docs/book')
with open('./docs/book/md5.txt', 'r', encoding='utf-8') as f:
md5_last = f.read()
if md5 == md5_last:
return True
except Exception as e:
print(e)
return False
def upload_docs(self, local_md5: str):
# 上传本地构建的文档到 DSM
print(f'==========上传 {self.docs_path}{self.dsm_path}==========')
# 使用 os.walk 递归遍历文件夹 依次按照对应路径上传
# 上传的时候 目标路径为本地路径的相对路径
for root, dirs, files in os.walk(self.docs_path):
for file in files:
file_path = os.path.join(root, file)
dest_path = f'{self.dsm_path}{root[len(self.docs_path):]}'
dest_path = dest_path.replace('\\', '/')
# 输出 文件路径 和 目标路径
print(f'{file_path} -> {dest_path}', end=' ')
pprint(self.fl.upload_file(dest_path=dest_path,
file_path=file_path,
overwrite=True))
# self.fl.upload_file(dest_path=dest_path,
# file_path=file_path,
# overwrite=True)
# 上传本地的 md5 文件
print(f'{local_md5} -> {self.dsm_path}', end=' ')
pprint(self.fl.upload_file(dest_path=self.dsm_path,
file_path=local_md5,
overwrite=True))
print('==========上传完成==========')
def main():
docs_path = 'docs/book'
dsm_path = '/web/dr'
dsm = DSM(docs_path, dsm_path)
dsm.list_files()
if dsm.check_md5('docs/md5.txt'):
print('md5 一致,不需要上传')
return 0
dsm.clear_dsm()
dsm.upload_docs('docs/md5.txt')
dsm.fl.logout()
if __name__ == '__main__':
main()