mirror of
https://github.com/onionshare/onionshare.git
synced 2025-05-02 22:45:03 -04:00
Format all code using black
This commit is contained in:
parent
8010b279e7
commit
88e151d414
87 changed files with 4293 additions and 2374 deletions
|
@ -33,12 +33,25 @@ import fileinput, argparse, re, os, codecs, json, sys
|
|||
def arg_parser():
|
||||
desc = __doc__.strip().splitlines()[0]
|
||||
p = argparse.ArgumentParser(description=desc)
|
||||
p.add_argument('-d', default='.', help='onionshare directory',
|
||||
metavar='ONIONSHARE_DIR', dest='onionshare_dir')
|
||||
p.add_argument('--show-all-keys', action='store_true',
|
||||
help='show translation key in source and exit'),
|
||||
p.add_argument('-l', default='all', help='language code (default: all)',
|
||||
metavar='LANG_CODE', dest='lang_code')
|
||||
p.add_argument(
|
||||
"-d",
|
||||
default=".",
|
||||
help="onionshare directory",
|
||||
metavar="ONIONSHARE_DIR",
|
||||
dest="onionshare_dir",
|
||||
)
|
||||
p.add_argument(
|
||||
"--show-all-keys",
|
||||
action="store_true",
|
||||
help="show translation key in source and exit",
|
||||
),
|
||||
p.add_argument(
|
||||
"-l",
|
||||
default="all",
|
||||
help="language code (default: all)",
|
||||
metavar="LANG_CODE",
|
||||
dest="lang_code",
|
||||
)
|
||||
return p
|
||||
|
||||
|
||||
|
@ -54,27 +67,29 @@ def main():
|
|||
|
||||
dir = args.onionshare_dir
|
||||
|
||||
src = files_in(dir, 'onionshare') + \
|
||||
files_in(dir, 'onionshare_gui') + \
|
||||
files_in(dir, 'onionshare_gui/mode') + \
|
||||
files_in(dir, 'onionshare_gui/mode/share_mode') + \
|
||||
files_in(dir, 'onionshare_gui/mode/receive_mode') + \
|
||||
files_in(dir, 'onionshare_gui/mode/website_mode') + \
|
||||
files_in(dir, 'install/scripts') + \
|
||||
files_in(dir, 'tests')
|
||||
pysrc = [p for p in src if p.endswith('.py')]
|
||||
src = (
|
||||
files_in(dir, "onionshare")
|
||||
+ files_in(dir, "onionshare_gui")
|
||||
+ files_in(dir, "onionshare_gui/mode")
|
||||
+ files_in(dir, "onionshare_gui/mode/share_mode")
|
||||
+ files_in(dir, "onionshare_gui/mode/receive_mode")
|
||||
+ files_in(dir, "onionshare_gui/mode/website_mode")
|
||||
+ files_in(dir, "install/scripts")
|
||||
+ files_in(dir, "tests")
|
||||
)
|
||||
pysrc = [p for p in src if p.endswith(".py")]
|
||||
|
||||
lang_code = args.lang_code
|
||||
|
||||
translate_keys = set()
|
||||
# load translate key from python source
|
||||
for line in fileinput.input(pysrc, openhook=fileinput.hook_encoded('utf-8')):
|
||||
for line in fileinput.input(pysrc, openhook=fileinput.hook_encoded("utf-8")):
|
||||
# search `strings._('translate_key')`
|
||||
# `strings._('translate_key', True)`
|
||||
m = re.findall(r'strings\._\((.*?)\)', line)
|
||||
m = re.findall(r"strings\._\((.*?)\)", line)
|
||||
if m:
|
||||
for match in m:
|
||||
key = match.split(',')[0].strip('''"' ''')
|
||||
key = match.split(",")[0].strip(""""' """)
|
||||
translate_keys.add(key)
|
||||
|
||||
if args.show_all_keys:
|
||||
|
@ -82,12 +97,16 @@ def main():
|
|||
print(k)
|
||||
sys.exit()
|
||||
|
||||
if lang_code == 'all':
|
||||
locale_files = [f for f in files_in(dir, 'share/locale') if f.endswith('.json')]
|
||||
if lang_code == "all":
|
||||
locale_files = [f for f in files_in(dir, "share/locale") if f.endswith(".json")]
|
||||
else:
|
||||
locale_files = [f for f in files_in(dir, 'share/locale') if f.endswith('%s.json' % lang_code)]
|
||||
locale_files = [
|
||||
f
|
||||
for f in files_in(dir, "share/locale")
|
||||
if f.endswith("%s.json" % lang_code)
|
||||
]
|
||||
for locale_file in locale_files:
|
||||
with codecs.open(locale_file, 'r', encoding='utf-8') as f:
|
||||
with codecs.open(locale_file, "r", encoding="utf-8") as f:
|
||||
trans = json.load(f)
|
||||
# trans -> {"key1": "translate-text1", "key2": "translate-text2", ...}
|
||||
locale_keys = set(trans.keys())
|
||||
|
@ -97,11 +116,11 @@ def main():
|
|||
|
||||
locale, ext = os.path.splitext(os.path.basename(locale_file))
|
||||
for k in sorted(disused):
|
||||
print(locale, 'disused', k)
|
||||
print(locale, "disused", k)
|
||||
|
||||
for k in sorted(lacked):
|
||||
print(locale, 'lacked', k)
|
||||
print(locale, "lacked", k)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue