1- from settings import BASE_FOLDER , USE_PROXY , PROXIES , VERSION_INFO_OVERRIDE , force_version_info , VERSION_INFO_OVERRIDE_BETA , force_version_info_beta
21import os
32import re
43import shutil
5- import requests
64from zipfile import ZipFile
5+
6+ import requests
77from requests .packages .urllib3 .exceptions import InsecureRequestWarning
8- # disable warning if use proxy
8+
9+ from settings import BASE_FOLDER , USE_PROXY , PROXIES , VERSION_INFO_OVERRIDE , force_version_info , \
10+ VERSION_INFO_OVERRIDE_BETA , force_version_info_beta
11+
12+ # disable warning if we use proxy
913requests .packages .urllib3 .disable_warnings (InsecureRequestWarning )
1014
1115CLIENT_FOLDER = BASE_FOLDER + 'trilium-linux-x64'
1721CMD_STOP_SERVICE = """pkill -9 trilium"""
1822
1923# 是否从GitHub下载文件
20- # whethere download files from GitHub
24+ # whether download files from GitHub
2125DO_DOWNLOAD = True
2226
2327# 是否删除临时文件
24- # whethere delete template files
28+ # whether delete template files
2529# DO_DELETE = False
2630DO_DELETE = True
2731
@@ -31,7 +35,7 @@ def requests_get(url):
3135 try :
3236 ret = requests .get (url , proxies = PROXIES , verify = not USE_PROXY )
3337 except Exception as e :
34- print ('If github is not avaliable , you can set USE_PROXY to True and set PROXIES to your proxy.' )
38+ print ('If github is not available , you can set USE_PROXY to True and set PROXIES to your proxy.' )
3539 print ('Exception' , e )
3640 return ret
3741
@@ -61,36 +65,20 @@ def get_latest_version():
6165
6266
6367def backup_old_service ():
64- BACKUP_SUFFIX = '_old'
65- backup_dir = CLIENT_FOLDER + BACKUP_SUFFIX
68+ backup_suffix = '_old'
69+ backup_dir = CLIENT_FOLDER + backup_suffix
6670 if os .path .exists (backup_dir ):
6771 shutil .rmtree (backup_dir )
6872 os .mkdir (backup_dir )
6973
7074 if os .path .exists (CLIENT_FOLDER ):
71- os .system (f'mv { CLIENT_FOLDER } { CLIENT_FOLDER } { BACKUP_SUFFIX } ' )
72- print (f'old version is moved to { CLIENT_FOLDER } { BACKUP_SUFFIX } ' )
73-
74-
75- def download_latest (url , file_name = None ):
76- """download latest release"""
77- print ('download latest tarball' )
78- if not file_name :
79- file_name = url .split ('/' )[- 1 ]
80-
81- print ('downloading ...' )
82- if DO_DOWNLOAD :
83- with requests .get (url , proxies = PROXIES , verify = False , stream = True ) as r :
84- r .raise_for_status ()
85- with open (file_name , 'wb' ) as f :
86- for chunk in r .iter_content (chunk_size = 8192 ):
87- f .write (chunk )
88- print (f'download complete, file saved as { file_name } ' )
89- return file_name
75+ os .system (f'mv { CLIENT_FOLDER } { CLIENT_FOLDER } { backup_suffix } ' )
76+ print (f'old version is moved to { CLIENT_FOLDER } { backup_suffix } ' )
9077
9178
92- def download_source (url , file_name = None ):
93- print ('download source' , url )
79+ def download_file (url , file_name = None ):
80+ """download file"""
81+ print ('download file' )
9482 if not file_name :
9583 file_name = url .split ('/' )[- 1 ]
9684 print ('downloading ...' )
@@ -109,7 +97,7 @@ def stop_service():
10997 os .system (CMD_STOP_SERVICE )
11098
11199
112- def clean_cahce ():
100+ def clean_cache ():
113101 os .system ('rm -rf ~/.config/Trilium Notes/Cache/' )
114102 os .system ('rm -rf ~/.config/Trilium Notes/Code Cache/' )
115103 os .system ('rm -rf ~/.config/Trilium Notes/GPUCache/' )
@@ -129,11 +117,10 @@ def decompress_package(file_name):
129117
130118def decompress_source_package (file_name ):
131119 if file_name .endswith ('.zip' ):
132- extracted_folder = ''
133120 with ZipFile (file_name , 'r' ) as zip :
134121 # printing all the contents of the zip file
135122 extracted_folder = zip .namelist ()[0 ].split ('/' )[0 ]
136- if extracted_folder :
123+ if extracted_folder :
137124 os .system (f'unzip -o { file_name } ' )
138125 os .system ('pwd' )
139126 if DO_DELETE :
@@ -164,18 +151,18 @@ def decompress_source_package(file_name):
164151
165152 # 翻译不生效可以尝试删除缓存
166153 # If the translation doesn't work, clean the cache files may help
167- clean_cahce ()
154+ clean_cache ()
168155 # backup_old_service()
169156
170157 # 下载release
171158 # get release file
172- file_name = download_latest (version_info ['browser_download_url' ])
159+ file_name = download_file (version_info ['browser_download_url' ])
173160 print (f'file_name { file_name } ' )
174161 decompress_package (file_name )
175162
176163 # 下载源码
177164 # get source code
178- file_name = download_source (version_info ['zipball_url' ], 'trilium-src.zip' )
165+ file_name = download_file (version_info ['zipball_url' ], 'trilium-src.zip' )
179166 file_name = 'trilium-src.zip'
180167 print (f'file_name { file_name } ' )
181168 decompress_source_package (file_name )
0 commit comments