Skip to content

Commit

Permalink
Also skip creating progress bar in lstor/chtor
Browse files Browse the repository at this point in the history
  • Loading branch information
kannibalox committed Apr 17, 2024
1 parent bf780da commit bfd8448
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed
- `mktor`/`lstor`/`chtor`: No longer create the progress bar object at
all if not enabled. This should improve the scripting capabilities.

### Added
- `pyrotorque`: Add `preload_fields` to `TreeWatch` job, to allow
fetching expensive-but-cacheable fields right after a successfully
Expand Down
45 changes: 28 additions & 17 deletions src/pyrosimple/scripts/chtor.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,30 +261,41 @@ def mainloop(self) -> None:
continue

if self.options.check_data:
# pylint: disable=import-outside-toplevel
from pyrosimple.util.metafile import PieceLogger
from pyrosimple.util.ui import HashProgressBar, HashProgressBarCounter
try:
from pyrosimple.util.metafile import ( # pylint: disable=import-outside-toplevel
PieceFailer,
)

piece_logger = PieceFailer(torrent, self.log)

with HashProgressBar() as pb:
if self.options.progress == "on":
progress_callback = cast(
HashProgressBarCounter, pb()
).progress_callback
else:
progress_callback = None
# pylint: disable=import-outside-toplevel
from pyrosimple.util.ui import (
HashProgressBar,
HashProgressBarCounter,
)

piece_logger = PieceLogger(torrent, self.log)
with HashProgressBar() as pb:
progress_callback = cast(
HashProgressBarCounter, pb()
).progress_callback

data_correct = torrent.hash_check(
Path(self.options.check_data),
progress_callback=progress_callback,
piece_callback=piece_logger.check_piece,
)
if not data_correct:
torrent.hash_check(
Path(self.options.check_data),
progress_callback=progress_callback,
piece_callback=piece_logger.check_piece,
)
else:
torrent.hash_check(
Path(self.options.check_data),
piece_callback=piece_logger.check_piece,
)
except OSError as exc:
self.log.error(
"File %s does match data from %s",
"File %s does match data from %s: %s",
filename,
self.options.check_data,
exc,
)
sys.exit(error.EX_DATAERR)

Expand Down
16 changes: 10 additions & 6 deletions src/pyrosimple/scripts/lstor.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,24 @@ def splitter(fields):
self.return_code = EX_SOFTWARE
if self.options.check_data:
# pylint: disable=import-outside-toplevel

from pyrosimple.util.metafile import PieceFailer
from pyrosimple.util.ui import HashProgressBar

piece_logger = PieceFailer(torrent, self.log)
try:
with HashProgressBar() as pb:
if self.options.progress == "on":
if self.options.progress == "on":
with HashProgressBar() as pb:
progress_callback = pb().progress_callback
else:
progress_callback = None

piece_logger = PieceFailer(torrent, self.log)
torrent.hash_check(
Path(self.options.check_data),
progress_callback=progress_callback,
piece_callback=piece_logger.check_piece,
)
else:
torrent.hash_check(
Path(self.options.check_data),
progress_callback=progress_callback,
piece_callback=piece_logger.check_piece,
)
except OSError as exc:
Expand Down

0 comments on commit bfd8448

Please sign in to comment.