Skip to content

Commit eb0b8ad

Browse files
[pre-commit.ci] Auto fixes from pre-commit.com hooks.
1 parent 0f62cec commit eb0b8ad

7 files changed

Lines changed: 79 additions & 31 deletions

File tree

games/baldursgate3/bg3_file_mapper.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from typing import Callable, Optional
55

6-
from PyQt6.QtCore import QDir, qDebug, qInfo, qWarning, QLoggingCategory
6+
from PyQt6.QtCore import QDir, QLoggingCategory, qDebug, qInfo, qWarning
77
from PyQt6.QtWidgets import QApplication
88

99
import mobase
@@ -45,23 +45,30 @@ def mappings(self) -> list[mobase.Mapping]:
4545
if progress.wasCanceled():
4646
qWarning("mapping canceled by user")
4747
return self.current_mappings
48-
(self._utils.overwrite_path / 'Script Extender').mkdir(parents=True, exist_ok=True)
49-
(self._utils.overwrite_path / 'Stats').mkdir(parents=True, exist_ok=True)
50-
(self._utils.overwrite_path / 'Temp').mkdir(parents=True, exist_ok=True)
51-
(self._utils.overwrite_path / 'LevelCache').mkdir(parents=True, exist_ok=True)
52-
(self._utils.overwrite_path / 'Stats').mkdir(parents=True, exist_ok=True)
53-
(self._utils.overwrite_path / 'Mods').mkdir(parents=True, exist_ok=True)
54-
(self._utils.overwrite_path / 'GMCampaigns').mkdir(parents=True, exist_ok=True)
48+
(self._utils.overwrite_path / "Script Extender").mkdir(
49+
parents=True, exist_ok=True
50+
)
51+
(self._utils.overwrite_path / "Stats").mkdir(parents=True, exist_ok=True)
52+
(self._utils.overwrite_path / "Temp").mkdir(parents=True, exist_ok=True)
53+
(self._utils.overwrite_path / "LevelCache").mkdir(parents=True, exist_ok=True)
54+
(self._utils.overwrite_path / "Stats").mkdir(parents=True, exist_ok=True)
55+
(self._utils.overwrite_path / "Mods").mkdir(parents=True, exist_ok=True)
56+
(self._utils.overwrite_path / "GMCampaigns").mkdir(parents=True, exist_ok=True)
5557
self.map_files(self._utils.overwrite_path)
5658
self.create_mapping(
5759
self._utils.modsettings_path,
58-
self.doc_path / "PlayerProfiles" / "Public" / self._utils.modsettings_path.name,
60+
self.doc_path
61+
/ "PlayerProfiles"
62+
/ "Public"
63+
/ self._utils.modsettings_path.name,
5964
)
6065
progress.setValue(len(active_mods) + 1)
6166
QApplication.processEvents()
6267
progress.close()
6368
if QLoggingCategory.defaultCategory().isDebugEnabled():
64-
qDebug(f"resolved mappings: { {m.source: m.destination for m in self.current_mappings} }")
69+
qDebug(
70+
f"resolved mappings: { {m.source: m.destination for m in self.current_mappings} }"
71+
)
6572
return self.current_mappings
6673

