syncpackage: Convert style to PEP 8.

This commit is contained in:
Benjamin Drung 2010-10-30 18:45:14 +02:00
parent b32dd85a63
commit b5b099424f

View File

@ -31,7 +31,7 @@ import sys
import urllib import urllib
# ubuntu-dev-tools modules # ubuntu-dev-tools modules
from ubuntutools.requestsync.mail import getDebianSrcPkg as ubuntutools_requestsync_mail_getDebianSrcPkg from ubuntutools.requestsync.mail import getDebianSrcPkg as requestsync_mail_getDebianSrcPkg
from ubuntutools.requestsync.lp import getDebianSrcPkg, getUbuntuSrcPkg from ubuntutools.requestsync.lp import getDebianSrcPkg, getUbuntuSrcPkg
from ubuntutools.lp import udtexceptions from ubuntutools.lp import udtexceptions
from ubuntutools.lp.lpapicache import Launchpad from ubuntutools.lp.lpapicache import Launchpad
@ -44,8 +44,8 @@ class File(object):
self.size = size self.size = size
def __repr__(self): def __repr__(self):
return self.name + " (" + self.checksum + " " + self.size + ") source " + \ return self.name + " (" + self.checksum + " " + self.size + \
str(bool(self.is_source_file())) ") source " + str(bool(self.is_source_file()))
def __eq__(self, other): def __eq__(self, other):
return self.name == other.name and self.checksum == other.checksum and \ return self.name == other.name and self.checksum == other.checksum and \
@ -76,8 +76,9 @@ class File(object):
try: try:
urllib.urlretrieve(self.url, self.name) urllib.urlretrieve(self.url, self.name)
except IOError as e: except IOError as e:
print >> sys.stderr, "%s: Error: Failed to download %s [Errno %i]: %s." % \ parameters = (script_name, self.name, e.errno, e.strerror)
(script_name, self.name, e.errno, e.strerror) print >> sys.stderr, ("%s: Error: Failed to download %s "
"[Errno %i]: %s.") % parameters
sys.exit(1) sys.exit(1)
@ -143,8 +144,9 @@ def dsc_getfiles(dscurl):
dsc = debian.deb822.Dsc(urllib.urlopen(dscurl)) dsc = debian.deb822.Dsc(urllib.urlopen(dscurl))
if 'Files' not in dsc: if 'Files' not in dsc:
print >> sys.stderr, "%s: Error: No Files field found in the dsc file. Please check %s!" % \ parameters = (script_name, os.path.basename(dscurl))
(script_name, os.path.basename(dscurl)) print >> sys.stderr, ("%s: Error: No Files field found in the dsc "
"file. Please check %s!") % parameters
sys.exit(1) sys.exit(1)
files = [] files = []
@ -173,7 +175,8 @@ def add_fixed_bugs(changes, bugs, script_name=None, verbose=False):
return "\n".join(changes + [""]) return "\n".join(changes + [""])
def sync_dsc(script_name, dscurl, debian_dist, release, name, email, bugs, keyid=None, verbose=False): def sync_dsc(script_name, dscurl, debian_dist, release, name, email, bugs,
keyid=None, verbose=False):
assert dscurl.endswith(".dsc") assert dscurl.endswith(".dsc")
dscname = os.path.basename(dscurl) dscname = os.path.basename(dscurl)
basepath = os.path.dirname(dscurl) basepath = os.path.dirname(dscurl)
@ -186,20 +189,22 @@ def sync_dsc(script_name, dscurl, debian_dist, release, name, email, bugs, keyid
try: try:
urllib.urlretrieve(dscurl, dscname) urllib.urlretrieve(dscurl, dscname)
except IOError as e: except IOError as e:
print >> sys.stderr, "%s: Error: Failed to download %s [Errno %i]: %s." % \ parameters = (script_name, dscname, e.errno, e.strerror)
(script_name, dscname, e.errno, e.strerror) print >> sys.stderr, ("%s: Error: Failed to download %s "
"[Errno %i]: %s.") % parameters
sys.exit(1) sys.exit(1)
dscfile = debian.deb822.Dsc(file(dscname)) dscfile = debian.deb822.Dsc(file(dscname))
if "Version" not in dscfile: if "Version" not in dscfile:
print >> sys.stderr, "%s: Error: No Version field found in the dsc file. Please check %s!" % \ print >> sys.stderr, ("%s: Error: No Version field found in the dsc "
(script_name, dscname) "file. Please check %s!") % (script_name, dscname)
sys.exit(1) sys.exit(1)
new_ver = Version(dscfile["Version"]) new_ver = Version(dscfile["Version"])
try: try:
ubuntu_source = getUbuntuSrcPkg(srcpkg, release) ubuntu_source = getUbuntuSrcPkg(srcpkg, release)
ubuntu_ver = Version(ubuntu_source.getVersion()) ubuntu_ver = Version(ubuntu_source.getVersion())
ubuntu_dsc = filter(lambda f: f.endswith(".dsc"), ubuntu_source.sourceFileUrls()) ubuntu_dsc = filter(lambda f: f.endswith(".dsc"),
ubuntu_source.sourceFileUrls())
assert len(ubuntu_dsc) == 1 assert len(ubuntu_dsc) == 1
ubuntu_dsc = ubuntu_dsc[0] ubuntu_dsc = ubuntu_dsc[0]
except udtexceptions.PackageNotFoundException: except udtexceptions.PackageNotFoundException:
@ -208,8 +213,8 @@ def sync_dsc(script_name, dscurl, debian_dist, release, name, email, bugs, keyid
# No need to continue if version is not greater than current one # No need to continue if version is not greater than current one
if new_ver <= ubuntu_ver: if new_ver <= ubuntu_ver:
raise Exception('%s version %s is not greater than already available %s' % \ raise Exception('%s version %s is not greater than already available '
(srcpkg, new_ver, ubuntu_ver)) '%s' % (srcpkg, new_ver, ubuntu_ver))
if verbose: if verbose:
print '%s: D: Source %s: current version %s, new version %s' % \ print '%s: D: Source %s: current version %s, new version %s' % \
(script_name, srcpkg, ubuntu_ver, new_ver) (script_name, srcpkg, ubuntu_ver, new_ver)
@ -217,8 +222,10 @@ def sync_dsc(script_name, dscurl, debian_dist, release, name, email, bugs, keyid
files = dsc_getfiles(dscurl) files = dsc_getfiles(dscurl)
source_files = filter(lambda f: f.is_source_file(), files) source_files = filter(lambda f: f.is_source_file(), files)
if verbose: if verbose:
print '%s: D: Files: %s' % (script_name, str(map(lambda x: x.get_name(), files))) print '%s: D: Files: %s' % (script_name, str(map(lambda x: x.get_name(),
print '%s: D: Source files: %s' % (script_name, str(map(lambda x: x.get_name(), source_files))) files)))
print '%s: D: Source files: %s' % (script_name,
str(map(lambda x: x.get_name(), source_files)))
map(lambda f: f.download(verbose), files) map(lambda f: f.download(verbose), files)
if ubuntu_dsc is None: if ubuntu_dsc is None:
@ -233,28 +240,33 @@ def sync_dsc(script_name, dscurl, debian_dist, release, name, email, bugs, keyid
# We need to check if all .orig*.tar.* tarballs exist in Ubuntu # We need to check if all .orig*.tar.* tarballs exist in Ubuntu
need_orig = False need_orig = False
for source_file in source_files: for source_file in source_files:
ubuntu_file = filter(lambda f: f.get_name() == source_file.get_name(), ubuntu_files) ubuntu_file = filter(lambda f: f.get_name() == source_file.get_name(),
ubuntu_files)
if len(ubuntu_file) == 0: if len(ubuntu_file) == 0:
# The source file does not exist in Ubuntu # The source file does not exist in Ubuntu
if verbose: if verbose:
print "%s: I: %s does not exist in Ubuntu." % \ parameters = (script_name, source_file.get_name())
(script_name, source_file.get_name()) print "%s: I: %s does not exist in Ubuntu." % parameters
need_orig = True need_orig = True
elif not ubuntu_file[0] == source_file: elif not ubuntu_file[0] == source_file:
# The checksum of the files mismatch -> We need a fake sync # The checksum of the files mismatch -> We need a fake sync
print "%s: Warning: The checksum of the file %s mismatch. A fake sync is required." % \ parameters = (script_name, source_file.get_name())
(script_name, source_file.get_name()) print ("%s: Warning: The checksum of the file %s mismatch. "
"A fake sync is required.") % parameters
fakesync_files.append(ubuntu_file[0]) fakesync_files.append(ubuntu_file[0])
if verbose: if verbose:
print "%s: D: Ubuntu version: %s" % (script_name, ubuntu_file[0]) print "%s: D: Ubuntu version: %s" % (script_name,
print "%s: D: Debian version: %s" % (script_name, source_file) ubuntu_file[0])
print "%s: D: Debian version: %s" % (script_name,
source_file)
if verbose: if verbose:
print '%s: D: needs source tarball: %s' % (script_name, str(need_orig)) print '%s: D: needs source tarball: %s' % (script_name, str(need_orig))
cur_ver = ubuntu_ver.get_related_debian_version() cur_ver = ubuntu_ver.get_related_debian_version()
if ubuntu_ver.is_modified_in_ubuntu(): if ubuntu_ver.is_modified_in_ubuntu():
print '%s: Warning: Overwriting modified Ubuntu version %s, setting current version to %s' % \ params = (script_name, ubuntu_ver.full_version, cur_ver.full_version)
(script_name, ubuntu_ver.full_version, cur_ver.full_version) print ('%s: Warning: Overwriting modified Ubuntu version %s, '
'setting current version to %s') % params
# extract package # extract package
cmd = ['dpkg-source', '-x', dscname] cmd = ['dpkg-source', '-x', dscname]
@ -371,7 +383,7 @@ def get_debian_dscurl(package, dist, release, version=None, component=None):
ubuntu_version = Version('~') ubuntu_version = Version('~')
if ubuntu_version >= Version(debian_srcpkg.getVersion()): if ubuntu_version >= Version(debian_srcpkg.getVersion()):
# The LP importer is maybe out of date # The LP importer is maybe out of date
debian_srcpkg = ubuntutools_requestsync_mail_getDebianSrcPkg(package, dist) debian_srcpkg = requestsync_mail_getDebianSrcPkg(package, dist)
if version is None: if version is None:
version = Version(debian_srcpkg.getVersion()) version = Version(debian_srcpkg.getVersion())
@ -386,7 +398,8 @@ def get_debian_dscurl(package, dist, release, version=None, component=None):
group = package[0] group = package[0]
dsc_file = package + "_" + version.strip_epoch() + ".dsc" dsc_file = package + "_" + version.strip_epoch() + ".dsc"
dscurl = os.path.join("http://ftp.debian.org/debian/pool", component, group, package, dsc_file) dscurl = os.path.join("http://ftp.debian.org/debian/pool", component, group,
package, dsc_file)
return dscurl return dscurl
if __name__ == "__main__": if __name__ == "__main__":
@ -398,12 +411,12 @@ if __name__ == "__main__":
parser.add_option("-d", "--distribution", type="string", parser.add_option("-d", "--distribution", type="string",
dest="dist", default=None, dest="dist", default=None,
help="Debian distribution to sync from.") help="Debian distribution to sync from.")
parser.add_option("-r", "--release", parser.add_option("-r", "--release", dest="release", default=None,
help="Specify target Ubuntu release.", dest="release", default=None) help="Specify target Ubuntu release.")
parser.add_option("-V", "--debian-version", parser.add_option("-V", "--debian-version", dest="debversion", default=None,
help="Specify the version to sync from.", dest="debversion", default=None) help="Specify the version to sync from.")
parser.add_option("-c", "--component", parser.add_option("-c", "--component", dest="component", default=None,
help="Specify the Debian component to sync from.", dest="component", default=None) help="Specify the Debian component to sync from.")
parser.add_option("-v", "--verbose", help="print more information", parser.add_option("-v", "--verbose", help="print more information",
dest="verbose", action="store_true", default=False) dest="verbose", action="store_true", default=False)
parser.add_option("-n", "--uploader-name", dest="uploader_name", parser.add_option("-n", "--uploader-name", dest="uploader_name",
@ -411,11 +424,11 @@ if __name__ == "__main__":
"for this upload instead of evaluating DEBFULLNAME.", "for this upload instead of evaluating DEBFULLNAME.",
default=os.environ["DEBFULLNAME"]) default=os.environ["DEBFULLNAME"])
parser.add_option("-e", "--uploader-email", dest="uploader_email", parser.add_option("-e", "--uploader-email", dest="uploader_email",
help="Use UPLOADER_EMAIL as email address of the maintainer " help="Use UPLOADER_EMAIL as email address of the "
"for this upload instead of evaluating DEBEMAIL.", "maintainer for this upload instead of evaluating "
default = os.environ["DEBEMAIL"]) "DEBEMAIL.", default=os.environ["DEBEMAIL"])
parser.add_option("-k", "--key", dest="keyid", parser.add_option("-k", "--key", dest="keyid", default=None,
help="Specify the key ID to be used for signing.", default=None) help="Specify the key ID to be used for signing.")
parser.add_option('--dont-sign', dest='keyid', action='store_false', parser.add_option('--dont-sign', dest='keyid', action='store_false',
help='Do not sign the upload') help='Do not sign the upload')
parser.add_option("-b", "--bug", metavar="BUG", parser.add_option("-b", "--bug", metavar="BUG",
@ -425,18 +438,19 @@ if __name__ == "__main__":
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if len(args) == 0: if len(args) == 0:
print >> sys.stderr, "%s: Error: No .dsc URL/path or package name specified." % \ print >> sys.stderr, ("%s: Error: No .dsc URL/path or package name "
(script_name) "specified.") % (script_name)
sys.exit(1) sys.exit(1)
elif len(args) > 1: elif len(args) > 1:
print >> sys.stderr, "%s: Error: Multiple .dsc URLs/paths or package names specified: %s" % \ parameters = (script_name, ", ".join(args))
(script_name, ", ".join(args)) print >> sys.stderr, ("%s: Error: Multiple .dsc URLs/paths or "
"package names specified: %s") % parameters
sys.exit(1) sys.exit(1)
invalid_bug_numbers = filter(lambda x: not x.isdigit(), options.bugs) invalid_bug_numbers = filter(lambda x: not x.isdigit(), options.bugs)
if len(invalid_bug_numbers) > 0: if len(invalid_bug_numbers) > 0:
print >> sys.stderr, "%s: Error: Invalid bug number(s) specified: %s" % \ print >> sys.stderr, "%s: Error: Invalid bug number(s) specified: %s" \
(script_name, ", ".join(invalid_bug_numbers)) % (script_name, ", ".join(invalid_bug_numbers))
sys.exit(1) sys.exit(1)
Launchpad.login_anonymously() Launchpad.login_anonymously()
@ -447,14 +461,16 @@ if __name__ == "__main__":
dscurl = args[0] dscurl = args[0]
else: else:
if options.component not in (None, "main", "contrib", "non-free"): if options.component not in (None, "main", "contrib", "non-free"):
print >> sys.stderr, "%s: Error: %s is not a valid Debian component." \ parameters = (script_name, options.component)
" It should be one of main, contrib, or non-free." % \ print >> sys.stderr, ("%s: Error: %s is not a valid Debian "
(script_name, options.component) "component. It should be one of main, "
"contrib, or non-free.") % parameters
sys.exit(1) sys.exit(1)
dscurl = get_debian_dscurl(args[0], options.dist, options.release, dscurl = get_debian_dscurl(args[0], options.dist, options.release,
options.debversion, options.component) options.debversion, options.component)
if options.verbose: if options.verbose:
print "%s: D: .dsc url: %s" % (script_name, dscurl) print "%s: D: .dsc url: %s" % (script_name, dscurl)
sync_dsc(script_name, dscurl, options.dist, options.release, options.uploader_name, sync_dsc(script_name, dscurl, options.dist, options.release,
options.uploader_email, options.bugs, options.keyid, options.verbose) options.uploader_name, options.uploader_email, options.bugs,
options.keyid, options.verbose)