Mentions légales du service

Skip to content
Snippets Groups Projects

Feature: can now provide only a substring for the --level command-line argument

Merged Florent Bouchez Tichadou requested to merge dev/flo/levelnamesubstring into main
3 files
+ 33
12
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 27
2
@@ -5,7 +5,7 @@
import importlib.util
from os import walk
from os.path import dirname, join
from os.path import dirname, join, relpath, isdir
from pathlib import Path
from typing import Optional
@@ -21,7 +21,7 @@ def find_levels(path: Optional[str] = None, categories: Optional[list] = None) -
:param path: The working directory.
:return: List of available levels
"""
path = path or f"{dirname(__file__)}/../../levels"
path = path or join(Config.ROOT_DIR, "levels")
levels = {}
if not categories:
@@ -57,6 +57,31 @@ def find_levels(path: Optional[str] = None, categories: Optional[list] = None) -
return levels
def find_one_level(name: str) -> str:
# lvld = name.rstrip('/')
reld = ""
if name.startswith("levels/"):
reld = "levels"
full_name = relpath(name, reld)
full_path = join(Config.ROOT_DIR, "levels", full_name)
if isdir(full_path):
return full_name
lvls = find_levels()
# otherwise, search for a match in all available levels
for lvl_grp in lvls:
for full_name, file in sorted(lvls[lvl_grp]):
if name in full_name:
return full_name
log.critical(f"Cannot find a level matching {name}")
exit(1)
def import_from_file(module_path: str, attribute: str):
"""
Import an attribute from a module (that is a python file).
Loading