[Scummvm-git-logs] scummvm master -> e5cf05a1fa49bcc329dd2461431b914d542b5558

rvanlaar noreply at scummvm.org
Sat Feb 11 21:14:06 UTC 2023


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
e2029f6d16 DEVTOOLS: COMPANION: Improve python typing
85e95e465f DEVTOOLS: COMPANION: make variable names explicit
e5cf05a1fa DEVTOOLS: COMPANION: ease logic inside forloop


Commit: e2029f6d1641e69c5ffdf321c498c79cf093594f
    https://github.com/scummvm/scummvm/commit/e2029f6d1641e69c5ffdf321c498c79cf093594f
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2023-02-11T22:13:11+01:00

Commit Message:
DEVTOOLS: COMPANION: Improve python typing

Main changes:
- use bytes instead of ByteString
    ByteString lacks a `decode` which we do call
- use newer python syntax `|` to not use Optional
- use newer python syntax to use lowercase list and tuple instead of
  List and Tuple
- typing fixes where the incorrect type was used

Changed paths:
    devtools/dumper-companion.py


diff --git a/devtools/dumper-companion.py b/devtools/dumper-companion.py
index 4a573eac2c3..874e5d004d0 100755
--- a/devtools/dumper-companion.py
+++ b/devtools/dumper-companion.py
@@ -23,10 +23,10 @@ import unicodedata
 import urllib.request
 import zipfile
 from binascii import crc_hqx
-from io import BytesIO, StringIO, IOBase
+from io import BytesIO, IOBase, StringIO
 from pathlib import Path
 from struct import pack, unpack
-from typing import Any, ByteString, List, Tuple
+from typing import Any
 
 import machfs
 
@@ -88,7 +88,7 @@ decode_map = {
 # fmt: on
 
 
-def decode_macjapanese(text: ByteString) -> str:
+def decode_macjapanese(text: bytes) -> str:
     """
     Decode MacJapanese
 
@@ -157,7 +157,7 @@ def decode_macjapanese(text: ByteString) -> str:
     return res
 
 
-def file_to_macbin(out_f: IOBase, f: machfs.File, name: ByteString) -> bytes:
+def file_to_macbin(out_f: IOBase, f: machfs.File, name: bytes) -> None:
     oldFlags = f.flags >> 8
     newFlags = f.flags & 0xFF
     macbin_header = pack(
@@ -191,6 +191,8 @@ def file_to_macbin(out_f: IOBase, f: machfs.File, name: ByteString) -> bytes:
         out_f.write(f.rsrc)
         out_f.write(b"\x00" * (-len(f.rsrc) % 128))
 
+    return None
+
 
 def macbin_get_datafork(f: bytes) -> bytes:
     (datalen,) = unpack(">I", f[0x53:0x57])
@@ -298,7 +300,7 @@ def extract_volume(args: argparse.Namespace) -> int:
     japanese: bool = args.japanese
     dryrun: bool = args.dryrun
     rawtext: bool = args.nopunycode
-    loglevel: string = args.log
+    loglevel: str = args.log
     force_macbinary: bool = args.forcemacbinary
 
     numeric_level = getattr(logging, loglevel.upper(), None)
@@ -396,7 +398,7 @@ def extract_volume(args: argparse.Namespace) -> int:
 
 
 def punyencode_paths(
-    paths: List[Path], verbose: bool = False, source_encoding: str = None
+    paths: list[Path], verbose: bool = False, source_encoding: str | None = None
 ) -> int:
     """Rename filepaths to their punyencoded names"""
     count = 0
@@ -416,7 +418,7 @@ def punyencode_paths(
     return count
 
 
-def demojibake_hfs_bytestring(s: ByteString, encoding: str):
+def demojibake_hfs_bytestring(s: bytes, encoding: str):
     """
     Takes misinterpreted bytestrings from macOS and transforms
     them into the correct interpretation.
@@ -440,12 +442,11 @@ def demojibake_hfs_bytestring(s: ByteString, encoding: str):
     )
 
 
-def decode_bytestring(s: ByteString, encoding: str):
+def decode_bytestring(s: bytes, encoding: str):
     """Wrapper for decode() that can dispatch to decode_macjapanese"""
     if encoding == "mac_japanese":
         return decode_macjapanese(s)
-    else:
-        return s.decode(encoding)
+    return s.decode(encoding)
 
 
 def punyencode_arg(args: argparse.Namespace) -> int:
@@ -455,15 +456,15 @@ def punyencode_arg(args: argparse.Namespace) -> int:
 
 
 def punyencode_dir(
-    directory: Path, verbose: bool = False, source_encoding: str = None
+    directory: Path, verbose: bool = False, source_encoding: str|None = None
 ) -> int:
     """
     Recursively punyencode all directory and filenames
 
     Renames the leaves, i.e. files, first and the works it way up the tree by renaming the
     """
-    files: List[Path] = []
-    dirs: List[Path] = []
+    files: list[Path] = []
+    dirs: list[Path] = []
     if source_encoding is not None:
         directory = Path(demojibake_hfs_bytestring(directory, source_encoding))
     else:
@@ -796,7 +797,7 @@ if __name__ == "__main__":
 ### Test functions
 
 
-def call_test_parser(input_args: List[str]) -> Any:
+def call_test_parser(input_args: list[str]) -> Any:
     """Helper function to call the parser"""
     parser = generate_parser()
     args = parser.parse_args(input_args)


