-
Notifications
You must be signed in to change notification settings - Fork 64
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
Primarily updates to add parameters which improve performance. #68
Open
slootsky
wants to merge
1
commit into
xtream1101:main
Choose a base branch
from
slootsky:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
__pycache__ | ||
*cookies.txt | ||
.tox/ | ||
build/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import sys | ||
import logging | ||
import argparse | ||
from humblebundle_downloader._version import __version__ | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -13,13 +14,47 @@ | |
# Ignore unwanted logs from the requests lib when debuging | ||
logging.getLogger('urllib3.connectionpool').setLevel(logging.WARNING) | ||
|
||
# convert a string representing size to an integer | ||
def parse_size(size): | ||
# Base10 unit definitions | ||
# K=x1000 M=x10000000 G=x1000000000 | ||
# units = {"K": 10**3, "M": 10**6, "G": 10**9, "T": 10**12} | ||
# Binary unit definitions: | ||
# K=x1024 M=x1024x1024 etc | ||
units = {"K": 2**10, "M": 2**20, "G": 2**30, "T": 2**40} | ||
try: | ||
return int(size) # if it's an int already just return it | ||
except ValueError: # it wasn't an int | ||
size=size.upper() | ||
if size.endswith('B'): | ||
return parse_size(size[:-1]) | ||
unit=size[-1:] | ||
number=size[:-1] | ||
if unit not in units.keys(): | ||
raise ValueError(f'Invalid Unit: {unit}') | ||
return int(float(number)*units[unit]) | ||
|
||
# convert a string represting time to an integer number of seconds | ||
def parse_seconds(size): | ||
# convert parameter to number of seconds | ||
units = {"S": 1, "M": 60, "H": 60*60, "D": 60*60*24, 'W': 60*60*24*7} | ||
try: | ||
return int(size) # if it's an int already just return it | ||
except ValueError: # it wasn't an int | ||
size=size.upper() | ||
unit=size[-1:] | ||
number=size[:-1] | ||
if unit not in units.keys(): | ||
raise ValueError(f'Invalid Unit: {unit}') | ||
return int(float(number)*units[unit]) | ||
|
||
def parse_args(args): | ||
if args[0].lower() == 'download': | ||
if ((len(args)>0) and (args[0].lower() == 'download')): | ||
args = args[1:] | ||
raise DeprecationWarning("`download` argument is no longer used") | ||
|
||
parser = argparse.ArgumentParser() | ||
parser = argparse.ArgumentParser(description='Download purchases from Humble Bundle', | ||
epilog=f'Version: {__version__}') | ||
|
||
cookie = parser.add_mutually_exclusive_group(required=True) | ||
cookie.add_argument( | ||
|
@@ -73,6 +108,32 @@ def parse_args(args): | |
help=("The purchase download key. Find in the url on the " | ||
"products/bundle download page. Can set multiple"), | ||
) | ||
parser.add_argument( | ||
'-b', '--write-buffer', | ||
type=str, default=1024*1024, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this the only argument with a default set here while all the others are set in the download_library.py init? |
||
help="Size of file buffer to use" | ||
) | ||
parser.add_argument( | ||
'--chunk_size','--chunk', | ||
type=str, | ||
help='Download Chunk Size' | ||
) | ||
parser.add_argument( | ||
'--timeout', | ||
type=str, | ||
help='Timeout (in seconds) for get requests' | ||
) | ||
parser.add_argument( | ||
'--debug', | ||
action='store_true', | ||
help='Run in Debug Mode. Stops on Exceptions' | ||
) | ||
parser.add_argument( | ||
'--keep', | ||
action='store_true', | ||
help='Keep files that fail download (ie: do not delete on failure)' | ||
) | ||
|
||
|
||
return parser.parse_args(args) | ||
|
||
|
@@ -92,4 +153,9 @@ def cli(): | |
purchase_keys=cli_args.keys, | ||
trove=cli_args.trove, | ||
update=cli_args.update, | ||
write_buffer=parse_size(cli_args.write_buffer), | ||
chunk_size=parse_size(cli_args.chunk_size), | ||
timeout=parse_seconds(cli_args.timeout), | ||
debug=cli_args.debug, | ||
keep=cli_args.keep, | ||
).start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://pypi.org/project/humanfriendly/ is a library option for this functionality