diff options
author | Florian Weimer <fw@deneb.enyo.de> | 2005-09-13 07:45:17 +0000 |
---|---|---|
committer | Florian Weimer <fw@deneb.enyo.de> | 2005-09-13 07:45:17 +0000 |
commit | 5f31eb4618a81913e6d3ef0663b98c8b83162214 (patch) | |
tree | f3e619bcd3b3eff5b3c0197c6396c2b57d1805a7 | |
parent | a7f76364bc3ffa5970d83692ff5b7337d92ce540 (diff) |
bin/apt-update-file:
Remove unnecessary import.
lib/python/debian_support.py (listReleases):
Add "sid".
(replaceFile):
Remove temporary file on exception.
(updateFile):
The file constructor raises IOError if the file does not exist.
urllib does not raise a proper exception on 4xx errors.
Handle varying whitespace in SHA1-Current field.
git-svn-id: svn+ssh://svn.debian.org/svn/secure-testing@1943 e39458fd-73e7-0310-bf30-c45bca0a0e42
-rwxr-xr-x | bin/apt-update-file | 1 | ||||
-rw-r--r-- | lib/python/debian_support.py | 45 |
2 files changed, 35 insertions, 11 deletions
diff --git a/bin/apt-update-file b/bin/apt-update-file index f424195b34..3971fdaa9a 100755 --- a/bin/apt-update-file +++ b/bin/apt-update-file @@ -20,7 +20,6 @@ def setup_paths(): path = path[0:idx] root_path = setup_paths() -import bugs import debian_support if len(sys.argv) <> 3: diff --git a/lib/python/debian_support.py b/lib/python/debian_support.py index 01515fdf0e..980a38a5be 100644 --- a/lib/python/debian_support.py +++ b/lib/python/debian_support.py @@ -179,7 +179,7 @@ class Release(PseudoEnum): pass def listReleases(): releases = {} - rels = ("woody", "sarge", "etch") + rels = ("woody", "sarge", "etch", "sid") for r in range(len(rels)): releases[rels[r]] = Release(rels[r], r) Release.releases = releases @@ -254,11 +254,20 @@ def patchLines(lines, patches): lines[first:last] = args def replaceFile(lines, local): - new_file = file(local + '.new', 'w+') - for l in lines: - new_file.write(l) - new_file.close() - os.rename(local + '.new', local) + + import os.path + + local_new = local + '.new' + new_file = file(local_new, 'w+') + + try: + for l in lines: + new_file.write(l) + new_file.close() + os.rename(local_new, local) + finally: + if os.path.exists(local_new): + os.unlink(local_new) def downloadGunzipLines(remote): """Downloads a file from a remote location and gunzips it. @@ -302,7 +311,9 @@ def updateFile(remote, local, verbose=None): try: local_file = file(local) - except OSError: + except IOError: + if verbose: + print "updateFile: no local copy, downloading full file" return downloadFile(remote, local) lines = local_file.readlines() @@ -315,11 +326,25 @@ def updateFile(remote, local, verbose=None): index_name = remote + '.diff/Index' re_whitespace=re.compile('\s+') - - for fields in PackageFile(index_name, urllib.urlopen(index_name)): + + try: + index_url = urllib.urlopen(index_name) + index_fields = list(PackageFile(index_name, index_url)) + except ParseError: + # FIXME: urllib does not raise a proper exception, so we parse + # the error message. + if verbose: + print "updateFile: could not interpret patch index file" + return downloadFile(remote, local) + except IOError: + if verbose: + print "updateFile: could not download patch index file" + return downloadFile(remote, local) + + for fields in index_fields: for (field, value) in fields: if field == 'SHA1-Current': - (remote_hash, remote_size) = value.split(' ') + (remote_hash, remote_size) = re_whitespace.split(value) if local_hash == remote_hash: if verbose: print "updateFile: local file is up-to-date" |