Skip to content

Commit 8867a5e

Browse files
authored
Merge pull request #99 from alexpdev/Fixes_#96
Fixes a couple of bugs mentioned is issues #96 and #98
2 parents ba6b9bf + 9e66205 commit 8867a5e

File tree

10 files changed

+242
-25
lines changed

10 files changed

+242
-25
lines changed

docs/objects.inv

11 Bytes
Binary file not shown.

docs/search/search_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/sitemap.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@
22
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
33
<url>
44
<loc>https://alexpdev.github.io/torrentfile/</loc>
5-
<lastmod>2022-03-08</lastmod>
5+
<lastmod>2022-03-17</lastmod>
66
<changefreq>daily</changefreq>
77
</url>
88
<url>
99
<loc>https://alexpdev.github.io/torrentfile/API/</loc>
10-
<lastmod>2022-03-08</lastmod>
10+
<lastmod>2022-03-17</lastmod>
1111
<changefreq>daily</changefreq>
1212
</url>
1313
<url>
1414
<loc>https://alexpdev.github.io/torrentfile/Commands/</loc>
15-
<lastmod>2022-03-08</lastmod>
15+
<lastmod>2022-03-17</lastmod>
1616
<changefreq>daily</changefreq>
1717
</url>
1818
<url>
1919
<loc>https://alexpdev.github.io/torrentfile/LGPLv3/</loc>
20-
<lastmod>2022-03-08</lastmod>
20+
<lastmod>2022-03-17</lastmod>
2121
<changefreq>daily</changefreq>
2222
</url>
2323
<url>
2424
<loc>https://alexpdev.github.io/torrentfile/changelog/</loc>
25-
<lastmod>2022-03-08</lastmod>
25+
<lastmod>2022-03-17</lastmod>
2626
<changefreq>daily</changefreq>
2727
</url>
2828
<url>
2929
<loc>https://alexpdev.github.io/torrentfile/examples/</loc>
30-
<lastmod>2022-03-08</lastmod>
30+
<lastmod>2022-03-17</lastmod>
3131
<changefreq>daily</changefreq>
3232
</url>
3333
<url>
3434
<loc>https://alexpdev.github.io/torrentfile/source/</loc>
35-
<lastmod>2022-03-08</lastmod>
35+
<lastmod>2022-03-17</lastmod>
3636
<changefreq>daily</changefreq>
3737
</url>
3838
</urlset>

docs/sitemap.xml.gz

0 Bytes
Binary file not shown.

docs/source/index.html

Lines changed: 181 additions & 12 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "torrentfile",
33
"displayName": "TorrentFile",
4-
"version": "0.6.12",
4+
"version": "0.6.13",
55
"description": "Create Bittorent v1, v2 and hybrid meta files.",
66
"repository": {
77
"type": "git",

tests/test_cli.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,3 +407,34 @@ def test_cli_subprocess(dir2):
407407
rmpath(out)
408408
else: # pragma: nocover
409409
assert os.environ.get("GITHUB_WORKFLOW")
410+
411+
412+
@pytest.mark.parametrize("ending", ["/", "\\"])
413+
def test_cli_slash_path(dir2, ending):
414+
"""
415+
Test if output when path ends with a /.
416+
"""
417+
if sys.platform != "win32" and ending == "\\": # pragma: nocover
418+
ending = "/"
419+
args = [
420+
"torrentfile",
421+
"create",
422+
"-t",
423+
"https://announce1.org",
424+
"--private",
425+
str(dir2) + ending,
426+
]
427+
sys.argv = args
428+
main()
429+
assert os.path.exists(str(dir2) + ".torrent")
430+
431+
432+
@pytest.mark.parametrize("flag", ["-t", "-w", "-a"])
433+
def test_cli_announce_path(dir2, flag):
434+
"""
435+
Test CLI when path is placed after the trackers flag.
436+
"""
437+
args = ["torrentfile", "create", flag, "https://announce1.org", str(dir2)]
438+
sys.argv = args
439+
main()
440+
assert os.path.exists(str(dir2) + ".torrent")

torrentfile/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def execute(args=None):
321321
"content",
322322
action="store",
323323
metavar="<content>",
324+
nargs="?",
324325
help="Path to content file or directory",
325326
)
326327

torrentfile/torrent.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,16 @@ def __init__(self, path=None, announce=None, private=False,
242242
Construct MetaFile superclass and assign local attributes.
243243
"""
244244
if not path:
245-
raise utils.MissingPathError
245+
found = False
246+
if announce or url_list:
247+
if announce and os.path.exists(announce[-1]):
248+
path = announce.pop()
249+
found = True
250+
elif url_list and os.path.exists(url_list[-1]):
251+
path = url_list.pop()
252+
found = True
253+
if not found:
254+
raise utils.MissingPathError
246255

247256
# base path to torrent content.
248257
self.path = path
@@ -276,6 +285,7 @@ def __init__(self, path=None, announce=None, private=False,
276285
self.comment = comment
277286
self.url_list = url_list
278287
self.source = source
288+
279289
self.meta = {
280290
"announce": self.announce,
281291
"announce-list": self.announce_list,
@@ -292,8 +302,13 @@ def __init__(self, path=None, announce=None, private=False,
292302
self.meta["info"]["source"] = source
293303
if url_list:
294304
self.meta["url-list"] = url_list
295-
self.meta["info"]["name"] = os.path.basename(self.path)
296305
self.meta["info"]["piece length"] = self.piece_length
306+
307+
parent, name = os.path.split(self.path)
308+
if not name:
309+
name = os.path.basename(parent)
310+
self.meta["info"]["name"] = name
311+
297312
# fmt: on
298313

299314
def assemble(self):
@@ -334,7 +349,8 @@ def write(self, outfile=None) -> tuple:
334349
self.outfile = outfile
335350

336351
if self.outfile is None:
337-
self.outfile = str(self.path) + ".torrent"
352+
path = str(self.path).rstrip("\\/")
353+
self.outfile = path + ".torrent"
338354

339355
self.meta = self.sort_meta()
340356
pyben.dump(self.meta, self.outfile)

torrentfile/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
Holds the release version number.
1616
"""
1717

18-
__version__ = "0.6.12"
18+
__version__ = "0.6.13"

0 commit comments

Comments
 (0)