Skip to content

Commit 0abd050

Browse files
committed
reformat code, refactor some code, fix bunch of typos, remove duplicated lines in translations
1 parent 0c87137 commit 0abd050

File tree

5 files changed

+93
-196
lines changed

5 files changed

+93
-196
lines changed

init.py

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
from settings import BASE_FOLDER, USE_PROXY, PROXIES, VERSION_INFO_OVERRIDE, force_version_info, VERSION_INFO_OVERRIDE_BETA, force_version_info_beta
21
import os
32
import re
43
import shutil
5-
import requests
64
from zipfile import ZipFile
5+
6+
import requests
77
from 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
913
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
1014

1115
CLIENT_FOLDER = BASE_FOLDER + 'trilium-linux-x64'
@@ -17,11 +21,11 @@
1721
CMD_STOP_SERVICE = """pkill -9 trilium"""
1822

1923
# 是否从GitHub下载文件
20-
# whethere download files from GitHub
24+
# whether download files from GitHub
2125
DO_DOWNLOAD = True
2226

2327
# 是否删除临时文件
24-
# whethere delete template files
28+
# whether delete template files
2529
# DO_DELETE = False
2630
DO_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

6367
def 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

130118
def 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)

make_release.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
from settings import DEBUG, PATCH_FOLDER, LANG, TRANS_RELEASE_FOLDER, USE_PROXY, PROXIES, VERSION_INFO_OVERRIDE, force_version_info_full, VERSION_INFO_OVERRIDE_BETA, force_version_info_full_beta
21
import os
32
import re
4-
import shutil
3+
54
import requests
6-
from zipfile import ZipFile
75
from requests.packages.urllib3.exceptions import InsecureRequestWarning
8-
# disable warning if use proxy
6+
7+
from settings import DEBUG, PATCH_FOLDER, LANG, TRANS_RELEASE_FOLDER, USE_PROXY, PROXIES, VERSION_INFO_OVERRIDE, \
8+
force_version_info_full, VERSION_INFO_OVERRIDE_BETA, force_version_info_full_beta
9+
10+
# disable warning if we use proxy
911
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
1012

1113
COMPRESS_TOOL = '7z'
@@ -18,13 +20,15 @@
1820

1921

2022
# 是否从GitHub下载文件
21-
# whethere download files from GitHub
23+
# whether download files from GitHub
2224
DO_DOWNLOAD = True
2325
# DO_DOWNLOAD = False
2426

2527
# 是否删除临时文件
26-
# whethere delete template files
28+
# whether delete template files
2729
DO_DELETE = True
30+
31+
2832
# DO_DELETE = False
2933

3034

@@ -33,7 +37,7 @@ def requests_get(url):
3337
try:
3438
ret = requests.get(url, proxies=PROXIES, verify=not USE_PROXY)
3539
except Exception as e:
36-
print('If github is not avaliable, you can set USE_PROXY to True and set PROXIES.')
40+
print('If github is not available, you can set USE_PROXY to True and set PROXIES.')
3741
print('Exception', e)
3842
return ret
3943

@@ -44,11 +48,10 @@ def get_latest_version():
4448
url = f'https://api.github.com/repos/{REPO_NAME}/releases/latest'
4549
print(url)
4650
res = requests_get(url)
47-
version_info = {}
51+
version_info = {'name': res.json()['name']}
4852

4953
# zipball_url 就是源码
5054
# version_info['zipball_url'] = res.json()['zipball_url']
51-
version_info['name'] = res.json()['name']
5255

