Skip to content

Commit

Permalink
fixed issues with tesseract loading
Browse files Browse the repository at this point in the history
  • Loading branch information
chpoit committed Jul 5, 2022
1 parent ccdf9b4 commit 4053daf
Show file tree
Hide file tree
Showing 16 changed files with 198 additions and 64 deletions.
6 changes: 5 additions & 1 deletion data/translations/eng.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,9 @@
"new-skill-correction-update": "New automatic skill corrections were submitted (You: {}, New: {}), do you download them?",
"wiki-button": "Open MHR Set Searcher",
"wiki-clipboard": "Copy URL",
"wiki-attempt": "Attempting to open the website..."
"wiki-attempt": "Attempting to open the website...",
"tess-wait-5-retry": "Waiting 5 seconds before trying to download the language pack again...",
"tess-url-error": "A URL error occured, this might be a DNS issue... retrying",
"tess-cannot-download": "Unable to download Tesseract language pack.",
"tess-not-found": "Tesseract was not found. Please install it, and if it is installed, pass it as a command line option at least once. If you have done both and it still isn't found, please open an issue on Github."
}
6 changes: 5 additions & 1 deletion data/translations/fra.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,9 @@
"new-skill-correction-update": "Des nouvelles corrections automatiques ont été soumises, (Locale: {}, Nouvelle: {}), voulez-vous les télécharger?",
"wiki-button": "Visiter le MHR Set Searcher",
"wiki-clipboard": "Copier l'URL",
"wiki-attempt": "Tentative d'ouverture du site web..."
"wiki-attempt": "Tentative d'ouverture du site web...",
"tess-wait-5-retry":"Pause de 5 secondes avant de ré-essayer le téléchargement du language pack...",
"tess-url-error":"Une erreur d'URL s'est produite, potentiellement causé par une erreur DNS...",
"tess-cannot-download":"Impossible de télécharger le language pack Tesseract.",
"tess-not-found": "Tesseract n'a pas été trouv. Veuillez l'installer, s'il est installé, passez le à travers le command line au moins une fois. Si cette erreur continue d'apparaître, veuillez créer une issue sur Github.."
}
6 changes: 3 additions & 3 deletions data/versions.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"app": "1.6.0",
"app": "1.6.1",
"skills": "3.1.1",
"languages": {
"eng": "1.1",
"eng": "1.2",
"jpn": 0,
"fra": "1.1",
"fra": "1.2",
"ita": 0,
"deu": 0,
"spa": 0,
Expand Down
1 change: 1 addition & 0 deletions scripts/build_skill_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def _printem(x):
os.path.join(sp, "skill_mappings.en.json"), "w", encoding="utf-8"
) as skill_map_fp:
json.dump(skills_reverse, skill_map_fp, ensure_ascii=False)

with open(
os.path.join(sp, "skill_mappings.alt.json"), "w", encoding="utf-8"
) as skill_map_fp:
Expand Down
2 changes: 1 addition & 1 deletion scripts/check_missing_skills.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

all_skills = set()
with open(os.path.join("data", "skill_list.txt")) as slf:
with open(os.path.join("data", "skill_list.txt"), encoding="utf-8") as slf:
for line in slf.readlines():
skill_name = line.strip()
all_skills.add(skill_name)
Expand Down
19 changes: 11 additions & 8 deletions scripts/compare_charms.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import os
import sys
import json
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(
os.path.join(os.getcwd(), os.path.expanduser(__file__))))

PACKAGE_PARENT = ".."
SCRIPT_DIR = os.path.dirname(
os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__)))
)
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
from src.Charm import Charm

f1 = "charms tesseract.json"
f2 = "charms.json"

with open(f1) as f:
with open(f1, encoding="utf-8") as f:
c1 = set(map(Charm.from_dict, json.load(f)))

with open(f2) as f:
with open(f2, encoding="utf-8") as f:
c2 = set(map(Charm.from_dict, json.load(f)))

c1 = set(c1)
Expand All @@ -23,13 +25,14 @@

dif = c1.symmetric_difference(c2)

print("Diffs", len(dif))
print("Diffs", len(dif))

if len(dif) == 0:
exit()
a = b = 0
with open("missing_charms.json", "w", encoding="utf-8") as missing,\
open("made_up_charms.json", "w", encoding="utf-8") as made_up:
with open("missing_charms.json", "w", encoding="utf-8") as missing, open(
"made_up_charms.json", "w", encoding="utf-8"
) as made_up:
for i in dif:
if i not in c1:
a += 1
Expand Down
4 changes: 2 additions & 2 deletions scripts/update_ver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

print("Writing", new_version, "to file")

with open(os.path.join("data", "versions.json"), "r") as f:
with open(os.path.join("data", "versions.json"), "r", encoding="utf-8") as f:
versions = json.load(f)
versions["app"] = new_version
with open(os.path.join("data", "versions.json"), "w") as f:
with open(os.path.join("data", "versions.json"), "w", encoding="utf-8") as f:
json.dump(versions, f, indent=4)
45 changes: 33 additions & 12 deletions src/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
from .ui.MainWindow import MainWindow
from .translator import Translator
from .resources import (
default_lang,
get_language_code,
get_resource_path,
get_app_language,
save_app_language,
get_game_language,
save_game_language,
save_tesseract_location,
)
from .updater.updater_utils import (
ask_main_update,
Expand All @@ -36,7 +38,7 @@
import json

logging.basicConfig(
filename="app.log", filemode="w", format="%(name)s - %(levelname)s - %(message)s"
filename="app.log", filemode="w", format="%(name)s - %(levelname)s - %(message)s",level='INFO', force=True
)

logger = logging.getLogger(__name__)
Expand All @@ -45,7 +47,15 @@
def handle_exception(exception, value, traceback):
logger.error(f"An error occured {exception}, {value}, {str(traceback)}")
logger.exception(f"An error occured")
print("An error occured", exception)
print("An error occured", exception, str(traceback))


def reset_config():
config_path = get_resource_path("CONFIG")
if os.path.exists(config_path):
os.remove(config_path)

init_config(get_language_code(default_lang()), get_language_code(default_lang()))


def init_config(app_language_code, skill_language_code):
Expand All @@ -69,21 +79,30 @@ def init_config(app_language_code, skill_language_code):
)