Commit: 85e95e465fa50aad516e465a54f3c5f450afae11
    https://github.com/scummvm/scummvm/commit/85e95e465fa50aad516e465a54f3c5f450afae11
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2023-02-11T22:13:11+01:00

Commit Message:
DEVTOOLS: COMPANION: make variable names explicit

Rename variable names to have a name that means what it's for.

Changed paths:
    devtools/dumper-companion.py


diff --git a/devtools/dumper-companion.py b/devtools/dumper-companion.py
index 874e5d004d0..441ef36fa3b 100755
--- a/devtools/dumper-companion.py
+++ b/devtools/dumper-companion.py
@@ -299,7 +299,7 @@ def extract_volume(args: argparse.Namespace) -> int:
     destination_dir: Path = args.dir
     japanese: bool = args.japanese
     dryrun: bool = args.dryrun
-    rawtext: bool = args.nopunycode
+    dopunycode: bool = not args.nopunycode
     loglevel: str = args.log
     force_macbinary: bool = args.forcemacbinary
 
@@ -337,8 +337,8 @@ def extract_volume(args: argparse.Namespace) -> int:
 
     if not dryrun:
         destination_dir.mkdir(parents=True, exist_ok=True)
-    maybe_not_jp = False
-    maybe_not_jp_warned = False
+    might_be_jp = False
+    might_be_jp_warned = False
     for hpath, obj in vol.iter_paths():
         # Encode the path
         upath = destination_dir
@@ -350,20 +350,20 @@ def extract_volume(args: argparse.Namespace) -> int:
                     if decode_macjapanese(
                         el.encode("mac_roman")
                     ) != el and not isinstance(obj, machfs.Folder):
-                        maybe_not_jp = True
+                        might_be_jp = True
                 except Exception:
                     # If we get an exception from trying to decode it as Mac-Japanese, it's probably not
                     pass
-            if not rawtext:
+            if dopunycode:
                 el = punyencode(el)
 
             upath /= el
 
-        if maybe_not_jp and not maybe_not_jp_warned:
+        if might_be_jp and not might_be_jp_warned:
             logging.warning(
                 "Possible Mac-Japanese string detected, did you mean to use --japanese?"
             )
-            maybe_not_jp_warned = True
+            might_be_jp_warned = True
 
         # Write the file to disk
         if isinstance(obj, machfs.Folder):


Commit: e5cf05a1fa49bcc329dd2461431b914d542b5558
    https://github.com/scummvm/scummvm/commit/e5cf05a1fa49bcc329dd2461431b914d542b5558
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2023-02-11T22:13:11+01:00

Commit Message:
DEVTOOLS: COMPANION: ease logic inside forloop

Continue early when in dryrun mode to have less checks on dryrun
and less indentation.

Changed paths:
    devtools/dumper-companion.py


diff --git a/devtools/dumper-companion.py b/devtools/dumper-companion.py
index 441ef36fa3b..59c84122922 100755
--- a/devtools/dumper-companion.py
+++ b/devtools/dumper-companion.py
@@ -365,35 +365,37 @@ def extract_volume(args: argparse.Namespace) -> int:
             )
             might_be_jp_warned = True
 
+        if dryrun:
+            continue
+
         # Write the file to disk
         if isinstance(obj, machfs.Folder):
-            if not dryrun:
-                upath.mkdir(exist_ok=True)
-                os.utime(upath, (obj.mddate - 2082844800, obj.mddate - 2082844800))
+            upath.mkdir(exist_ok=True)
+            os.utime(upath, (obj.mddate - 2082844800, obj.mddate - 2082844800))
             # Set the modified time for folders
-        else:
-            print(upath)
-            if not dryrun:
-                if obj.data and not obj.rsrc and not force_macbinary:
-                    upath.write_bytes(obj.data)
-
-                elif obj.rsrc or force_macbinary:
-                    with upath.open("wb") as out_file:
-                        file_to_macbin(out_file, obj, hpath[-1].encode("mac_roman"))
-
-                elif not obj.data and not obj.rsrc:
-                    upath.touch()
-
-                os.utime(upath, (obj.mddate - 2082844800, obj.mddate - 2082844800))
-                # This needs to be done after writing files as writing files resets
-                # the parent folder's modified time that was set before
-                if len(hpath) > 1:
-                    for i in range(len(hpath), 0, -1):
-                        parent_folder_modtime = vol.get(hpath[:i]).mddate - 2082844800
-                        os.utime(
-                            Path(*(upath.parts[:i])),
-                            (parent_folder_modtime, parent_folder_modtime),
-                        )
+            continue
+
+        print(upath)
+        if obj.data and not obj.rsrc and not force_macbinary:
+            upath.write_bytes(obj.data)
+
+        elif obj.rsrc or force_macbinary:
+            with upath.open("wb") as out_file:
+                file_to_macbin(out_file, obj, hpath[-1].encode("mac_roman"))
+
+        elif not obj.data and not obj.rsrc:
+            upath.touch()
+
+        os.utime(upath, (obj.mddate - 2082844800, obj.mddate - 2082844800))
+        # This needs to be done after writing files as writing files resets
+        # the parent folder's modified time that was set before
+        if len(hpath) > 1:
+            for i in range(len(hpath), 0, -1):
+                parent_folder_modtime = vol.get(hpath[:i]).mddate - 2082844800
+                os.utime(
+                    Path(*(upath.parts[:i])),
+                    (parent_folder_modtime, parent_folder_modtime),
+                )
     return 0
 
 




More information about the Scummvm-git-logs mailing list