-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow version to be imported without importing the main module
- Loading branch information
1 parent
a64b22d
commit eb93c55
Showing
4 changed files
with
64 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
from .dread_patcher import patch, patch_with_status_update | ||
from pathlib import Path | ||
|
||
from .patch_util import patch_with_status_update | ||
|
||
|
||
def patch(input_path: Path, output_path: Path, configuration: dict): | ||
from .dread_patcher import patch_extracted | ||
return patch_extracted(input_path, output_path, configuration) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import logging | ||
import typing | ||
from pathlib import Path | ||
|
||
from open_dread_rando.logger import LOG | ||
|
||
|
||
def patch_with_status_update(input_path: Path, output_path: Path, configuration: dict, | ||
status_update: typing.Callable[[float, str], None]): | ||
from open_dread_rando.dread_patcher import patch_extracted | ||
total_logs = 108 | ||
|
||
class StatusUpdateHandler(logging.Handler): | ||
count = 0 | ||
|
||
def emit(self, record: logging.LogRecord) -> None: | ||
message = self.format(record) | ||
|
||
# Ignore "Writing <...>.pkg" messages, since there's also Updating... | ||
if message.startswith("Writing ") and message.endswith(".pkg"): | ||
return | ||
|
||
# Encoding a bmsad is quick, skip these | ||
if message.endswith(".bmsad"): | ||
return | ||
|
||
# These can come up frequently and are benign | ||
if message.startswith("Skipping extracted file"): | ||
return | ||
|
||
self.count += 1 | ||
status_update(self.count / total_logs, message) | ||
|
||
new_handler = StatusUpdateHandler() | ||
# new_handler.setFormatter(logging.Formatter('[%(asctime)s] [%(levelname)s] %(message)s')) | ||
tree_editor_log = logging.getLogger("mercury_engine_data_structures.file_tree_editor") | ||
|
||
try: | ||
tree_editor_log.setLevel(logging.DEBUG) | ||
tree_editor_log.handlers.insert(0, new_handler) | ||
tree_editor_log.propagate = False | ||
LOG.setLevel(logging.INFO) | ||
LOG.handlers.insert(0, new_handler) | ||
LOG.propagate = False | ||
|
||
patch_extracted(input_path, output_path, configuration) | ||
if new_handler.count < total_logs: | ||
status_update(1, f"Done was {new_handler.count}") | ||
|
||
finally: | ||
tree_editor_log.removeHandler(new_handler) | ||
tree_editor_log.propagate = True | ||
LOG.removeHandler(new_handler) | ||
LOG.propagate = True |