Continue switching from briefcase to poetry

This commit is contained in:
Micah Lee 2021-12-19 17:33:11 -08:00
parent 165ccf4627
commit 73c2f73aa9
12 changed files with 204 additions and 306 deletions

View file

@ -48,12 +48,10 @@ def main():
os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
)
if platform.system() == "Windows":
dist_path = os.path.join(
root_path, "src", "onionshare", "resources", "tor", "Tor"
)
dist_path = os.path.join(root_path, "onionshare", "resources", "tor", "Tor")
bin_filename = "meek-client.exe"
else:
dist_path = os.path.join(root_path, "src", "onionshare", "resources", "tor")
dist_path = os.path.join(root_path, "onionshare", "resources", "tor")
bin_filename = "meek-client"
bin_path = os.path.join(os.path.expanduser("~"), "go", "bin", bin_filename)

View file

@ -1,154 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Check translation lacked or disused.
Example:
in OnionShare directory
$ check_lacked_trans.py
de disused choose_file
de disused gui_starting_server
de lacked gui_canceled
de lacked gui_starting_server1
de lacked gui_starting_server2
de lacked gui_starting_server3
en disused choose_file
es disused choose_file
es disused gui_starting_server
...
1. search `{{strings.translation_key}}` and `strings._('translation_key')`
from .py or .html files.
2. load translation key from locale/*.json.
3. compare these.
"""
import argparse
import re
import os
import codecs
import json
import 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",
)
return p
def files_in(*dirs):
dir = os.path.join(*dirs)
files = os.listdir(dir)
return [os.path.join(dir, f) for f in files]
def main():
parser = arg_parser()
args = parser.parse_args()
dir = args.onionshare_dir
src = (
files_in(dir, "onionshare_gui")
+ files_in(dir, "onionshare_gui/tab")
+ files_in(dir, "onionshare_gui/tab/mode")
+ files_in(dir, "onionshare_gui/tab/mode/chat_mode")
+ files_in(dir, "onionshare_gui/tab/mode/receive_mode")
+ files_in(dir, "onionshare_gui/tab/mode/share_mode")
+ files_in(dir, "onionshare_gui/tab/mode/website_mode")
+ files_in(dir, "install/scripts")
)
filenames = [p for p in src if p.endswith(".py")]
lang_code = args.lang_code
translate_keys = set()
for filename in filenames:
# load translate key from python source
with open(filename) as f:
src = f.read()
# find all the starting strings
start_substr = "strings._\("
starting_indices = [m.start() for m in re.finditer(start_substr, src)]
for starting_i in starting_indices:
# are we dealing with single quotes or double quotes?
quote = None
inc = 0
while True:
quote_i = starting_i + len("strings._(") + inc
if src[quote_i] == '"':
quote = '"'
break
if src[quote_i] == "'":
quote = "'"
break
inc += 1
# find the starting quote
starting_i = src.find(quote, starting_i)
if starting_i:
starting_i += 1
# find the ending quote
ending_i = src.find(quote, starting_i)
if ending_i:
key = src[starting_i:ending_i]
translate_keys.add(key)
if args.show_all_keys:
for k in sorted(translate_keys):
print(k)
sys.exit()
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)
]
for locale_file in locale_files:
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())
disused = locale_keys - translate_keys
lacked = translate_keys - locale_keys
locale, ext = os.path.splitext(os.path.basename(locale_file))
for k in sorted(disused):
print(locale, "disused", k)
for k in sorted(lacked):
print(locale, "lacked", k)
if __name__ == "__main__":
main()

View file

@ -1,3 +0,0 @@
cd src
python -c "import onionshare; onionshare.main()" %*
cd ..

View file

@ -1,9 +0,0 @@
#!/bin/bash
# Run OnionShare desktop, allowing you to use command-line arguments
SCRIPTS_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )
cd "$SCRIPTS_DIR"
cd ../src
python -c "import onionshare; onionshare.main()" $@

View file

@ -47,7 +47,7 @@ def main():
)
working_path = os.path.join(root_path, "build", "tor")
tarball_path = os.path.join(working_path, tarball_filename)
dist_path = os.path.join(root_path, "src", "onionshare", "resources", "tor")
dist_path = os.path.join(root_path, "onionshare", "resources", "tor")
# Make sure dirs exist
if not os.path.exists(working_path):

View file

@ -51,7 +51,7 @@ def main():
"/Volumes", "Tor Browser", "Tor Browser.app", "Contents"
)
dmg_path = os.path.join(working_path, dmg_filename)
dist_path = os.path.join(root_path, "src", "onionshare", "resources", "tor")
dist_path = os.path.join(root_path, "onionshare", "resources", "tor")
if not os.path.exists(dist_path):
os.makedirs(dist_path, exist_ok=True)

View file

@ -46,7 +46,7 @@ def main():
)
working_path = os.path.join(root_path, "build", "tor")
exe_path = os.path.join(working_path, exe_filename)
dist_path = os.path.join(root_path, "src", "onionshare", "resources", "tor")
dist_path = os.path.join(root_path, "onionshare", "resources", "tor")
# Make sure the working folder exists
if not os.path.exists(working_path):

View file

@ -1,45 +0,0 @@
#!/usr/bin/env python3
"""
This script builds the CLI python wheel, copies it to the desktop folder,
and installs it in the virtual environment.
"""
import inspect
import os
import glob
import subprocess
import shutil
def main():
# Build paths
root_path = os.path.dirname(
os.path.dirname(
os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
)
)
cli_path = os.path.join(root_path, "cli")
desktop_path = os.path.join(root_path, "desktop")
# Delete old wheels
for filename in glob.glob(os.path.join(cli_path, "dist", "*.whl")):
os.remove(filename)
# Build new wheel
subprocess.call(["poetry", "install"], cwd=cli_path)
subprocess.call(["poetry", "build"], cwd=cli_path)
wheel_filename = glob.glob(os.path.join(cli_path, "dist", "*.whl"))[0]
wheel_basename = os.path.basename(wheel_filename)
shutil.copyfile(
wheel_filename,
os.path.join(desktop_path, wheel_basename),
)
# Reinstall the new wheel
subprocess.call(["pip", "uninstall", "onionshare-cli", "-y"])
subprocess.call(["pip", "install", os.path.join(desktop_path, wheel_basename)])
subprocess.call(["pip", "install", "typing-extensions"])
if __name__ == "__main__":
main()