Skip to content

Commit

Permalink
fix: Fix Download.name and always init struct args to empty dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Aug 7, 2019
1 parent 75e16bd commit 874deb9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/aria2p/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def check_args(parser, args):
subparser[args.subcommand].error("the following arguments are required: gids or --all")
elif args.do_all and args.gids:
subparser[args.subcommand].error("argument -a/--all: not allowed with arguments gids")
elif args.subcommand.endswith("-all"):
elif (args.subcommand or "").endswith("-all"):
warnings.warn(
f"Subcommand '{args.subcommand}' is deprecated in favor of '{args.subcommand[:-4]} --all'.\n"
f"It will be removed in version 0.5.0, please update your scripts/code.",
Expand Down
13 changes: 9 additions & 4 deletions src/aria2p/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, struct):
Args:
struct (dict): a dictionary Python object returned by the JSON-RPC client.
"""
self._struct = struct
self._struct = struct or {}

def __str__(self):
return self.info["name"]
Expand Down Expand Up @@ -83,7 +83,7 @@ def __init__(self, struct):
Args:
struct (dict): a dictionary Python object returned by the JSON-RPC client.
"""
self._struct = struct
self._struct = struct or {}

def __str__(self):
return str(self.path)
Expand Down Expand Up @@ -182,7 +182,7 @@ def __init__(self, api, struct):
struct (dict): a dictionary Python object returned by the JSON-RPC client.
"""
self.api = api
self._struct = struct
self._struct = struct or {}
self._files = []
self._root_files_paths = []
self._bittorrent = None
Expand Down Expand Up @@ -220,7 +220,12 @@ def name(self):
if self.bittorrent and self.bittorrent.info:
self._name = self.bittorrent.info["name"]
else:
self._name = str(self.files[0].path.relative_to(self.dir))
file_path = str(self.files[0].path.absolute())
dir_path = str(self.dir.absolute())
if file_path.startswith(dir_path):
self._name = Path(file_path[len(dir_path)+1:]).parts[0]
else:
self._name = self.files[0].uris[0]["uri"].split("/")[-1]
return self._name

@property
Expand Down
2 changes: 1 addition & 1 deletion src/aria2p/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, api, struct, download=None):
"""
self.api = api
self.download = download
self._struct = struct
self._struct = struct or {}

@property
def are_global(self):
Expand Down
2 changes: 1 addition & 1 deletion src/aria2p/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, struct):
Args:
struct (dict): a dictionary Python object returned by the JSON-RPC client.
"""
self._struct = struct
self._struct = struct or {}

@property
def download_speed(self):
Expand Down

0 comments on commit 874deb9

Please sign in to comment.