Skip to content

Commit

Permalink
small fixes to fetch.py
Browse files Browse the repository at this point in the history
  • Loading branch information
numerodix committed Jun 27, 2008
1 parent 3e9bb24 commit e9464d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions fetch.py
Expand Up @@ -99,6 +99,8 @@ def __init__(self, mode=FETCH, url=None, filename=None):
self.totalsize = None
self.tries = os.environ.get("TRIES") or 2

self.started = False

urllib._urlopener = MyURLopener(self)

def log_url(self, status, error=False):
Expand Down Expand Up @@ -211,9 +213,14 @@ def throw_type_error(self):
def fetch_hook(self, blocknum, blocksize, totalsize):
self.download_size = blocknum * blocksize

if blocknum == 0:
self.timestamp = time.time()
if blocknum == 1:
self.started = True

#step = 12
step = 5
if blocknum % step == 0:
if blocknum > 0 and blocknum % step == 0:
t = time.time()
interval = t - self.timestamp
self.timestamp = t
Expand Down Expand Up @@ -268,7 +275,6 @@ def launch(self):
"""

try:
self.timestamp = time.time()
self.load_url()
except filetype.WrongFileTypeError:
self.write_progress(error="wrong type")
Expand Down Expand Up @@ -324,7 +330,8 @@ def launch(self):
if len(args) > 1:
filename = args[1]
else:
filename = urlrewrite.url_to_filename(url)
os.environ["ORIG_FILENAMES"] = os.environ.get("ORIG_FILENAMES") or str(True)
filename = io.safe_filename(urlrewrite.url_to_filename(url))
Fetcher(mode=Fetcher.FETCH, url=url, filename=filename).launch()
except filetype.WrongFileTypeError:
os.unlink(filename)
Expand Down
2 changes: 1 addition & 1 deletion urlrewrite.py
Expand Up @@ -67,7 +67,7 @@ def rewrite_urls(origin_url, urls):

def url_to_filename(url):
(scheme, netloc, path, query, _) = urlparse.urlsplit(url)
if os.environ.get("SHORT_FILENAMES"):
if os.environ.get("ORIG_FILENAMES"):
filename = os.path.basename(path)
else:
(path, ext) = os.path.splitext(path)
Expand Down

0 comments on commit e9464d6

Please sign in to comment.