Skip to content

Commit

Permalink
Some restructuring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lattyware committed Jul 7, 2019
1 parent 97c504b commit d6192a3
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ usage: unrpa [-h] [-v] [-s] [-l] [-p PATH] [-m] [-f VERSION]
| -l, --list | only list contents, do not extract. |
| -p PATH, --path PATH | will extract to the given path. |
| -m, --mkdir | will make any non-existent directories in extraction path. |
| -f VERSION, --force VERSION | forces an archive version. May result in failure.<br>Possible versions: RPA-3.0, RPA-3.2, ZiX-12A, ZiX-12B, ALT-1.0, RPA-2.0, RPA-1.0. |
| -f VERSION, --force VERSION | forces an archive version. May result in failure.<br>Possible versions: RPA-1.0, RPA-2.0, RPA-3.0, ALT-1.0, ZiX-12A, ZiX-12B, RPA-3.2. |
| --continue-on-error | try to continue extraction when something goes wrong. |
| -o OFFSET, --offset OFFSET | sets an offset to be used to decode unsupported archives. |
| -k KEY, --key KEY | sets a key to be used to decode unsupported archives. |
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import setuptools # type: ignore
from unrpa import meta

with open("README.md", "r") as readme:
long_description = readme.read()

setuptools.setup(
name="unrpa",
version="2.1.0",
version=meta.version,
author="Gareth Latty",
author_email="[email protected]",
description="Extract files from the RPA archive format (from the Ren'Py Visual Novel Engine).",
Expand Down
11 changes: 8 additions & 3 deletions unrpa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
AmbiguousArchiveError,
UnknownArchiveError,
)
from unrpa.versions import rpa, alt, zix
from unrpa.versions import official_rpa, alt, zix, unofficial_rpa
from unrpa.versions.version import Version
from unrpa.view import ArchiveView

Expand All @@ -44,10 +44,15 @@ class UnRPA:
info = 1
debug = 2

provided_versions: FrozenSet[Type[Version]] = frozenset(
{*rpa.versions, *alt.versions, *zix.versions}
ordered_versions: Tuple[Type[Version], ...] = (
*official_rpa.versions,
*alt.versions,
*zix.versions,
*unofficial_rpa.versions,
)

provided_versions: FrozenSet[Type[Version]] = frozenset(ordered_versions)

def __init__(
self,
filename: str,
Expand Down
9 changes: 6 additions & 3 deletions unrpa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from unrpa import UnRPA
from unrpa.errors import UnRPAError
from unrpa import meta


def main() -> None:
Expand Down Expand Up @@ -81,7 +82,7 @@ def main() -> None:
dest="version",
default=None,
help="forces an archive version. May result in failure. Possible versions: "
+ ", ".join(version.name for version in UnRPA.provided_versions)
+ ", ".join(version.name for version in UnRPA.ordered_versions)
+ ".",
)
parser.add_argument(
Expand Down Expand Up @@ -110,7 +111,9 @@ def main() -> None:
help="sets a key to be used to decode unsupported archives.",
)

parser.add_argument("--version", action="version", version="%(prog)s 2.0.1")
parser.add_argument(
"--version", action="version", version=f"%(prog)s {meta.version}"
)

parser.add_argument(
"filename", metavar="FILENAME", type=str, help="the RPA file to extract."
Expand All @@ -129,7 +132,7 @@ def main() -> None:
except StopIteration:
parser.error(
"The archive version you gave isn’t one we recognise - it needs to be one of: "
+ ", ".join(version.name for version in UnRPA.provided_versions)
+ ", ".join(version.name for version in UnRPA.ordered_versions)
)

provided_offset_and_key: Optional[Tuple[int, int]] = None
Expand Down
1 change: 1 addition & 0 deletions unrpa/meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "2.1.0"
4 changes: 2 additions & 2 deletions unrpa/versions/alt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import BinaryIO, Tuple, Optional, FrozenSet, Type
from typing import BinaryIO, Tuple, Optional, Type

from unrpa.versions.version import HeaderBasedVersion, Version

Expand All @@ -18,4 +18,4 @@ def find_offset_and_key(self, archive: BinaryIO) -> Tuple[int, Optional[int]]:
return offset, key


versions: FrozenSet[Type[Version]] = frozenset({ALT1})
versions: Tuple[Type[Version], ...] = (ALT1,)
18 changes: 2 additions & 16 deletions unrpa/versions/rpa.py → unrpa/versions/official_rpa.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import FrozenSet, BinaryIO, Tuple, Optional, Type
from typing import BinaryIO, Tuple, Optional, Type

from unrpa.versions.version import ExtensionBasedVersion, HeaderBasedVersion, Version

Expand Down Expand Up @@ -38,18 +38,4 @@ def find_offset_and_key(self, archive: BinaryIO) -> Tuple[int, Optional[int]]:
return offset, key


class RPA32(HeaderBasedVersion):
"""A slightly custom variant of RPA-3.0."""

name = "RPA-3.2"
header = b"RPA-3.2"

def find_offset_and_key(self, archive: BinaryIO) -> Tuple[int, Optional[int]]:
line = archive.readline()
parts = line.split()
offset = int(parts[1], 16)
key = int(parts[3], 16)
return offset, key


versions: FrozenSet[Type[Version]] = frozenset({RPA1, RPA2, RPA3, RPA32})
versions: Tuple[Type[Version], ...] = (RPA1, RPA2, RPA3)
14 changes: 14 additions & 0 deletions unrpa/versions/unofficial_rpa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Tuple, Type

from unrpa.versions.version import Version
from unrpa.versions.official_rpa import RPA3


class RPA32(RPA3):
"""A slightly custom variant of RPA-3.0."""

name = "RPA-3.2"
header = b"RPA-3.2"


versions: Tuple[Type[Version], ...] = (RPA32,)
4 changes: 2 additions & 2 deletions unrpa/versions/zix.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import re
import struct
from typing import BinaryIO, Tuple, Optional, FrozenSet, Type
from typing import BinaryIO, Tuple, Optional, Type

from unrpa.versions.errors import (
VersionSpecificRequirementUnmetError,
Expand Down Expand Up @@ -90,7 +90,7 @@ def postprocess(self, source: ArchiveView, sink: BinaryIO) -> None:
sink.write(segment)


versions: FrozenSet[Type[Version]] = frozenset({ZiX12A, ZiX12B})
versions: Tuple[Type[Version], ...] = (ZiX12A, ZiX12B)


class LoaderRequiredError(VersionSpecificRequirementUnmetError):
Expand Down

0 comments on commit d6192a3

Please sign in to comment.