mirror of
https://github.com/dockur/windows.git
synced 2026-07-28 21:53:34 +07:00
Update iso-prototype.py
This commit is contained in:
+103
-3
@@ -379,14 +379,114 @@ def find_existing_record(iso, logical: PurePosixPath) -> dict[str, str]:
|
||||
return found
|
||||
|
||||
|
||||
def namespace_kwargs(iso, logical: PurePosixPath, *, is_dir: bool = False) -> dict[str, str]:
|
||||
kwargs: dict[str, str] = {"iso_path": iso_candidates(logical, is_dir=is_dir)[0]}
|
||||
def iso9660_alias_component(
|
||||
name: str,
|
||||
*,
|
||||
is_dir: bool,
|
||||
interchange_level: int,
|
||||
) -> str:
|
||||
value = name.upper()
|
||||
|
||||
# ISO9660 level 4 permits arbitrary characters. For levels 1-3, replace
|
||||
# characters outside the d1 set accepted by PyCdlib. A file's dot remains
|
||||
# the separator between its name and extension.
|
||||
if interchange_level < 4:
|
||||
allowed = set("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")
|
||||
|
||||
def sanitize(part: str) -> str:
|
||||
return "".join(
|
||||
char if char in allowed else "_"
|
||||
for char in part
|
||||
)
|
||||
|
||||
if is_dir:
|
||||
value = sanitize(value)
|
||||
else:
|
||||
stem, dot, extension = value.rpartition(".")
|
||||
|
||||
if not dot:
|
||||
stem = value
|
||||
extension = ""
|
||||
|
||||
value = sanitize(stem)
|
||||
|
||||
if extension:
|
||||
value += "." + sanitize(extension)
|
||||
|
||||
if not value:
|
||||
value = "_"
|
||||
|
||||
if interchange_level == 1:
|
||||
if is_dir:
|
||||
return value[:8]
|
||||
|
||||
stem, dot, extension = value.partition(".")
|
||||
stem = stem[:8]
|
||||
|
||||
if dot:
|
||||
return f"{stem}.{extension[:3]}"
|
||||
|
||||
return stem
|
||||
|
||||
return value
|
||||
|
||||
|
||||
def iso9660_alias_path(
|
||||
iso,
|
||||
logical: PurePosixPath,
|
||||
*,
|
||||
is_dir: bool = False,
|
||||
) -> str:
|
||||
logical_parts = [
|
||||
part
|
||||
for part in logical.parts
|
||||
if part != "/"
|
||||
]
|
||||
|
||||
aliases: list[str] = []
|
||||
|
||||
for index, part in enumerate(logical_parts):
|
||||
component_is_dir = (
|
||||
is_dir or index < len(logical_parts) - 1
|
||||
)
|
||||
|
||||
aliases.append(
|
||||
iso9660_alias_component(
|
||||
part,
|
||||
is_dir=component_is_dir,
|
||||
interchange_level=iso.interchange_level,
|
||||
)
|
||||
)
|
||||
|
||||
path = "/" + "/".join(aliases)
|
||||
|
||||
if is_dir:
|
||||
return path
|
||||
|
||||
return path + ";1"
|
||||
|
||||
|
||||
def namespace_kwargs(
|
||||
iso,
|
||||
logical: PurePosixPath,
|
||||
*,
|
||||
is_dir: bool = False,
|
||||
) -> dict[str, str]:
|
||||
kwargs: dict[str, str] = {
|
||||
"iso_path": iso9660_alias_path(
|
||||
iso,
|
||||
logical,
|
||||
is_dir=is_dir,
|
||||
)
|
||||
}
|
||||
|
||||
if iso.has_joliet():
|
||||
kwargs["joliet_path"] = str(logical)
|
||||
|
||||
if iso.has_udf():
|
||||
kwargs["udf_path"] = str(logical)
|
||||
return kwargs
|
||||
|
||||
return kwargs
|
||||
|
||||
def ensure_parent_directories(iso, logical: PurePosixPath) -> None:
|
||||
current = PurePosixPath("/")
|
||||
|
||||
Reference in New Issue
Block a user