Skip to content

Commit

Permalink
TEMPORARY COMMIT - DO NOT MERGE
Browse files Browse the repository at this point in the history
  • Loading branch information
JockeTF committed Dec 11, 2024
1 parent 42f1023 commit 017cb59
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fimfarchive/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from .base import Command
from .build import BuildCommand
from .check import CheckCommand
from .root import RootCommand
from .update import UpdateCommand

Expand All @@ -32,5 +33,6 @@
'Command',
'RootCommand',
'BuildCommand',
'CheckCommand',
'UpdateCommand',
)
62 changes: 62 additions & 0 deletions fimfarchive/commands/check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
Check command.
"""


#
# Fimfarchive, preserves stories from Fimfiction.
# Copyright (C) 2024 Joakim Soderlund
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#


from argparse import ArgumentParser
from io import BytesIO
from zipfile import ZipFile

from fimfarchive.fetchers import FimfarchiveFetcher
from fimfarchive.utils import tqdm

from .base import Command


class CheckCommand(Command):
"""
Checks archive and story integrity.
"""

@property
def parser(self) -> ArgumentParser:
"""
Returns a command line arguments parser.
"""
parser = ArgumentParser(prog='', description=self.__doc__)
parser.add_argument('archive', help="file to check")

return parser

def __call__(self, *args: str) -> int:
opts = self.parser.parse_args(args)
fetcher = FimfarchiveFetcher(opts.archive)

if fetcher.archive.testzip() is not None:
exit("Invalid CRC: Archive")

for story in tqdm(fetcher, leave=True):
with ZipFile(BytesIO(story.data)) as zobj:
if zobj.testzip() is not None:
exit(f"Invalid CRC: {story.key}")

return 0
2 changes: 2 additions & 0 deletions fimfarchive/commands/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from .base import Command
from .build import BuildCommand
from .check import CheckCommand
from .update import UpdateCommand


Expand All @@ -40,6 +41,7 @@ class RootCommand(Command):
"""
commands: Dict[str, Type[Command]] = {
'build': BuildCommand,
'check': CheckCommand,
'update': UpdateCommand,
}

Expand Down

0 comments on commit 017cb59

Please sign in to comment.