def read_default_args(args):
if args.tess_dir is not None:
save_tesseract_location(args.tess_dir)

if args.app_language is not None:
app_language_code = get_language_code(args.app_language)
save_app_language(app_language_code)

if args.language is not None:
skill_language_code = get_language_code(args.language)
save_game_language(skill_language_code)


def main(args):
if args.license:
print_licenses()
sys.exit(0)

app_language_code = get_language_code(args.app_language)
skill_language_code = get_language_code(args.language)

init_config(app_language_code, skill_language_code)
if args.reset_config:
save_app_language(skill_language_code)
save_game_language(skill_language_code)
reset_config()

app_language_code = get_app_language()
skill_language_code = get_game_language()
init_config(app_language_code, skill_language_code)

if args.console:
run_in_console(args)
Expand All @@ -92,7 +111,7 @@ def main(args):
version_checker = VersionChecker()

language_versions = version_checker.get_language_versions()

for language_version in language_versions:
lang, code, local, remote = language_version
if local < remote:
Expand All @@ -104,7 +123,10 @@ def main(args):
pass

main_window, translator = create_main_window(
args, skill_language_code, list(map(lambda x: x[0], language_versions))
args,
skill_language_code,
app_language_code,
list(map(lambda x: x[0], language_versions)),
)

new_app_update = ask_main_update(version_checker, main_window, translator)
Expand All @@ -117,8 +139,7 @@ def main(args):
main_window.mainloop()


def create_main_window(args, skill_language_code, app_langs):
app_language_code = get_language_code(args.app_language)
def create_main_window(args, skill_language_code, app_language_code, app_langs):
translator = Translator(app_language_code)
new_window = MainWindow(translator, args, skill_language_code, app_langs)
new_window.report_callback_exception = handle_exception
Expand Down
18 changes: 14 additions & 4 deletions src/arg_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def build_args():
help="Changes the Input directory for videos",
default="inputs",
)

parser.add_argument(
"-f",
"--frames",
Expand All @@ -44,6 +45,15 @@ def build_args():
default="frames",
)

parser.add_argument(
"-t",
"--tesseract",
dest="tess_dir",
required=False,
help="When you want to pass a custom tesseract location. It is saved to the config",
default=None,
)

parser.add_argument(
"-c",
"--charm-json",
Expand All @@ -66,17 +76,17 @@ def build_args():
"--language",
dest="language",
required=False,
help="Sets the language of the switch recording. (only works for first launch)",
default="English",
help="Sets the language of the switch recording. It is saved to the config",
default=None,
)

parser.add_argument(
"-a",
"--app-language",
dest="app_language",
required=False,
help="Sets the language of the app. (only works for first launch)",
default="English",
help="Sets the language of the app. It is saved to the config",
default=None,
)

parser.add_argument(
Expand Down
4 changes: 2 additions & 2 deletions src/charm_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def keep_existing_and_update(x):
if charm.has_skills():
charms.append(charm)
else:
logger.warn(_("logger-skill-less").format(frame_loc))
logger.warning(_("logger-skill-less").format(frame_loc))
except Exception as e:
logger.error(_("logger-charm-error").format(frame_loc, e))
logger.exception("Traceback")
Expand Down Expand Up @@ -286,7 +286,7 @@ def save_duplicates(charms, mode="w"):
charm_dupes[charm] = []
charm_dupes[charm].append(frame_loc)

with open(dupe_file_name, mode) as dupe_file:
with open(dupe_file_name, mode, encoding="utf-8") as dupe_file:
for charm in filter(lambda x: len(charm_dupes[x]) > 1, charm_dupes):
locations = charm_dupes[charm]
dupe_file.write(f"{charm.to_dict()}\n")
Expand Down
20 changes: 20 additions & 0 deletions src/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ def get_english_skill_mapping_url(language="eng"):
url = f"https://raw.githubusercontent.com/chpoit/utsushis-charm/master/data/skills/skill_mappings.en.json"
return url

def get_wiki_url(skill_language_code):
if skill_language_code == "jpn":
return "https://mhrise.wiki-db.com/sim"
return "https://mhrise.wiki-db.com/sim/?hl=en"


def get_english_skill_mappping_location():
return os.path.join(get_resource_path("LOCAL_SKILLS"), "skill_mappings.en.json")
Expand Down Expand Up @@ -214,12 +219,27 @@ def save_game_language(app_language_code):
_write_config(config)


def get_tesseract_location():
config = _load_config()
if "tesseract-directory" in config:
return config["tesseract-directory"]
return None


def save_tesseract_location(location):
config = _load_config()
config["tesseract-directory"] = location
_write_config(config)


def reverse(dict_):
reversed = {}
for key in dict_:
reversed[dict_[key]] = key
return reversed

def default_lang():
return "English"

_local_root = os.getenv("LOCALAPPDATA") or HOME if WINDOWS else HOME
_local_dir_name = "utsushis-charm"
Expand Down
Loading

0 comments on commit 4053daf

Please sign in to comment.