diff --git a/.github/workflows/helper/pre-commit/check_translation_tag.py b/.github/workflows/helper/pre-commit/check_translation_tag.py
index 34705f74d..f3d4457e2 100755
--- a/.github/workflows/helper/pre-commit/check_translation_tag.py
+++ b/.github/workflows/helper/pre-commit/check_translation_tag.py
@@ -30,6 +30,7 @@ from typing import Optional, Sequence
import argparse
import re
+
def main(argv: Optional[Sequence[str]] = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*', help='Filenames to check')
@@ -47,12 +48,12 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
for line in file:
if (match := regex.match(line)) is not None:
error_buffer += str(f"Defect file: \"{filename}\"\n"
- f"Line: {line_counter}\n"
- f"Column span: {match.span()}\n"
- f"Part: \"{match.group()}\"\n\n")
+ f"Line: {line_counter}\n"
+ f"Column span: {match.span()}\n"
+ f"Part: \"{match.group()}\"\n\n")
line_counter += 1
- except UnicodeDecodeError as error:
+ except UnicodeDecodeError:
# not a text file, skip
continue
@@ -64,5 +65,6 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
return 0
+
if __name__ == '__main__':
exit(main())
diff --git a/dist/windows/gather_qt_translations.py b/dist/windows/gather_qt_translations.py
index d1ff44499..cfa212c8c 100644
--- a/dist/windows/gather_qt_translations.py
+++ b/dist/windows/gather_qt_translations.py
@@ -7,9 +7,11 @@ import shutil
import sys
from typing import List
+
def isNotStub(path: str) -> bool:
return (os.path.getsize(path) >= (10 * 1024))
+
def main() -> int:
parser = argparse.ArgumentParser(description='Gather valid Qt translations for NSIS packaging.')
parser.add_argument("qt_translations_folder", help="Qt's translations folder")
@@ -27,5 +29,6 @@ def main() -> int:
return 0
+
if __name__ == '__main__':
sys.exit(main())
diff --git a/src/searchengine/nova3/novaprinter.py b/src/searchengine/nova3/novaprinter.py
index 09250dc85..fdd423ba0 100644
--- a/src/searchengine/nova3/novaprinter.py
+++ b/src/searchengine/nova3/novaprinter.py
@@ -1,4 +1,4 @@
-#VERSION: 1.46
+#VERSION: 1.47
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@@ -45,13 +45,13 @@ def anySizeToBytes(size_string):
# separate integer from unit
try:
size, unit = size_string.split()
- except:
+ except Exception:
try:
size = size_string.strip()
unit = ''.join([c for c in size if c.isalpha()])
if len(unit) > 0:
size = size[:-len(unit)]
- except:
+ except Exception:
return -1
if len(size) == 0:
return -1
diff --git a/src/update_qrc_files.py b/src/update_qrc_files.py
index 1767bc962..aa59fb7d4 100755
--- a/src/update_qrc_files.py
+++ b/src/update_qrc_files.py
@@ -36,8 +36,8 @@ output = '''
'''
for language in languages_list:
- output += ' %s'%('lang'+os.sep+language)
- output += os.linesep
+ output += ' %s' % ('lang' + os.sep + language)
+ output += os.linesep
output += '''
'''
lang_file = open('lang.qrc', 'w')
@@ -48,41 +48,41 @@ lang_file.close()
os.chdir('gui/searchengine')
search_list = []
for root, dirs, files in os.walk('nova3'):
- for file in files:
- if file.startswith("__"):
- continue
- if splitext(file)[-1] in ('.py', '.png'):
- search_list.append(join(root, file))
+ for file in files:
+ if file.startswith("__"):
+ continue
+ if splitext(file)[-1] in ('.py', '.png'):
+ search_list.append(join(root, file))
output = '''
'''
for file in search_list:
- output += ' %s'%(file)
- output += os.linesep
+ output += ' %s' % (file)
+ output += os.linesep
output += '''
'''
search_file = open('search.qrc', 'w')
search_file.write(output)
search_file.close()
-os.chdir('../..');
+os.chdir('../..')
# update icons files directory
icons_list = []
for root, dirs, files in os.walk('icons'):
- if 'skin_unused' in dirs:
- dirs.remove('skin_unused')
- for file in files:
- if splitext(file)[-1] in ('.png', '.jpg', '.gif'):
- icons_list.append(join(root, file))
+ if 'skin_unused' in dirs:
+ dirs.remove('skin_unused')
+ for file in files:
+ if splitext(file)[-1] in ('.png', '.jpg', '.gif'):
+ icons_list.append(join(root, file))
output = '''
'''
for icon in icons_list:
- output += ' %s'%(icon)
- output += os.linesep
+ output += ' %s' % (icon)
+ output += os.linesep
output += '''
'''
icons_file = open('icons.qrc', 'w')
diff --git a/src/webui/www/split_merge_json.py b/src/webui/www/split_merge_json.py
index 4fb27742a..17cd12539 100755
--- a/src/webui/www/split_merge_json.py
+++ b/src/webui/www/split_merge_json.py
@@ -16,6 +16,7 @@ import os
from pathlib import PurePath
import sys
+
def updateJson(json_file: str, source: dict[str, str]) -> None:
trimmed_path: str = json_file
path_parts = PurePath(json_file).parts
@@ -42,6 +43,7 @@ def updateJson(json_file: str, source: dict[str, str]) -> None:
file.write("\n")
file.truncate()
+
def splitJson(transifex_dir: str, json_public_dir: str, json_private_dir: str) -> None:
locales: list[str] = glob.glob("*.json", root_dir=transifex_dir)
locales = [x for x in locales if x != "en.json"]
@@ -65,6 +67,7 @@ def splitJson(transifex_dir: str, json_public_dir: str, json_private_dir: str) -
updateJson(public_file, transifex_json)
updateJson(private_file, transifex_json)
+
def mergeJson(transifex_dir: str, json_public_dir: str, json_private_dir: str) -> None:
transifex_en_file: str = f"{transifex_dir}/en.json"
public_en_file: str = f"{json_public_dir}/en.json"
@@ -92,6 +95,7 @@ def mergeJson(transifex_dir: str, json_public_dir: str, json_private_dir: str) -
json.dump(transifex_en_json, file, ensure_ascii=False, indent=2, sort_keys=True)
file.write("\n")
+
def main() -> int:
script_path: str = os.path.dirname(os.path.realpath(__file__))
transifex_dir: str = f"{script_path}/transifex"
@@ -124,5 +128,6 @@ def main() -> int:
return 0
+
if __name__ == '__main__':
sys.exit(main())
diff --git a/src/webui/www/translations_qt2i18next.py b/src/webui/www/translations_qt2i18next.py
index c685bd8ab..4c0f4a856 100755
--- a/src/webui/www/translations_qt2i18next.py
+++ b/src/webui/www/translations_qt2i18next.py
@@ -14,6 +14,7 @@ import os
import sys
import xml.etree.ElementTree as ET
+
def getTsStrings(ts_file: str, key: str) -> list[str]:
tr_strings: list[str] = []
tree = ET.parse(ts_file)
@@ -33,6 +34,7 @@ def getTsStrings(ts_file: str, key: str) -> list[str]:
return tr_strings
+
def migrate2Json(ts_dir: str, json_dir: str, locale: str) -> None:
ts_file: str = f"{ts_dir}/webui_{locale}.ts"
js_file: str = f"{json_dir}/{locale}.json"
@@ -71,6 +73,7 @@ def migrate2Json(ts_dir: str, json_dir: str, locale: str) -> None:
print("\tFinished.")
+
def main() -> int:
script_path: str = os.path.dirname(os.path.realpath(__file__))
ts_dir: str = f"{script_path}/translations"
@@ -97,5 +100,6 @@ def main() -> int:
return 0
+
if __name__ == '__main__':
sys.exit(main())
diff --git a/src/webui/www/tstool.py b/src/webui/www/tstool.py
index 65f838765..2166815dc 100755
--- a/src/webui/www/tstool.py
+++ b/src/webui/www/tstool.py
@@ -41,9 +41,10 @@ no_obsolete = False
www_folder = "."
ts_folder = os.path.join(www_folder, "translations")
+
def parseSource(filename, sources):
print("Parsing %s..." % (os.path.normpath(filename)))
- with open(filename, encoding = 'utf-8', mode = 'r') as file:
+ with open(filename, encoding='utf-8', mode='r') as file:
regex = re.compile(
r"QBT_TR\((([^\)]|\)(?!QBT_TR))+)\)QBT_TR\[CONTEXT=([a-zA-Z_][a-zA-Z0-9_]*)\]")
for match in regex.finditer(file.read()):
@@ -54,11 +55,12 @@ def parseSource(filename, sources):
sources[context] = set()
sources[context].add(string)
+
def processTranslation(filename, sources):
print('Processing %s...' % (os.path.normpath(filename)))
try:
- tree = ET.ElementTree(file = filename)
+ tree = ET.ElementTree(file=filename)
except Exception:
print('\tFailed to parse %s!' % (os.path.normpath(filename)))
return
@@ -82,7 +84,7 @@ def processTranslation(filename, sources):
trtype = translation.attrib.get('type')
if (trtype == 'obsolete') or (trtype == 'vanished'):
- del translation.attrib['type'] # i.e. finished
+ del translation.attrib['type'] # i.e. finished
else:
if no_obsolete or (translation.attrib.get('type', '') == 'unfinished'):
context.remove(message)
@@ -117,13 +119,15 @@ def processTranslation(filename, sources):
context.tail = '\n'
context.find('./name').tail = '\n' + indent
messages = context.findall('./message')
- if len(messages) == 0: continue
+ if len(messages) == 0:
+ continue
for message in messages:
message.text = '\n' + (indent * 2)
message.tail = '\n' + indent
elems = message.findall('./')
- if len(elems) == 0: continue
+ if len(elems) == 0:
+ continue
for elem in elems:
elem.tail = '\n' + (indent * 2)
@@ -131,24 +135,25 @@ def processTranslation(filename, sources):
messages[-1:][0].tail = '\n'
try:
- with open(filename, mode = 'wb') as file:
+ with open(filename, mode='wb') as file:
file.write(b'\n'
b'\n')
- tree.write(file, encoding = 'utf-8')
+ tree.write(file, encoding='utf-8')
except Exception:
print('\tFailed to write %s!' % (os.path.normpath(filename)))
+
argp = argparse.ArgumentParser(
- prog = 'tstool.py', description = 'Update qBittorrent WebUI translation files.')
-argp.add_argument('--no-obsolete', dest = 'no_obsolete', action = 'store_true',
- default = no_obsolete,
- help = 'remove obsolete messages (default: mark them as obsolete)')
-argp.add_argument('--www-folder', dest = 'www_folder', action = 'store',
- default = www_folder,
- help = 'folder with WebUI source files (default: "%s")' % (www_folder))
-argp.add_argument('--ts-folder', dest = 'ts_folder', action = 'store',
- default = ts_folder,
- help = 'folder with WebUI translation files (default: "%s")' % (ts_folder))
+ prog='tstool.py', description='Update qBittorrent WebUI translation files.')
+argp.add_argument('--no-obsolete', dest='no_obsolete', action='store_true',
+ default=no_obsolete,
+ help='remove obsolete messages (default: mark them as obsolete)')
+argp.add_argument('--www-folder', dest='www_folder', action='store',
+ default=www_folder,
+ help='folder with WebUI source files (default: "%s")' % (www_folder))
+argp.add_argument('--ts-folder', dest='ts_folder', action='store',
+ default=ts_folder,
+ help='folder with WebUI translation files (default: "%s")' % (ts_folder))
args = argp.parse_args()
no_obsolete = args.no_obsolete
@@ -174,8 +179,7 @@ print("")
print("Processing translation files...")
for entry in os.scandir(ts_folder):
- if (entry.is_file() and entry.name.startswith('webui_')
- and entry.name.endswith(".ts")):
+ if (entry.is_file() and entry.name.startswith('webui_') and entry.name.endswith(".ts")):
processTranslation(entry.path, copy.deepcopy(source_ts))
print("Done!")