diff --git "a/librian/librian_util/release\344\277\241\346\201\257.py" "b/librian/librian_util/release\344\277\241\346\201\257.py" new file mode 100644 index 0000000..d12bf81 --- /dev/null +++ "b/librian/librian_util/release\344\277\241\346\201\257.py" @@ -0,0 +1,4 @@ +from . import 路徑 + + +是release = (路徑.librian外層 / '.librian_release_info').is_file() diff --git "a/librian/librian_util/\346\233\264\346\226\260\345\231\250.py" "b/librian/librian_util/\346\233\264\346\226\260\345\231\250.py" new file mode 100644 index 0000000..6e1352d --- /dev/null +++ "b/librian/librian_util/\346\233\264\346\226\260\345\231\250.py" @@ -0,0 +1,69 @@ +import logging +import subprocess +import base64 +import hashlib + +import requests + +from . import 路徑, release信息 + + +嵌入的python路徑 = 路徑.librian外層 / 'python36/python.exe' + +嵌入的git路徑 = 路徑.librian外層 / 'MinGit-2.25.0-busybox-64-bit/cmd/git.exe' + + +def 自我更新(): + if release信息.是release: + git路徑 = 嵌入的git路徑 + else: + try: + git路徑 = 'git' + subprocess.check_call('git --version', stdout=subprocess.DEVNULL) + except FileNotFoundError: + raise FileNotFoundError('需要一個Git。更新功能需要你有Git命令可用,或者使用release版本中嵌入的Git。') + subprocess.run( + [str(git路徑), 'pull', 'origin', 'master'], + shell=True, + check=True, + stderr=subprocess.PIPE, + cwd=路徑.librian外層, + ) + + if release信息.是release: + subprocess.run( + [str(嵌入的python路徑), '-m', 'pip', 'install', '-r', 'requirements_release.txt'], + shell=True, + check=True, + stderr=subprocess.PIPE, + cwd=路徑.librian外層, + ) + build文件更新() + + +def build文件更新(): + def md5(fname): + hash_md5 = hashlib.md5() + with open(fname, 'rb') as f: + for chunk in iter(lambda: f.read(4096), b""): + hash_md5.update(chunk) + return base64.b64encode(hash_md5.digest()).decode('utf-8') + + def 下載(文件名, 網址): + r = requests.get(網址) + with open(文件名, 'wb') as f: + f.write(r.content) + + 文件表 = { + 'Librian面板.exe': 'https://rimosto-cdn.azureedge.net/librian/Librian面板.exe' + } + for 文件名, 網址 in 文件表.items(): + 文件真名 = 路徑.librian外層 / 文件名 + if 文件真名.is_file(): + 本地md5 = md5(文件真名) + 在線md5 = requests.head(網址).headers['Content-MD5'] + if 本地md5 == 在線md5: + continue + logging.warning(f'{文件名}過期了。') + 下載(文件名, 網址) + logging.warning(f'下載{文件名}。') diff --git "a/librian/librian\351\235\242\346\235\277/librian_panel.py" "b/librian/librian\351\235\242\346\235\277/librian_panel.py" index c51acd6..d5679ca 100644 --- "a/librian/librian\351\235\242\346\235\277/librian_panel.py" +++ "b/librian/librian\351\235\242\346\235\277/librian_panel.py" @@ -22,7 +22,7 @@ from librian.librian本體.帶有vue的山彥 import 帶有vue的山彥 from librian.librian本體.librian虛擬機 import 虛擬機環境 -from librian.librian_util import 加載器, 文件, 路徑 +from librian.librian_util import 加載器, 文件, 路徑, 更新器 rp = dulwich.repo.Repo('.') @@ -169,19 +169,14 @@ def 瀏覽器打開(self, s): webbrowser.open(s) def 自我更新(self, callback): - git路徑 = 'git' - try: - subprocess.check_call('git --version', stdout=subprocess.DEVNULL) - except FileNotFoundError: - 嵌入的git路徑 = 路徑.librian外層 / 'MinGit-2.25.0-busybox-64-bit/cmd/git.exe' - if Path(嵌入的git路徑).is_file(): - git路徑 = 嵌入的git路徑 - else: - self.alert('需要一個Git', 'info', '更新功能需要你有Git命令可用,或者使用release版本中嵌入的Git。') - return def t(): - r = subprocess.run(f'{git路徑} pull origin master', stderr=subprocess.PIPE, encoding='utf8', check=False) - callback.Call([r.returncode, r.stderr]) + try: + 更新器.自我更新() + except subprocess.CalledProcessError as e: + callback.Call([e.returncode, e.stderr.decode('gbk')]) + except Exception as e: + callback.Call([1, e.__repr__()]) + callback.Call([0, '']) threading.Thread(target=t).start() def 退出(self): diff --git "a/librian/\351\233\234\347\211\251/\346\247\213\345\273\272\347\224\250/Librian\351\235\242\346\235\277.cpp" "b/librian/\351\233\234\347\211\251/\346\247\213\345\273\272\347\224\250/Librian\351\235\242\346\235\277.cpp" index ddcaf65..6fdac2b 100644 --- "a/librian/\351\233\234\347\211\251/\346\247\213\345\273\272\347\224\250/Librian\351\235\242\346\235\277.cpp" +++ "b/librian/\351\233\234\347\211\251/\346\247\213\345\273\272\347\224\250/Librian\351\235\242\346\235\277.cpp" @@ -5,6 +5,6 @@ #include int main(int argc, char *argv[]) { - system("\"\"./python36/python\"\" -m librian.librian.librian_panel"); - system("pause"); + // system("\"\"./python36/python\"\" -m librian.librian.librian_panel"); + system("start \"Librian\" cmd /C \"\"./python36/python.exe\" -m librian.librian.librian_panel & pause\""); } \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index e9bece5..042a7d4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,5 @@ weasyprint>=50 PyYAML>=5.2 fire>=0.2.1 dulwich>=0.19.14 -AppKit==0.2.8 ; sys_platform == 'darwin' \ No newline at end of file +requests>=2.24.0 +AppKit>=0.2.8 ; sys_platform == 'darwin' \ No newline at end of file diff --git a/requirements_release.txt b/requirements_release.txt index 694e9d7..61ac2b6 100644 --- a/requirements_release.txt +++ b/requirements_release.txt @@ -8,4 +8,5 @@ Pillow==5.2.0 opencc==1.1.1 PyYAML==5.1 fire==0.2.1 -dulwich==0.19.14 \ No newline at end of file +dulwich==0.19.14 +requests==2.24.0 \ No newline at end of file