Skip to content

Commit

Permalink
fix typo for config change recovery
Browse files Browse the repository at this point in the history
finish transitioning mod iteration over from translations to mods
  • Loading branch information
EphDoering committed Oct 8, 2024
1 parent f7acdb0 commit a272178
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 90 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"cooldown",
"excepthook",
"Factorio",
"freeplay",
"localised",
"neighbouring",
"pyinstaller",
Expand Down
17 changes: 9 additions & 8 deletions fa_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import fa_paths
import translations
from launch_and_monitor import launch_with_params
import fa_menu
from mods import mod_manager


class Scenario(NamedTuple):
Expand All @@ -19,7 +19,7 @@ class Scenario(NamedTuple):
def get_scenario_from_path(path):
with path.open(encoding="utf8") as fp:
json_desc = json.load(fp)
parts = translations.get_mod_path_parts(path)
parts = mod_manager.get_mod_path_parts(path)
key = parts[0] + "/" + parts[2]
locale = path.parent.joinpath("locale")
if not locale:
Expand Down Expand Up @@ -52,12 +52,13 @@ def get_scenarios(m_scenario=None):
if m_scenario:
return m_scenario.name
scenarios = []
for path in translations.iterate_over_mod_files(
"scenarios/.*/description.json", re.compile(r"FactorioAccess.*")
):
scenario = get_scenario_from_path(path)
if scenario:
scenarios.append(scenario)
with mod_manager:
for path in mod_manager.iter_mod_files(
"scenarios/.*/description.json", True, re.compile(r"FactorioAccess.*")
):
scenario = get_scenario_from_path(path)
if scenario:
scenarios.append(scenario)
scenarios.sort()
return {s.name: (s,) for s in scenarios}

Expand Down
44 changes: 22 additions & 22 deletions modify_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import translations
import config
from fa_menu import select_option
from mods import mod_manager

MOD_NAME = "FactorioAccess"
CHANGESET_PATH = "config_changes"
CHANGESET_PATH = r"config_changes/.*\.ini"

config_re = re.compile(r"^([\w-]+)=(.*)")
comment_re = re.compile(r"^;")

our_mod_filter = re.compile(fa_paths.MOD_NAME)


def get_changes_from_fp(fp):
changes = defaultdict(dict)
Expand All @@ -33,18 +35,18 @@ def get_changes_from_fp(fp):

def get_all_changes(after="AA"):
all_changes = {}
for cfg_path in translations.iterate_over_mod_files(
CHANGESET_PATH + r"/.*\.ini", re.compile("FactorioAccess.*")
):
version = cfg_path.name[:2]
if version <= after:
continue
if not re.fullmatch("[A-Z]{2}", version):
raise ValueError(
"configureation change sets must begin with the next two capital letters"
)
with cfg_path.open(encoding="utf8") as fp:
all_changes[version] = get_changes_from_fp(fp)
with mod_manager:
mod_iter = mod_manager.iter_mod_files(CHANGESET_PATH, True, our_mod_filter)
for cfg_path in mod_iter:
version = cfg_path.name[:2]
if version <= after:
continue
if not re.fullmatch("[A-Z]{2}", version):
raise ValueError(
"configuration change sets must begin with the next two capital letters"
)
with cfg_path.open(encoding="utf8") as fp:
all_changes[version] = get_changes_from_fp(fp)
return all_changes


Expand All @@ -53,19 +55,17 @@ def do_config_check():
current = ""
try:
for i in ["1", "2"]:
current += config.current_conf.get_setting(
"controls", f"access-config-version{i}-DO-NOT-EDIT"
)
setting_string = f"access-config-version{i}-DO-NOT-EDIT"
current += config.current_conf.get_setting("controls", setting_string)
except config.Config_Missing:
current = "AA"
if current == "Co":
current = (
"AE" # to correct for an issue with a config file being baddly named.
)
if current == "Ch":
# to correct for an issue with a config file being badly named.
current = "AE"
change_sets = get_all_changes(after=current)
if not change_sets:
return
p = """There are changes that the Factorio Access mod recommends making to your cofiguration file that have not yet been applied.
p = """There are changes that the Factorio Access mod recommends making to your configuration file that have not yet been applied.
These can be applied interactively or all at once.
How would you like to proceed?"""
ops = [
Expand Down
12 changes: 0 additions & 12 deletions mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,18 +510,6 @@ def iter_mod_files(


if __name__ == "__main__":
test = [
DependencyType.CONFLICT,
DependencyType.HIDDEN_OPTIONAL,
DependencyType.CONFLICT,
DependencyType.NORMAL,
]
s_test = list(sorted(test))
print(test, s_test)
test.sort(key=lambda x: list(DependencyType).index(x))
print(test)
print(DependencyType.NORMAL <= DependencyType.OPTIONAL)
print(list(DependencyType))
print(dependency.from_str("! stop >= 3.4.5").meets(mod_version("3.4.5")))
with mod_manager:
pass
48 changes: 0 additions & 48 deletions translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,54 +258,6 @@ def get_mod_path_parts(path: Union[zipfile.Path, Path]):
return tuple(parts[::-1])


def iterate_over_mods(re_filter: re.Pattern[str] = None) -> Iterator[Path]:
import fa_paths

if re_filter:
for mod_path in iterate_over_mods():
if re_filter.fullmatch(mod_path.name):
yield mod_path
return
base_path = fa_paths.READ_DIR
for base_core in ["core", "base"]:
yield base_path.joinpath(base_core)
yield from fa_paths.MODS.iterdir()


def mod_re_files_sub(parts: list[str], path: Union[zipfile.Path, Path]):
if not path.exists():
return
if not parts:
if path.is_file():
yield path
return
if not path.is_dir():
return
part = parts[0]
if not fancy.search(part):
yield from mod_re_files_sub(parts[1:], path.joinpath(part))
return
myre = re.compile(part)
for path_part in path.iterdir():
if myre.fullmatch(path_part.name):
yield from mod_re_files_sub(parts[1:], path_part)


def iterate_over_this_mods_files(parts: list[str], mod_path: Path):
if mod_path.is_file():
if not zipfile.is_zipfile(mod_path):
return
mod_path = zipfile.Path(mod_path)
mod_path = next(mod_path.iterdir())
yield from mod_re_files_sub(parts, mod_path)


def iterate_over_mod_files(inner_re_path: str, mod_filter: re.Pattern[str] = None):
parts = inner_re_path.split("/")
for mod in iterate_over_mods(mod_filter):
yield from iterate_over_this_mods_files(parts, mod)


def read_cfg(fp: Iterable[str], conf=False, ret=defaultdict(dict)):
name = ""
while True:
Expand Down

0 comments on commit a272178

Please sign in to comment.