Add CLI option --progressbar.

This commit is contained in:
Jim Miller 2017-04-05 12:44:51 -05:00
parent 06aebc1707
commit 10aadfb907
3 changed files with 18 additions and 0 deletions

View file

@ -131,6 +131,9 @@ def main(argv=None,
parser.add_option('-d', '--debug',
action='store_true', dest='debug',
help='Show debug and notice output.', )
parser.add_option('-p', '--progressbar',
action='store_true', dest='progressbar',
help='Display a simple progress bar while downloading--one dot(.) per network fetch.', )
parser.add_option('-v', '--version',
action='store_true', dest='version',
help='Display version and quit.', )
@ -462,6 +465,9 @@ def get_configuration(url,
(var, val) = opt.split('=')
configuration.set('overrides', var, val)
if options.progressbar:
configuration.set('overrides','progressbar','true')
return configuration
if __name__ == '__main__':

View file

@ -22,6 +22,7 @@ from ConfigParser import DEFAULTSECT, MissingSectionHeaderError, ParsingError
import time
import logging
import sys
import urllib
import urllib2 as u2
import urlparse as up
@ -913,6 +914,11 @@ class Configuration(ConfigParser.SafeConfigParser):
logger.info("Could not decode story, tried:%s Stripping non-ASCII."%decode)
return "".join([x for x in data if ord(x) < 128])
def _progressbar(self):
if self.getConfig('progressbar'):
sys.stdout.write('.')
sys.stdout.flush()
# Assumes application/x-www-form-urlencoded. parameters, headers are dict()s
def _postUrl(self, url,
parameters={},
@ -951,6 +957,7 @@ class Configuration(ConfigParser.SafeConfigParser):
('X-Clacks-Overhead','GNU Terry Pratchett')]
data = self._decode(self.opener.open(req,None,float(self.getConfig('connect_timeout',30.0))).read())
self._progressbar()
self._set_to_pagecache(cachekey,data,url)
return data
@ -1003,6 +1010,7 @@ class Configuration(ConfigParser.SafeConfigParser):
opened = self.opener.open(url.replace(' ','%20'),urllib.urlencode(parameters),float(self.getConfig('connect_timeout',30.0)))
else:
opened = self.opener.open(url.replace(' ','%20'),None,float(self.getConfig('connect_timeout',30.0)))
self._progressbar()
data = opened.read()
self._set_to_pagecache(cachekey,data,opened.url)

View file

@ -199,6 +199,10 @@ connect_timeout:60.0
## each metadata item passed to post_process_cmd before it's called.
#post_process_safepattern:(^\.|/\.|[^a-zA-Z0-9_\. \[\]\(\)&'-]+)
## For use only with CLI version--display a simple progress bar while
## downloading--one dot(.) per network fetch. Same as using --progressbar
#progressbar:false
## Use regular expressions to find and replace (or remove) metadata.
## For example, you could change Sci-Fi=>SF, remove *-Centered tags,
## etc. See http://docs.python.org/library/re.html (look for re.sub)