From 5c14871416804d2fda8667e729e5fe90f4a5e2e8 Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Mon, 2 Aug 2010 15:37:48 +0200 Subject: [PATCH] syncpackage: Print propper error message if dsc file is malformed. --- debian/changelog | 3 ++- syncpackage | 39 ++++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/debian/changelog b/debian/changelog index d81e1e4..cf81cf0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,6 +18,7 @@ ubuntu-dev-tools (0.101) UNRELEASED; urgency=low version for debian versions that contain more than one dash. - Prepend script name to every output - Output every executed command in verbose mode + - Print propper error message if dsc file is malformed. * update-maintainer: Add a --quiet option. [ Michael Bienia ] @@ -28,7 +29,7 @@ ubuntu-dev-tools (0.101) UNRELEASED; urgency=low * requestsync: Fix bug where the variable 'hasLP' is not always set (lp: #607874). - -- Benjamin Drung Fri, 30 Jul 2010 03:51:02 +0200 + -- Benjamin Drung Mon, 02 Aug 2010 15:35:49 +0200 ubuntu-dev-tools (0.100) maverick; urgency=low diff --git a/syncpackage b/syncpackage index 4fa7293..726b045 100755 --- a/syncpackage +++ b/syncpackage @@ -19,6 +19,7 @@ # # ################################################################## +import debian.deb822 import debian.debian_support import hashlib import optparse @@ -130,27 +131,23 @@ def remove_signature(dscname, script_name=None, verbose=False): f.writelines(unsigned_file) f.close() -def dsc_getfiles(dsc): +def dsc_getfiles(dscurl): '''Return list of files in a .dsc file (excluding the .dsc file itself).''' - basepath = os.path.dirname(dsc) - f = urllib.urlopen(dsc) + basepath = os.path.dirname(dscurl) + dsc = debian.deb822.Dsc(urllib.urlopen(dscurl)) + + if 'Files' not in dsc: + print >> sys.stderr, "%s: Error: No Files field found in the dcs file. Please check %s!" % \ + (script_name, os.path.basename(dscurl)) + sys.exit(1) + files = [] - - # skip until 'Files:' - for l in f: - if l.strip() == 'Files:': - break - - for l in f: - if not l.startswith(' '): - break + for f in dcs['Files']: (checksum, size, fname) = l.split() - url = os.path.join(basepath, fname) - if not fname.endswith('.dsc'): - files.append(File(url, checksum, size)) - - f.close() + url = os.path.join(basepath, f['name']) + if not f['name'].endswith('.dsc'): + files.append(File(url, f['md5sum'], f['size'])) return files def add_fixed_bugs(changes, bugs, script_name=None, verbose=False): @@ -183,8 +180,12 @@ def sync_dsc(script_name, dscurl, debian_dist, release, name, email, bugs, keyid dscfile = dscurl else: urllib.urlretrieve(dscurl, dscname) - dscfile = open(dscname).readlines() - new_ver = Version(filter(lambda l: l.startswith("Version:"), dscfile)[0][8:].strip()) + dscfile = debian.deb822.Dsc(file(dscname)) + if "Version" not in dscfile: + print >> sys.stderr, "%s: Error: No Version field found in the dcs file. Please check %s!" % \ + (script_name, dscname) + sys.exit(1) + new_ver = Version(dscfile["Version"]) try: ubuntu_source = getUbuntuSrcPkg(srcpkg, release)