Author: fw Date: 2005-09-13 07:45:17 +0000 (Tue, 13 Sep 2005) New Revision: 1943 Modified: bin/apt-update-file lib/python/debian_support.py Log: 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. Modified: bin/apt-update-file ==================================================================--- bin/apt-update-file 2005-09-12 21:14:17 UTC (rev 1942) +++ bin/apt-update-file 2005-09-13 07:45:17 UTC (rev 1943) @@ -20,7 +20,6 @@ path = path[0:idx] root_path = setup_paths() -import bugs import debian_support if len(sys.argv) <> 3: Modified: lib/python/debian_support.py ==================================================================--- lib/python/debian_support.py 2005-09-12 21:14:17 UTC (rev 1942) +++ lib/python/debian_support.py 2005-09-13 07:45:17 UTC (rev 1943) @@ -179,7 +179,7 @@ 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,12 +254,21 @@ 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 @@ 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 @@ 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"