Skip to content

Commit

Permalink
Merge pull request #136 from alexpdev/dev
Browse files Browse the repository at this point in the history
Updated CLI main help message and usage message
  • Loading branch information
alexpdev authored Jun 6, 2022
2 parents 5e5f661 + 654b7eb commit fc5320f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 56 deletions.
12 changes: 6 additions & 6 deletions docs/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://alexpdev.github.io/torrentfile/</loc>
<lastmod>2022-06-05</lastmod>
<lastmod>2022-06-06</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://alexpdev.github.io/torrentfile/Apache2/</loc>
<lastmod>2022-06-05</lastmod>
<lastmod>2022-06-06</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://alexpdev.github.io/torrentfile/Commands/</loc>
<lastmod>2022-06-05</lastmod>
<lastmod>2022-06-06</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://alexpdev.github.io/torrentfile/changelog/</loc>
<lastmod>2022-06-05</lastmod>
<lastmod>2022-06-06</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://alexpdev.github.io/torrentfile/man/</loc>
<lastmod>2022-06-05</lastmod>
<lastmod>2022-06-06</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://alexpdev.github.io/torrentfile/source/</loc>
<lastmod>2022-06-05</lastmod>
<lastmod>2022-06-06</lastmod>
<changefreq>daily</changefreq>
</url>
</urlset>
Binary file modified docs/sitemap.xml.gz
Binary file not shown.
66 changes: 28 additions & 38 deletions torrentfile/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ def execute(args=None) -> list:
args = sys.argv[1:]
else:
args = ["-h"]

parser = ArgumentParser(
"torrentfile",
usage="torrentfile [options] command [command options]",
description=(
"Command line tools for creating, editing, checking and "
"interacting with Bittorrent metainfo files"
"Command line tools for creating, editing, checking, building "
"and interacting with Bittorrent metainfo files"
),
prefix_chars="-",
formatter_class=TorrentFileHelpFormatter,
Expand Down Expand Up @@ -211,9 +211,9 @@ def execute(args=None) -> list:
parser.set_defaults(func=parser.print_help)

subparsers = parser.add_subparsers(
title="Actions",
title="Commands",
dest="command",
metavar="create, edit, magnet, recheck, rebuild",
metavar="create, edit, info, magnet, recheck, rebuild\n",
)
create_parser = subparsers.add_parser(
"create",
Expand Down Expand Up @@ -346,9 +346,7 @@ def execute(args=None) -> list:

edit_parser = subparsers.add_parser(
"edit",
help="""
Edit existing torrent meta file.
""",
help="""Edit existing torrent meta file.""",
aliases=["e"],
prefix_chars="-",
formatter_class=TorrentFileHelpFormatter,
Expand Down Expand Up @@ -408,11 +406,24 @@ def execute(args=None) -> list:
)
edit_parser.set_defaults(func=edit)

info_parser = subparsers.add_parser(
"info",
help="Show detailed information about a torrent file.",
aliases=["i"],
prefix_chars="-",
formatter_class=TorrentFileHelpFormatter,
)
info_parser.add_argument(
"metafile",
action="store",
metavar="<*.torrent>",
help="path to pre-existing torrent file.",
)
info_parser.set_defaults(func=info)

magnet_parser = subparsers.add_parser(
"magnet",
help="""
Generate magnet url from an existing Bittorrent meta file.
""",
help="Generate magnet url from an existing Bittorrent meta file.",
aliases=["m"],
prefix_chars="-",
formatter_class=TorrentFileHelpFormatter,
Expand All @@ -427,10 +438,8 @@ def execute(args=None) -> list:

check_parser = subparsers.add_parser(
"recheck",
help="""
Calculate amount of torrent meta file's content is found on disk.
""",
aliases=["r", "check"],
help="Gives a detailed look at how much of the torrent is available.",
aliases=["check"],
prefix_chars="-",
formatter_class=TorrentFileHelpFormatter,
)
Expand All @@ -448,31 +457,12 @@ def execute(args=None) -> list:
)
check_parser.set_defaults(func=recheck)

info_parser = subparsers.add_parser(
"info",
help="""
Show detailed information about a torrent file.
""",
aliases=["i"],
prefix_chars="-",
formatter_class=TorrentFileHelpFormatter,
)
info_parser.add_argument(
"metafile",
action="store",
metavar="<*.torrent>",
help="path to pre-existing torrent file.",
)
info_parser.set_defaults(func=info)

rebuild_parser = subparsers.add_parser(
"rebuild",
aliases=["build", "b"],
help="""
Re-assemble files obtained from a bittorrent file into the
appropriate file structure for re-seeding. Read documentation
for more information, or use cases.
""",
aliases=["build"],
help="""Re-assemble files obtained from a bittorrent file into the
appropriate file structure for re-seeding. Read documentation
for more information, or use cases.""",
formatter_class=TorrentFileHelpFormatter,
)
rebuild_parser.add_argument(
Expand Down
15 changes: 3 additions & 12 deletions torrentfile/recheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@
import os
from hashlib import sha1, sha256 # nosec
from pathlib import Path
from threading import Thread

import pyben

from torrentfile.hasher import FileHasher
from torrentfile.mixins import ProgMixin, waiting
from torrentfile.mixins import ProgMixin
from torrentfile.utils import ArgumentError, MissingPathError

SHA1 = 20
Expand Down Expand Up @@ -86,22 +85,14 @@ def __init__(self, metafile: str, path: str):
raise ArgumentError(
"The <metafile> must be a .torrent file. Not a directory"
)
meta = []
thread = Thread(target=pyben.loadinto, args=(metafile, meta))
thread.start()
self.last_log = None
self.log_msg("Checking: %s, %s", metafile, path)
self.metafile = metafile
self.total = 0
self.paths = []
self.fileinfo = {}
thread2 = Thread(
target=waiting, args=("Extracting metadata", meta, 30)
)
if len(meta) == 0: # pragma: nocover
thread2.start()
thread.join()
self.meta = meta[0]
print("Extracting data from torrent file...")
self.meta = pyben.load(metafile)
self.info = self.meta["info"]
self.name = self.info["name"]
self.piece_length = self.info["piece length"]
Expand Down

0 comments on commit fc5320f

Please sign in to comment.