5356
patterns = {
5457
'linux': r'trilium-linux-x64-[0-9\.]+.tar.xz',
@@ -70,12 +73,11 @@ def get_latest_version():
7073
return version_info
7174

7275

73-
def download_latest(url, file_name=None):
74-
"""download latest release"""
75-
print('download latest tarball')
76+
def download_file(url, file_name=None):
77+
"""download file"""
78+
print('download file')
7679
if not file_name:
7780
file_name = url.split('/')[-1]
78-
7981
print('downloading ...')
8082
if DO_DOWNLOAD:
8183
with requests.get(url, proxies=PROXIES, verify=False, stream=True) as r:
@@ -93,7 +95,7 @@ def download_releases(releases):
9395
if package_type != 'linux':
9496
continue
9597
release = releases[package_type]
96-
download_latest(release['url'], TRANS_RELEASE_FOLDER + release['name'])
98+
download_file(release['url'], TRANS_RELEASE_FOLDER + release['name'])
9799

98100

99101
def decompress_package(file_name):
@@ -120,7 +122,6 @@ def decompress_package(file_name):
120122

121123

122124
def patch_linux(file_name):
123-
124125
if not file_name.endswith('.tar.xz'):
125126
print('linux客户端文件名有问题')
126127
print('linux client wrong file name')
@@ -175,7 +176,6 @@ def patch_linux(file_name):
175176

176177

177178
def patch_linux_server(file_name):
178-
179179
if not file_name.endswith('.tar.xz'):
180180
print('linux server 文件名有问题')
181181
print('linux server wrong file name')
@@ -212,7 +212,6 @@ def patch_linux_server(file_name):
212212

213213

214214
def patch_windows(file_name):
215-
216215
if not file_name.endswith('.zip'):
217216
print('windows 文件名有问题')
218217
exit()
@@ -262,7 +261,6 @@ def patch_windows(file_name):
262261

263262

264263
def patch_mac(file_name):
265-
266264
if not file_name.endswith('.zip'):
267265
print('windows 文件名有问题')
268266
exit()
@@ -316,7 +314,7 @@ def patch_mac(file_name):
316314

317315
if __name__ == '__main__':
318316

319-
a = input(f'Delete folder {TRANS_RELEASE_FOLDER}, contunue?(y)')
317+
a = input(f'Delete folder {TRANS_RELEASE_FOLDER}, continue?(y)')
320318
if a not in ['y', ]:
321319
exit()
322320

settings.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import platform
99

10-
# DEBUG = False
1110
DEBUG = False
11+
# DEBUG = False
1212

1313
if platform.system() == 'Linux':
1414
# BASE_PATH 是工作目录
@@ -28,7 +28,6 @@
2828
PATCH_FOLDER = '/Users/nate/soft/trilium/trilium-trans-patch/'
2929
TRANS_RELEASE_FOLDER = '/Users/nate/soft/trilium/trilium-trans-release/'
3030

31-
3231
# release文件名后缀
3332
# release file name suffix
3433
LANG = 'cn'
@@ -61,10 +60,14 @@
6160
force_version_info_full = {
6261
'name': 'v0.47.8 release',
6362
'releases': {
64-
'linux': {'name': 'trilium-linux-x64-0.47.8.tar.xz', 'url': 'https://github.com/zadam/trilium/releases/download/v0.47.8/trilium-linux-x64-0.47.8.tar.xz'},
65-
'linux-server': {'name': 'trilium-linux-x64-server-0.47.8.tar.xz', 'url': 'https://github.com/zadam/trilium/releases/download/v0.47.8/trilium-linux-x64-server-0.47.8.tar.xz'},
66-
'mac': {'name': 'trilium-mac-x64-0.47.8.zip', 'url': 'https://github.com/zadam/trilium/releases/download/v0.47.8/trilium-mac-x64-0.47.8.zip'},
67-
'windows': {'name': 'trilium-windows-x64-0.47.8.zip', 'url': 'https://github.com/zadam/trilium/releases/download/v0.47.8/trilium-windows-x64-0.47.8.zip'}
63+
'linux': {'name': 'trilium-linux-x64-0.47.8.tar.xz',
64+
'url': 'https://github.com/zadam/trilium/releases/download/v0.47.8/trilium-linux-x64-0.47.8.tar.xz'},
65+
'linux-server': {'name': 'trilium-linux-x64-server-0.47.8.tar.xz',
66+
'url': 'https://github.com/zadam/trilium/releases/download/v0.47.8/trilium-linux-x64-server-0.47.8.tar.xz'},
67+
'mac': {'name': 'trilium-mac-x64-0.47.8.zip',
68+
'url': 'https://github.com/zadam/trilium/releases/download/v0.47.8/trilium-mac-x64-0.47.8.zip'},
69+
'windows': {'name': 'trilium-windows-x64-0.47.8.zip',
70+
'url': 'https://github.com/zadam/trilium/releases/download/v0.47.8/trilium-windows-x64-0.47.8.zip'}
6871
}
6972
}
7073

@@ -80,9 +83,13 @@
8083
force_version_info_full_beta = {
8184
'name': 'v0.49.1-beta release',
8285
'releases': {
83-
'linux': {'name': 'trilium-linux-x64-v0.49.1-beta.tar.xz', 'url': 'https://github.com/zadam/trilium/releases/download/v0.49.1-beta/trilium-linux-x64-0.49.1-beta.tar.xz'},
84-
'linux-server': {'name': 'trilium-linux-x64-server-v0.49.1-beta.tar.xz', 'url': 'https://github.com/zadam/trilium/releases/download/v0.49.1-beta/trilium-linux-x64-server-0.49.1-beta.tar.xz'},
85-
'mac': {'name': 'trilium-mac-x64-v0.49.1-beta.zip', 'url': 'https://github.com/zadam/trilium/releases/download/v0.49.1-beta/trilium-mac-x64-0.49.1-beta.zip'},
86-
'windows': {'name': 'trilium-windows-x64-v0.49.1-beta.zip', 'url': 'https://github.com/zadam/trilium/releases/download/v0.49.1-beta/trilium-windows-x64-0.49.1-beta.zip'}
86+
'linux': {'name': 'trilium-linux-x64-v0.49.1-beta.tar.xz',
87+
'url': 'https://github.com/zadam/trilium/releases/download/v0.49.1-beta/trilium-linux-x64-0.49.1-beta.tar.xz'},
88+
'linux-server': {'name': 'trilium-linux-x64-server-v0.49.1-beta.tar.xz',
89+
'url': 'https://github.com/zadam/trilium/releases/download/v0.49.1-beta/trilium-linux-x64-server-0.49.1-beta.tar.xz'},
90+
'mac': {'name': 'trilium-mac-x64-v0.49.1-beta.zip',
91+
'url': 'https://github.com/zadam/trilium/releases/download/v0.49.1-beta/trilium-mac-x64-0.49.1-beta.zip'},
92+
'windows': {'name': 'trilium-windows-x64-v0.49.1-beta.zip',
93+
'url': 'https://github.com/zadam/trilium/releases/download/v0.49.1-beta/trilium-windows-x64-0.49.1-beta.zip'}
8794
}
8895
}

0 commit comments

Comments
 (0)