diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2019-05-16 08:30:45 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2019-05-16 08:30:45 -0300 |
commit | d94457aa7f882c7f38af6e271737679935d782ce (patch) | |
tree | 66529a051734d8f634112d7e73543352ee7d0e43 | |
parent | bc11bb55f4b3affa6c6dee16e6a8b5ff9d3cd627 (diff) | |
download | ckandumper-d94457aa7f882c7f38af6e271737679935d782ce.tar.gz ckandumper-d94457aa7f882c7f38af6e271737679935d782ce.tar.bz2 |
Basic exception handling
-rwxr-xr-x | ckandumper | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -30,7 +30,7 @@ class DownloadMultiple: def __init__(self, limit_rate, limit_concurrent = 20, progress = True, debug = False, wget = '/usr/bin/wget'): if not os.path.exists(wget): - raise FileNotFoundError('Wget not found in your path; please install it first.') + raise FileNotFoundError('Wget not found in path ' + wget + '; please install it first.') self.limit_rate = limit_rate self.limit_concurrent = asyncio.Semaphore(int(limit_concurrent)) @@ -59,8 +59,8 @@ class DownloadMultiple: self.ensuredir(os.path.dirname(local_filename)); - # Other opts: -q --show-progress - cmd = self.wget + ' ' + self.limit_rate + ' -q --show-progress --progress=dot -c -O "' + local_filename + '" ' + url + # Other opts: -q --show-progress -O + cmd = self.wget + ' ' + self.limit_rate + ' -c -O "' + local_filename + '" ' + url proc = await asyncio.create_subprocess_shell(cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) @@ -68,13 +68,25 @@ class DownloadMultiple: stdout, stderr = await proc.communicate() if stdout: + output = open(local_filename + '.stdout', 'w') + output.write(stdout.decode()) + output.close() + if self.debug: print(f'[stdout] {url} {stdout.decode()}') if stderr: + output = open(local_filename + '.stderr', 'w') + output.write(stderr.decode()) + output.close() + if self.debug: print(f'[stderr] {url} {stderr.decode()}') + output = open(local_filename + '.returncode', 'w') + output.write(str(proc.returncode)) + output.close() + if self.debug: print(f'[{cmd!r} exited with {proc.returncode}]') @@ -258,5 +270,9 @@ if __name__ == "__main__": args = parser.parse_args() # Dispatch - ckan = CkanDumper(args) - ckan.dump() + try: + ckan = CkanDumper(args) + ckan.dump() + except FileNotFoundError as e: + print(e) + exit(1) |