From 1c814c8ec6de63ab220860fce5a8e663c685ab3d Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Sat, 10 Sep 2011 15:42:40 +0200 Subject: [PATCH] ubuntutools/requestsync: Follow PEP 8 naming conventions. --- debian/changelog | 5 +++- requestsync | 46 +++++++++++++++---------------- syncpackage | 24 ++++++++-------- ubuntutools/requestsync/common.py | 6 ++-- ubuntutools/requestsync/lp.py | 22 +++++++-------- ubuntutools/requestsync/mail.py | 38 ++++++++++++------------- 6 files changed, 72 insertions(+), 69 deletions(-) diff --git a/debian/changelog b/debian/changelog index 2f24565..243a64c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -35,7 +35,10 @@ ubuntu-dev-tools (0.131) UNRELEASED; urgency=low [ Colin Watson ] * syncpackage: Fix typo. - -- Stefano Rivera Thu, 08 Sep 2011 23:13:05 +0200 + [ Benjamin Drung ] + * ubuntutools/requestsync: Follow PEP 8 naming conventions. + + -- Benjamin Drung Sat, 10 Sep 2011 15:41:16 +0200 ubuntu-dev-tools (0.130) unstable; urgency=low diff --git a/requestsync b/requestsync index 2fa3c44..7500009 100755 --- a/requestsync +++ b/requestsync @@ -36,7 +36,7 @@ from distro_info import UbuntuDistroInfo from ubuntutools.config import UDTConfig, ubu_email from ubuntutools.lp import udtexceptions from ubuntutools.misc import require_utf8 -from ubuntutools.requestsync.common import (edit_report, getDebianChangelog, +from ubuntutools.requestsync.common import (edit_report, get_debian_changelog, raw_input_exit_on_ctrlc) # @@ -119,7 +119,7 @@ def main(): mxlist = DNS.mxlookup(bug_mail_domain) firstmx = mxlist[0] mailserver_host = firstmx[1] - except ImportError, x: + except ImportError: print >> sys.stderr, ('Please install python-dns to support ' 'Launchpad mail server lookup.') sys.exit(1) @@ -136,11 +136,11 @@ def main(): # import the needed requestsync module if options.lpapi: - from ubuntutools.requestsync.lp import (checkExistingReports, - getDebianSrcPkg, - getUbuntuSrcPkg, - getUbuntuDeltaChangelog, - needSponsorship, postBug) + from ubuntutools.requestsync.lp import (check_existing_reports, + get_debian_srcpkg, + get_ubuntu_srcpkg, + get_ubuntu_delta_changelog, + need_sponsorship, post_bug) from ubuntutools.lp.lpapicache import Distribution, Launchpad # See if we have LP credentials and exit if we don't - # cannot continue in this case @@ -150,11 +150,11 @@ def main(): except IOError: sys.exit(1) else: - from ubuntutools.requestsync.mail import (checkExistingReports, - getDebianSrcPkg, - getUbuntuSrcPkg, - getUbuntuDeltaChangelog, - mailBug, needSponsorship) + from ubuntutools.requestsync.mail import (check_existing_reports, + get_debian_srcpkg, + get_ubuntu_srcpkg, + get_ubuntu_delta_changelog, + mail_bug, need_sponsorship) if not any(x in os.environ for x in ('UBUMAIL', 'DEBEMAIL', 'EMAIL')): print >> sys.stderr, ( 'E: The environment variable UBUMAIL, DEBEMAIL or EMAIL needs ' @@ -188,7 +188,7 @@ def main(): # Get the current Ubuntu source package try: - ubuntu_srcpkg = getUbuntuSrcPkg(srcpkg, release) + ubuntu_srcpkg = get_ubuntu_srcpkg(srcpkg, release) ubuntu_version = Version(ubuntu_srcpkg.getVersion()) ubuntu_component = ubuntu_srcpkg.getComponent() newsource = False # override the -n flag @@ -206,7 +206,7 @@ def main(): # Get the requested Debian source package try: - debian_srcpkg = getDebianSrcPkg(srcpkg, distro) + debian_srcpkg = get_debian_srcpkg(srcpkg, distro) debian_version = Version(debian_srcpkg.getVersion()) debian_component = debian_srcpkg.getComponent() except udtexceptions.PackageNotFoundException, error: @@ -218,7 +218,7 @@ def main(): # try rmadison import ubuntutools.requestsync.mail try: - debian_srcpkg = ubuntutools.requestsync.mail.getDebianSrcPkg( + debian_srcpkg = ubuntutools.requestsync.mail.get_debian_srcpkg( srcpkg, distro) debian_version = Version(debian_srcpkg.getVersion()) debian_component = debian_srcpkg.getComponent() @@ -239,7 +239,7 @@ def main(): # -s flag not specified - check if we do need sponsorship if not sponsorship: - sponsorship = needSponsorship(srcpkg, ubuntu_component, release) + sponsorship = need_sponsorship(srcpkg, ubuntu_component, release) if not sponsorship and not ffe: print >> sys.stderr, ('Consider using syncpackage(1) for syncs that ' @@ -247,7 +247,7 @@ def main(): # Check for existing package reports if not newsource: - checkExistingReports(srcpkg) + check_existing_reports(srcpkg) # Generate bug report pkg_to_sync = ('%s %s (%s) from Debian %s (%s)' @@ -266,7 +266,7 @@ def main(): 'Not saving the report file will abort the request.') report += (u'Explanation of the Ubuntu delta and why it can be ' u'dropped:\n%s\n>>> ENTER_EXPLANATION_HERE <<<\n\n' - % getUbuntuDeltaChangelog(ubuntu_srcpkg)) + % get_ubuntu_delta_changelog(ubuntu_srcpkg)) if ffe: need_interaction = True @@ -288,7 +288,7 @@ def main(): else: report += ('Changelog entries since current %s version %s:\n\n' % (release, ubuntu_version)) - changelog = getDebianChangelog(debian_srcpkg, base_version) + changelog = get_debian_changelog(debian_srcpkg, base_version) if not changelog: if not options.missing_changelog_ok: print >> sys.stderr, ("E: Did not retrieve any changelog entries. " @@ -323,13 +323,13 @@ def main(): # Map status to the values expected by LP API mapping = {'new': 'New', 'confirmed': 'Confirmed'} # Post sync request using LP API - postBug(srcpkg, subscribe, mapping[status], title, report) + post_bug(srcpkg, subscribe, mapping[status], title, report) else: email_from = ubu_email(export=False)[1] # Mail sync request - mailBug(srcpkg, subscribe, status, title, report, bug_mail_domain, - options.keyid, email_from, mailserver_host, mailserver_port, - mailserver_user, mailserver_pass) + mail_bug(srcpkg, subscribe, status, title, report, bug_mail_domain, + options.keyid, email_from, mailserver_host, mailserver_port, + mailserver_user, mailserver_pass) if __name__ == '__main__': try: diff --git a/syncpackage b/syncpackage index 02061d8..bd00e5c 100755 --- a/syncpackage +++ b/syncpackage @@ -36,10 +36,10 @@ from lazr.restfulclient.errors import HTTPError from ubuntutools.archive import (DebianSourcePackage, UbuntuSourcePackage, DownloadError) from ubuntutools.config import UDTConfig, ubu_email -from ubuntutools.requestsync.common import getDebianChangelog -from ubuntutools.requestsync.mail import (getDebianSrcPkg - as requestsync_mail_getDebianSrcPkg) -from ubuntutools.requestsync.lp import getDebianSrcPkg, getUbuntuSrcPkg +from ubuntutools.requestsync.common import get_debian_changelog +from ubuntutools.requestsync.mail import (get_debian_srcpkg + as requestsync_mail_get_debian_srcpkg) +from ubuntutools.requestsync.lp import get_debian_srcpkg, get_ubuntu_srcpkg from ubuntutools.lp import udtexceptions from ubuntutools.lp.lpapicache import (Distribution, Launchpad, SourcePackagePublishingHistory) @@ -125,7 +125,7 @@ def sync_dsc(src_pkg, debian_dist, release, name, email, bugs, ubuntu_mirror, new_ver = Version(src_pkg.dsc["Version"]) try: - ubuntu_source = getUbuntuSrcPkg(src_pkg.source, release) + ubuntu_source = get_ubuntu_srcpkg(src_pkg.source, release) ubuntu_ver = Version(ubuntu_source.getVersion()) ubu_pkg = UbuntuSourcePackage(src_pkg.source, ubuntu_ver.full_version, ubuntu_source.getComponent(), @@ -278,7 +278,7 @@ def fetch_source_pkg(package, dist, version, component, ubuntu_release, mirror): if version is None or component is None: try: - debian_srcpkg = getDebianSrcPkg(package, dist) + debian_srcpkg = get_debian_srcpkg(package, dist) except (udtexceptions.PackageNotFoundException, udtexceptions.SeriesNotFoundException), e: Logger.error(str(e)) @@ -286,7 +286,7 @@ def fetch_source_pkg(package, dist, version, component, ubuntu_release, mirror): if version is None: version = Version(debian_srcpkg.getVersion()) try: - ubuntu_srcpkg = getUbuntuSrcPkg(package, ubuntu_release) + ubuntu_srcpkg = get_ubuntu_srcpkg(package, ubuntu_release) ubuntu_version = Version(ubuntu_srcpkg.getVersion()) except udtexceptions.PackageNotFoundException: ubuntu_version = Version('~') @@ -295,7 +295,7 @@ def fetch_source_pkg(package, dist, version, component, ubuntu_release, mirror): sys.exit(1) if ubuntu_version >= version: # The LP importer is maybe out of date - debian_srcpkg = requestsync_mail_getDebianSrcPkg(package, dist) + debian_srcpkg = requestsync_mail_get_debian_srcpkg(package, dist) if requested_version is None: version = Version(debian_srcpkg.getVersion()) if ubuntu_version >= version: @@ -335,8 +335,8 @@ def copy(src_pkg, release, bugs, simulate=False, force=False): sys.exit(1) try: - ubuntu_spph = getUbuntuSrcPkg(src_pkg.source, - ubuntu_series, ubuntu_pocket) + ubuntu_spph = get_ubuntu_srcpkg(src_pkg.source, + ubuntu_series, ubuntu_pocket) ubuntu_pkg = UbuntuSourcePackage(src_pkg.source, ubuntu_spph.getVersion(), ubuntu_spph.getComponent(), @@ -365,7 +365,7 @@ def copy(src_pkg, release, bugs, simulate=False, force=False): src_pkg.source, ubuntu_series, ubuntu_pocket, src_pkg.version) - changes = getDebianChangelog(debian_spph, base_version).strip() + changes = get_debian_changelog(debian_spph, base_version).strip() if changes: Logger.normal("New changes:\n%s", changes) @@ -542,7 +542,7 @@ def main(): + ', '.join(args)) try: - options.bugs = map(int, options.bugs) + options.bugs = [int(b) for b in options.bugs] except TypeError: parser.error('Invalid bug number(s) specified.') diff --git a/ubuntutools/requestsync/common.py b/ubuntutools/requestsync/common.py index b43a596..7841e2e 100644 --- a/ubuntutools/requestsync/common.py +++ b/ubuntutools/requestsync/common.py @@ -38,7 +38,7 @@ def raw_input_exit_on_ctrlc(*args, **kwargs): print '\nAbort requested. No sync request filed.' sys.exit(1) -def getChangelog(srcpkg, distro): +def get_changelog(srcpkg, distro): ''' Download and return a parsed changelog for srcpackage, from packages.debian.org or changelogs.ubuntu.com @@ -70,11 +70,11 @@ def getChangelog(srcpkg, distro): # TODO: Move this into requestsync.mail, and implement an LP version # when LP: #833384 is fixed -def getDebianChangelog(srcpkg, version): +def get_debian_changelog(srcpkg, version): ''' Return the new changelog entries since 'version'. ''' - changelog = getChangelog(srcpkg, 'debian') + changelog = get_changelog(srcpkg, 'debian') if changelog is None: return None new_entries = [] diff --git a/ubuntutools/requestsync/lp.py b/ubuntutools/requestsync/lp.py index a1cf6ce..9111cfc 100644 --- a/ubuntutools/requestsync/lp.py +++ b/ubuntutools/requestsync/lp.py @@ -30,7 +30,7 @@ from ubuntutools.requestsync.common import raw_input_exit_on_ctrlc from ubuntutools.lp.lpapicache import (Launchpad, Distribution, PersonTeam, DistributionSourcePackage) -def getDebianSrcPkg(name, release): +def get_debian_srcpkg(name, release): debian = Distribution('debian') debian_archive = debian.getArchive() @@ -38,13 +38,13 @@ def getDebianSrcPkg(name, release): return debian_archive.getSourcePackage(name, release) -def getUbuntuSrcPkg(name, release, pocket='Release'): +def get_ubuntu_srcpkg(name, release, pocket='Release'): ubuntu = Distribution('ubuntu') ubuntu_archive = ubuntu.getArchive() return ubuntu_archive.getSourcePackage(name, release, pocket) -def needSponsorship(name, component, release): +def need_sponsorship(name, component, release): ''' Check if the user has upload permissions for either the package itself or the component @@ -64,7 +64,7 @@ team.''' return need_sponsor -def checkExistingReports(srcpkg): +def check_existing_reports(srcpkg): ''' Check existing bug reports on Launchpad for a possible sync request. @@ -73,13 +73,13 @@ def checkExistingReports(srcpkg): # Fetch the package's bug list from Launchpad pkg = Distribution('ubuntu').getSourcePackage(name=srcpkg) - pkgBugList = pkg.searchTasks(status=["Incomplete", "New", "Confirmed", - "Triaged", "In Progress", - "Fix Committed"], - omit_duplicates=True) + pkg_bug_list = pkg.searchTasks(status=["Incomplete", "New", "Confirmed", + "Triaged", "In Progress", + "Fix Committed"], + omit_duplicates=True) # Search bug list for other sync requests. - for bug in pkgBugList: + for bug in pkg_bug_list: # check for Sync or sync and the package name if not bug.is_complete and 'ync %s' % srcpkg in bug.title: print ('The following bug could be a possible duplicate sync bug ' @@ -91,7 +91,7 @@ def checkExistingReports(srcpkg): raw_input_exit_on_ctrlc('Press [Enter] to continue or [Ctrl-C] ' 'to abort. ') -def getUbuntuDeltaChangelog(srcpkg): +def get_ubuntu_delta_changelog(srcpkg): ''' Download the Ubuntu changelog and extract the entries since the last sync from Debian. @@ -125,7 +125,7 @@ def getUbuntuDeltaChangelog(srcpkg): return '\n'.join(delta) -def postBug(srcpkg, subscribe, status, bugtitle, bugtext): +def post_bug(srcpkg, subscribe, status, bugtitle, bugtext): ''' Use the LP API to file the sync request. ''' diff --git a/ubuntutools/requestsync/mail.py b/ubuntutools/requestsync/mail.py index e7b89e4..862feb7 100644 --- a/ubuntutools/requestsync/mail.py +++ b/ubuntutools/requestsync/mail.py @@ -30,21 +30,21 @@ from devscripts.logger import Logger from distro_info import DebianDistroInfo from ubuntutools.archive import rmadison, FakeSPPH -from ubuntutools.requestsync.common import (getChangelog, +from ubuntutools.requestsync.common import (get_changelog, raw_input_exit_on_ctrlc) from ubuntutools import subprocess from ubuntutools.lp.udtexceptions import PackageNotFoundException __all__ = [ - 'getDebianSrcPkg', - 'getUbuntuSrcPkg', - 'needSponsorship', - 'checkExistingReports', - 'getUbuntuDeltaChangelog', - 'mailBug', + 'get_debian_srcpkg', + 'get_ubuntu_srcpkg', + 'need_sponsorship', + 'check_existing_reports', + 'get_ubuntu_delta_changelog', + 'mail_bug', ] -def getSrcPkg(distro, name, release): +def _get_srcpkg(distro, name, release): if distro == 'debian': # Canonicalise release: debian_info = DebianDistroInfo() @@ -59,13 +59,13 @@ def getSrcPkg(distro, name, release): return FakeSPPH(pkg['source'], pkg['version'], pkg['component']) -def getDebianSrcPkg(name, release): - return getSrcPkg('debian', name, release) +def get_debian_srcpkg(name, release): + return _get_srcpkg('debian', name, release) -def getUbuntuSrcPkg(name, release): - return getSrcPkg('ubuntu', name, release) +def get_ubuntu_srcpkg(name, release): + return _get_srcpkg('ubuntu', name, release) -def needSponsorship(name, component, release): +def need_sponsorship(name, component, release): ''' Ask the user if he has upload permissions for the package or the component. @@ -83,7 +83,7 @@ def needSponsorship(name, component, release): else: print 'Invalid answer' -def checkExistingReports(srcpkg): +def check_existing_reports(srcpkg): ''' Point the user to the URL to manually check for duplicate bug reports. ''' @@ -92,12 +92,12 @@ def checkExistingReports(srcpkg): 'for duplicate sync requests before continuing.' % srcpkg) raw_input_exit_on_ctrlc('Press [Enter] to continue or [Ctrl-C] to abort. ') -def getUbuntuDeltaChangelog(srcpkg): +def get_ubuntu_delta_changelog(srcpkg): ''' Download the Ubuntu changelog and extract the entries since the last sync from Debian. ''' - changelog = getChangelog(srcpkg, 'ubuntu') + changelog = get_changelog(srcpkg, 'ubuntu') if changelog is None: return u'' delta = [] @@ -111,9 +111,9 @@ def getUbuntuDeltaChangelog(srcpkg): return u'\n'.join(delta) -def mailBug(srcpkg, subscribe, status, bugtitle, bugtext, bug_mail_domain, - keyid, myemailaddr, mailserver_host, mailserver_port, - mailserver_user, mailserver_pass): +def mail_bug(srcpkg, subscribe, status, bugtitle, bugtext, bug_mail_domain, + keyid, myemailaddr, mailserver_host, mailserver_port, + mailserver_user, mailserver_pass): ''' Submit the sync request per email. '''