Skip to content

Commit

Permalink
Version 1.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
kz26 committed Nov 3, 2016
1 parent a991b44 commit 71e4d94
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

1.5.3
-----
* Use relative paths instead of absolute paths for directory mode path generation
* Add invalid input path check in get_info() and generate()

1.5.2
-----
* Use humanfriendly.format_size in binary mode
Expand Down
2 changes: 1 addition & 1 deletion docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ available in your system path.
--md5 Add per-file MD5 hashes
--verbose, -v verbose mode

dottorrent/1.5.1 (https://github.com/kz26/dottorrent)
dottorrent/1.5.3 (https://github.com/kz26/dottorrent)



Expand Down
13 changes: 9 additions & 4 deletions dottorrent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def get_info(self):
if os.path.isfile(self.path):
total_size = os.path.getsize(self.path)
total_files = 1
else:
elif os.path.exists(self.path):
total_size = 0
total_files = 0
for x in os.walk(self.path):
Expand All @@ -151,6 +151,8 @@ def get_info(self):
if fsize:
total_size += fsize
total_files += 1
else:
raise exceptions.InvalidInputException
if not (total_files and total_size):
raise exceptions.EmptyInputException
if self.piece_size:
Expand Down Expand Up @@ -179,13 +181,15 @@ def generate(self, callback=None):
single_file = os.path.isfile(self.path)
if single_file:
files.append((self.path, os.path.getsize(self.path), {}))
else:
elif os.path.exists(self.path):
for x in os.walk(self.path):
for fn in x[2]:
fpath = os.path.normpath(os.path.join(x[0], fn))
fsize = os.path.getsize(fpath)
if fsize:
files.append((fpath, fsize, {}))
else:
raise exceptions.InvalidInputException
total_size = sum([x[1] for x in files])
if not (len(files) and total_size):
raise exceptions.EmptyInputException
Expand Down Expand Up @@ -259,15 +263,16 @@ def generate(self, callback=None):
data['info']['name'] = files[0][0].split(os.sep)[-1].encode()
else:
data['info']['files'] = []
path_sp = self.path.split(os.sep)
for x in files:
fx = OrderedDict()
fx['length'] = x[1]
if self.include_md5:
fx['md5sum'] = x[2]['md5sum']
fx['path'] = [y.encode()
for y in x[0].split(os.sep)[1:]]
for y in x[0].split(os.sep)[len(path_sp):]]
data['info']['files'].append(fx)
data['info']['name'] = self.path.split(os.sep)[-1].encode()
data['info']['name'] = path_sp[-1].encode()
data['info']['pieces'] = bytes(self._pieces)
data['info']['piece length'] = self.piece_size
data['info']['private'] = int(self.private)
Expand Down
6 changes: 6 additions & 0 deletions dottorrent/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ def __init__(self, *args, **kwargs):
super().__init__('Input path must be non-empty')


class InvalidInputException(Exception):

def __init__(self, *args, **kwargs):
super().__init__('Input path is invalid')


class InvalidURLException(Exception):

def __init__(self, url, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion dottorrent/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.5.2'
__version__ = '1.5.3'

0 comments on commit 71e4d94

Please sign in to comment.