6774
def map_files(
@@ -70,7 +77,7 @@ def map_files(
7077
dest: Optional[Path] = None,
7178
pattern: str = "*",
7279
rel: bool = True,
73-
only_convert: bool = False
80+
only_convert: bool = False,
7481
):
7582
dest = dest if dest else self.doc_path
7683
dest_func: Callable[[Path], str] = (
@@ -89,7 +96,9 @@ def map_files(
8996
file
9097
) > os.path.getmtime(converted_path):
9198
import json
99+
92100
import yaml
101+
93102
with open(file, "r") as yaml_file:
94103
with open(converted_path, "w") as json_file:
95104
json.dump(

games/baldursgate3/bg3_utils.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@
2727
"ScriptExtender",
2828
}
2929

30-
def get_node_string(folder: str = "", md5: str = "", name: str = "", publish_handle: str = "0", uuid: str = "", version64: str = "0") -> str:
30+
31+
def get_node_string(
32+
folder: str = "",
33+
md5: str = "",
34+
name: str = "",
35+
publish_handle: str = "0",
36+
uuid: str = "",
37+
version64: str = "0",
38+
) -> str:
3139
return f"""
3240
<node id="ModuleShortDesc">
3341
<attribute id="Folder" type="LSString" value="{folder}"/>
@@ -38,16 +46,22 @@ def get_node_string(folder: str = "", md5: str = "", name: str = "", publish_han
3846
<attribute id="Version64" type="int64" value="{version64}"/>
3947
</node>"""
4048

49+
4150
class BG3Utils:
42-
_mod_settings_xml_start = f"""\
51+
_mod_settings_xml_start = """\
4352
<?xml version="1.0" encoding="UTF-8"?>
4453
<save>
4554
<version major="4" minor="8" revision="0" build="500"/>
4655
<region id="ModuleSettings">
4756
<node id="root">
4857
<children>
4958
<node id="Mods">
50-
<children>""" + get_node_string(folder="GustavX", name="GustavX", uuid="cb555efe-2d9e-131f-8195-a89329d218ea", version64="36028797018963968")
59+
<children>""" + get_node_string(
60+
folder="GustavX",
61+
name="GustavX",
62+
uuid="cb555efe-2d9e-131f-8195-a89329d218ea",
63+
version64="36028797018963968",
64+
)
5165
_mod_settings_xml_end = """
5266
</children>
5367
</node>
@@ -101,12 +115,16 @@ def modsettings_backup(self):
101115

102116
@functools.cached_property
103117
def modsettings_path(self):
104-
return create_dir_if_needed(Path(self._organizer.profilePath()) / "modsettings.lsx")
118+
return create_dir_if_needed(
119+
Path(self._organizer.profilePath()) / "modsettings.lsx"
120+
)
105121

106122
@functools.cached_property
107123
def plugin_data_path(self) -> Path:
108124
"""Gets the path to the data folder for the current plugin."""
109-
return create_dir_if_needed(Path(self._organizer.pluginDataPath(), self._name).absolute())
125+
return create_dir_if_needed(
126+
Path(self._organizer.pluginDataPath(), self._name).absolute()
127+
)
110128

111129
@functools.cached_property
112130
def tools_dir(self):
@@ -247,8 +265,9 @@ def on_mod_installed(self, mod: mobase.IModInterface) -> None:
247265
if self.lslib_retriever.download_lslib_if_missing():
248266
self._pak_parser.get_metadata_for_files_in_mod(mod, True)
249267

268+
250269
def create_dir_if_needed(path: Path) -> Path:
251-
if '.' not in path.name[1:]:
270+
if "." not in path.name[1:]:
252271
path.mkdir(parents=True, exist_ok=True)
253272
else:
254273
path.parent.mkdir(parents=True, exist_ok=True)

games/baldursgate3/pak_parser.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,13 @@ def get_module_short_desc(config: configparser.ConfigParser, file: Path) -> str:
283283
section: configparser.SectionProxy = config[file.name]
284284
return (
285285
""
286-
if "override" in section.keys()
287-
or "Name" not in section.keys()
288-
else
289-
bg3_utils.get_node_string(folder=section["Folder"], md5=section["MD5"], name=section["Name"],
290-
publish_handle=section["PublishHandle"], uuid=section["UUID"],
291-
version64=section["Version64"])
286+
if "override" in section.keys() or "Name" not in section.keys()
287+
else bg3_utils.get_node_string(
288+
folder=section["Folder"],
289+
md5=section["MD5"],
290+
name=section["Name"],
291+
publish_handle=section["PublishHandle"],
292+
uuid=section["UUID"],
293+
version64=section["Version64"],
294+
)
292295
)

games/baldursgate3/plugins/bg3_tool_plugin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import mobase
21
from PyQt6.QtCore import QCoreApplication
32
from PyQt6.QtGui import QIcon, QPixmap
43

4+
import mobase
5+
56

67
class BG3ToolPlugin(mobase.IPluginTool, mobase.IPlugin):
78
desc = sub_name = ""
89
icon_bytes: bytes
10+
911
def __init__(self):
1012
mobase.IPluginTool.__init__(self)
1113
mobase.IPlugin.__init__(self)

games/baldursgate3/plugins/check_for_lslib_updates_plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .bg3_tool_plugin import BG3ToolPlugin
22
from .icons import download
33

4+
45
class BG3ToolCheckForLsLibUpdates(BG3ToolPlugin):
56
icon_bytes = download
67
sub_name = "Check For LsLib Updates"

games/baldursgate3/plugins/convert_jsons_to_yaml_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ def display(self):
4040

4141

4242
def _convert_jsons_in_dir_to_yaml(path: Path):
43-
4443
for file in list(path.rglob("*.json")):
4544
converted_path = file.parent / file.name.replace(".json", ".yaml")
4645
try:
4746
if not converted_path.exists() or os.path.getmtime(file) > os.path.getmtime(
4847
converted_path
4948
):
5049
import yaml
50+
5151
with open(file, "r") as json_file:
5252
with open(converted_path, "w") as yaml_file:
5353
yaml.dump(

games/game_baldursgate3.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from typing import Any
88

99
from PyQt6.QtCore import (
10+
QLoggingCategory,
1011
qDebug,
11-
qInfo, QLoggingCategory,
12+
qInfo,
1213
)
1314

1415
import mobase
@@ -180,7 +181,12 @@ def _on_finished_run(self, exec_path: str, exit_code: int):
180181
if "bin/bg3" not in exec_path:
181182
return
182183
self.utils.log_dir.mkdir(parents=True, exist_ok=True)
183-
if QLoggingCategory.defaultCategory().isDebugEnabled() and self.utils.log_diff and self.utils.modsettings_backup.exists() and self.utils.modsettings_path.exists():
184+
if (
185+
QLoggingCategory.defaultCategory().isDebugEnabled()
186+
and self.utils.log_diff
187+
and self.utils.modsettings_backup.exists()
188+
and self.utils.modsettings_path.exists()
189+
):
184190
for x in difflib.unified_diff(
185191
self.utils.modsettings_backup.open().readlines(),
186192
self.utils.modsettings_path.open().readlines(),
@@ -192,7 +198,9 @@ def _on_finished_run(self, exec_path: str, exit_code: int):
192198
moved = {}
193199
for path in self.utils.overwrite_path.rglob("*.log"):
194200
try:
195-
moved[str(path.relative_to(Path.home()))] = str((self.utils.log_dir / path.name).relative_to(Path.home()))
201+
moved[str(path.relative_to(Path.home()))] = str(
202+
(self.utils.log_dir / path.name).relative_to(Path.home())
203+
)
196204
path.replace(self.utils.log_dir / path.name)
197205
except PermissionError as e:
198206
qDebug(str(e))
@@ -201,7 +209,9 @@ def _on_finished_run(self, exec_path: str, exit_code: int):
201209
if path.name == "log.txt":
202210
dest = self.utils.log_dir / f"{path.parent.name}-{path.name}"
203211
try:
204-
moved[str(path.relative_to(Path.home()))] = str(dest.relative_to(Path.home()))
212+
moved[str(path.relative_to(Path.home()))] = str(
213+
dest.relative_to(Path.home())
214+
)
205215
path.replace(dest)
206216
except PermissionError as e:
207217
qDebug(str(e))
@@ -220,7 +230,9 @@ def _on_finished_run(self, exec_path: str, exit_code: int):
220230
shutil.rmtree(path, ignore_errors=True)
221231
removed.add(path)
222232
if QLoggingCategory.defaultCategory().isDebugEnabled() and len(removed) > 0:
223-
qDebug(f"cleaned the following folders due to them being older than {cutoff_time}: {removed}")
233+
qDebug(
234+
f"cleaned the following folders due to them being older than {cutoff_time}: {removed}"
235+
)
224236
for fdir in {self.utils.overwrite_path, self.doc_path}:
225237
removed = set()
226238
for folder in sorted(list(fdir.walk(top_down=False)))[:-1]:
@@ -230,4 +242,6 @@ def _on_finished_run(self, exec_path: str, exit_code: int):
230242
except OSError:
231243
pass
232244
if QLoggingCategory.defaultCategory().isDebugEnabled() and len(removed) > 0:
233-
qDebug(f"cleaned empty dirs from {fdir.relative_to(Path.home())} {removed}")
245+
qDebug(
246+
f"cleaned empty dirs from {fdir.relative_to(Path.home())} {removed}"
247+
)

0 commit comments

Comments
 (0)