-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Verify checksum after download #73
Comments
Without previous knowledge of Python and without a working installation this is what I came up with. def download(argv=None):
if argv is None:
argv = sys.argv[1:]
parser = argparse.ArgumentParser(description='Download a file from Jottacloud.')
parser.add_argument('remotefile', help='The path to the file that you want to download')
parser.add_argument('-l', '--loglevel', help='Logging level. Default: %(default)s.',
choices=('debug', 'info', 'warning', 'error'), default='warning')
parser.add_argument('-c', '--checksum', help='Verfy checksum of file after download')
args = parse_args_and_apply_logging_level(parser, argv)
jfs = JFS.JFS()
root_folder = get_root_dir(jfs)
path_to_object = posixpath.join(root_folder.path, args.remotefile)
remote_file = jfs.getObject(path_to_object)
total_size = remote_file.size
with open(remote_file.name, 'wb') as fh:
bytes_read = 0
with ProgressBar(expected_size=total_size) as bar:
for chunk_num, chunk in enumerate(remote_file.stream()):
fh.write(chunk)
bytes_read += len(chunk)
bar.show(bytes_read)
if args.checksum:
md5 = JFS.calculate_md5(data)
if md5 != JFSFile.md5:
print ('''MD5 hashes don't match!''')
answer = input('Continue: [y/n]')
if not answer or answer[0].lower() != 'y':
print('%s was not downloaded successfully' % args.remotefile')
exit(1)
print('%s downloaded successfully' % args.remotefile) |
That's not that bad for something you wrote without knowing the language. But you'll see some issues once you get your installation running (get it straight from github). So get that going, and then keep on coding :) Here's some things I see immediately
|
So there are some progress, but got stuck at an error which I couldn't figure out how to fix (commenting out the for loop in calculate_md5 removes the error).
I'm not sure that the way I am accessing the local file are the best. I'm also struggling getting the md5 property from the remote file. Would be nice with a hint in the right direction. =)
|
I think the first error is related to issue #79. Will see if the result there fixes the issue. |
After you
And take it from there. 👍 |
I've been trying to get it to work but the checksum doesn't seem to be correct. Not sure this is a issue that's related to using it under windows or not but. Anyway, below is the code in Cli.py. with open(remote_file.name, 'wb') as fh:
bytes_read = 0
with ProgressBar(expected_size=total_size) as bar:
for chunk_num, chunk in enumerate(remote_file.stream()):
fh.write(chunk)
bytes_read += len(chunk)
bar.show(bytes_read)
#if args.checksum:
md5_lf = JFS.calculate_md5(open(remote_file.name, 'rb')) #opening in binary mode
md5_jf = remote_file.md5
print md5_lf
print md5_jf
print('%s downloaded successfully' % args.remotefile) The checksum i get is:
Checking the file in an external md5 checker (http://onlinemd5.com/) gives the value of: Also doing a File content when opened in notepad:
File content when doing
|
Sorry, got it to work! How do I go forward and suggest the new code (first time I use github)? |
I think I need to rewrite some of the code that was proposed in the version i submitted since there has been quite a lot of changes and fixes since I wrote the code in the first place. Any help is appriciated. |
Via private email, the suggestion was raised that our tools could automatically verify the content after download, by comparing the md5 checksum from jottacloud and that of the newly downloaded file.
Sounds like a nice command line option for
download()
incli.py
.This would be a nice way to get the know the codebase for beginners.
The text was updated successfully, but these errors were encountered: