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