Add more checks for --min/max-sleep-interval arguments and use more idiomatic naming
This commit is contained in:
parent
7aa589a5e1
commit
1ad6b891b2
@ -147,10 +147,14 @@ def _real_main(argv=None):
|
|||||||
opts.max_filesize = numeric_limit
|
opts.max_filesize = numeric_limit
|
||||||
if opts.sleep_interval is not None:
|
if opts.sleep_interval is not None:
|
||||||
if opts.sleep_interval < 0:
|
if opts.sleep_interval < 0:
|
||||||
parser.error('sleep interval should not be negative')
|
parser.error('sleep interval must be positive or 0')
|
||||||
elif opts.max_sleep_interval is not None:
|
if opts.max_sleep_interval is not None:
|
||||||
if opts.max_sleep_interval < opts.sleep_interval:
|
if opts.max_sleep_interval < 0:
|
||||||
parser.error('max sleep interval should not be less than sleep interval')
|
parser.error('max sleep interval must be positive or 0')
|
||||||
|
if opts.max_sleep_interval < opts.sleep_interval:
|
||||||
|
parser.error('max sleep interval must be greater than or equal to min sleep interval')
|
||||||
|
else:
|
||||||
|
opts.max_sleep_interval = opts.sleep_interval
|
||||||
|
|
||||||
def parse_retries(retries):
|
def parse_retries(retries):
|
||||||
if retries in ('inf', 'infinite'):
|
if retries in ('inf', 'infinite'):
|
||||||
|
@ -343,10 +343,11 @@ class FileDownloader(object):
|
|||||||
})
|
})
|
||||||
return True
|
return True
|
||||||
|
|
||||||
sleep_lower_bound = self.params.get('sleep_interval')
|
min_sleep_interval = self.params.get('sleep_interval')
|
||||||
if sleep_lower_bound:
|
if min_sleep_interval:
|
||||||
sleep_upper_bound = self.params.get('max_sleep_interval', sleep_lower_bound)
|
max_sleep_interval = self.params.get('max_sleep_interval', min_sleep_interval)
|
||||||
sleep_interval = random.uniform(sleep_lower_bound, sleep_upper_bound)
|
print(min_sleep_interval, max_sleep_interval)
|
||||||
|
sleep_interval = random.uniform(min_sleep_interval, max_sleep_interval)
|
||||||
self.to_screen('[download] Sleeping %s seconds...' % sleep_interval)
|
self.to_screen('[download] Sleeping %s seconds...' % sleep_interval)
|
||||||
time.sleep(sleep_interval)
|
time.sleep(sleep_interval)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user