~leonardr/ubuntu-qa-tools/fix-api-usage

« back to all changes in this revision

Viewing changes to security-tools/fetch-buildlogs

  • Committer: Kees Cook
  • Date: 2010-03-30 18:24:38 UTC
  • Revision ID: kees@outflux.net-20100330182438-62h2riykkwspz8ur
convert to "version=1.0" syntax for LPlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#
5
5
# Copyright (C) 2009-2010, Canonical, Ltd.
6
6
# Author: Kees Cook <kees@ubuntu.com>
 
7
#
 
8
# TODO: handle not specifying pocket so we can just "get latest" of Release, Updates, Security
7
9
 
8
10
import sys, optparse, time, os, tempfile, subprocess, shutil, urllib2, glob
9
11
import lpl_common
83
85
        filename = os.path.basename(url)
84
86
    tmp = filename + '.downloading'
85
87
    print "\t%s ..." % (url)
86
 
    response = opener.open(url)
 
88
 
 
89
    tries = 0
 
90
    max_tries = 10
 
91
    while True:
 
92
        try:
 
93
            response = opener.open(url)
 
94
            break
 
95
        except urllib2.URLError, e:
 
96
            tries += 1
 
97
            if tries >= max_tries or (e.code != 502 and e.code != 504 and e.code != 500):
 
98
                print >>sys.stderr, "Failed (%d): %s" % (e.code, url)
 
99
                raise
 
100
 
 
101
            print >>sys.stderr, "Retrying (%d): %s" % (e.code, url)
 
102
            time.sleep(3)
 
103
 
87
104
    chunked_read(response, outfile=file(tmp,'w'))
88
105
    os.rename(tmp,filename)
89
106