ubuntutools/requestsync: Follow PEP 8 naming conventions.

This commit is contained in:
Benjamin Drung 2011-09-10 15:42:40 +02:00
parent 1aabfec757
commit 1c814c8ec6
6 changed files with 72 additions and 69 deletions

5
debian/changelog vendored
View File

@ -35,7 +35,10 @@ ubuntu-dev-tools (0.131) UNRELEASED; urgency=low
[ Colin Watson ] [ Colin Watson ]
* syncpackage: Fix typo. * syncpackage: Fix typo.
-- Stefano Rivera <stefanor@debian.org> Thu, 08 Sep 2011 23:13:05 +0200 [ Benjamin Drung ]
* ubuntutools/requestsync: Follow PEP 8 naming conventions.
-- Benjamin Drung <bdrung@debian.org> Sat, 10 Sep 2011 15:41:16 +0200
ubuntu-dev-tools (0.130) unstable; urgency=low ubuntu-dev-tools (0.130) unstable; urgency=low

View File

@ -36,7 +36,7 @@ from distro_info import UbuntuDistroInfo
from ubuntutools.config import UDTConfig, ubu_email from ubuntutools.config import UDTConfig, ubu_email
from ubuntutools.lp import udtexceptions from ubuntutools.lp import udtexceptions
from ubuntutools.misc import require_utf8 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) raw_input_exit_on_ctrlc)
# #
@ -119,7 +119,7 @@ def main():
mxlist = DNS.mxlookup(bug_mail_domain) mxlist = DNS.mxlookup(bug_mail_domain)
firstmx = mxlist[0] firstmx = mxlist[0]
mailserver_host = firstmx[1] mailserver_host = firstmx[1]
except ImportError, x: except ImportError:
print >> sys.stderr, ('Please install python-dns to support ' print >> sys.stderr, ('Please install python-dns to support '
'Launchpad mail server lookup.') 'Launchpad mail server lookup.')
sys.exit(1) sys.exit(1)
@ -136,11 +136,11 @@ def main():
# import the needed requestsync module # import the needed requestsync module
if options.lpapi: if options.lpapi:
from ubuntutools.requestsync.lp import (checkExistingReports, from ubuntutools.requestsync.lp import (check_existing_reports,
getDebianSrcPkg, get_debian_srcpkg,
getUbuntuSrcPkg, get_ubuntu_srcpkg,
getUbuntuDeltaChangelog, get_ubuntu_delta_changelog,
needSponsorship, postBug) need_sponsorship, post_bug)
from ubuntutools.lp.lpapicache import Distribution, Launchpad from ubuntutools.lp.lpapicache import Distribution, Launchpad
# See if we have LP credentials and exit if we don't - # See if we have LP credentials and exit if we don't -
# cannot continue in this case # cannot continue in this case
@ -150,11 +150,11 @@ def main():
except IOError: except IOError:
sys.exit(1) sys.exit(1)
else: else:
from ubuntutools.requestsync.mail import (checkExistingReports, from ubuntutools.requestsync.mail import (check_existing_reports,
getDebianSrcPkg, get_debian_srcpkg,
getUbuntuSrcPkg, get_ubuntu_srcpkg,
getUbuntuDeltaChangelog, get_ubuntu_delta_changelog,
mailBug, needSponsorship) mail_bug, need_sponsorship)
if not any(x in os.environ for x in ('UBUMAIL', 'DEBEMAIL', 'EMAIL')): if not any(x in os.environ for x in ('UBUMAIL', 'DEBEMAIL', 'EMAIL')):
print >> sys.stderr, ( print >> sys.stderr, (
'E: The environment variable UBUMAIL, DEBEMAIL or EMAIL needs ' 'E: The environment variable UBUMAIL, DEBEMAIL or EMAIL needs '
@ -188,7 +188,7 @@ def main():
# Get the current Ubuntu source package # Get the current Ubuntu source package
try: try:
ubuntu_srcpkg = getUbuntuSrcPkg(srcpkg, release) ubuntu_srcpkg = get_ubuntu_srcpkg(srcpkg, release)
ubuntu_version = Version(ubuntu_srcpkg.getVersion()) ubuntu_version = Version(ubuntu_srcpkg.getVersion())
ubuntu_component = ubuntu_srcpkg.getComponent() ubuntu_component = ubuntu_srcpkg.getComponent()
newsource = False # override the -n flag newsource = False # override the -n flag
@ -206,7 +206,7 @@ def main():
# Get the requested Debian source package # Get the requested Debian source package
try: try:
debian_srcpkg = getDebianSrcPkg(srcpkg, distro) debian_srcpkg = get_debian_srcpkg(srcpkg, distro)
debian_version = Version(debian_srcpkg.getVersion()) debian_version = Version(debian_srcpkg.getVersion())
debian_component = debian_srcpkg.getComponent() debian_component = debian_srcpkg.getComponent()
except udtexceptions.PackageNotFoundException, error: except udtexceptions.PackageNotFoundException, error:
@ -218,7 +218,7 @@ def main():
# try rmadison # try rmadison
import ubuntutools.requestsync.mail import ubuntutools.requestsync.mail
try: try:
debian_srcpkg = ubuntutools.requestsync.mail.getDebianSrcPkg( debian_srcpkg = ubuntutools.requestsync.mail.get_debian_srcpkg(
srcpkg, distro) srcpkg, distro)
debian_version = Version(debian_srcpkg.getVersion()) debian_version = Version(debian_srcpkg.getVersion())
debian_component = debian_srcpkg.getComponent() debian_component = debian_srcpkg.getComponent()
@ -239,7 +239,7 @@ def main():
# -s flag not specified - check if we do need sponsorship # -s flag not specified - check if we do need sponsorship
if not sponsorship: if not sponsorship:
sponsorship = needSponsorship(srcpkg, ubuntu_component, release) sponsorship = need_sponsorship(srcpkg, ubuntu_component, release)
if not sponsorship and not ffe: if not sponsorship and not ffe:
print >> sys.stderr, ('Consider using syncpackage(1) for syncs that ' print >> sys.stderr, ('Consider using syncpackage(1) for syncs that '
@ -247,7 +247,7 @@ def main():
# Check for existing package reports # Check for existing package reports
if not newsource: if not newsource:
checkExistingReports(srcpkg) check_existing_reports(srcpkg)
# Generate bug report # Generate bug report
pkg_to_sync = ('%s %s (%s) from Debian %s (%s)' 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.') 'Not saving the report file will abort the request.')
report += (u'Explanation of the Ubuntu delta and why it can be ' report += (u'Explanation of the Ubuntu delta and why it can be '
u'dropped:\n%s\n>>> ENTER_EXPLANATION_HERE <<<\n\n' u'dropped:\n%s\n>>> ENTER_EXPLANATION_HERE <<<\n\n'
% getUbuntuDeltaChangelog(ubuntu_srcpkg)) % get_ubuntu_delta_changelog(ubuntu_srcpkg))
if ffe: if ffe:
need_interaction = True need_interaction = True
@ -288,7 +288,7 @@ def main():
else: else:
report += ('Changelog entries since current %s version %s:\n\n' report += ('Changelog entries since current %s version %s:\n\n'
% (release, ubuntu_version)) % (release, ubuntu_version))
changelog = getDebianChangelog(debian_srcpkg, base_version) changelog = get_debian_changelog(debian_srcpkg, base_version)
if not changelog: if not changelog:
if not options.missing_changelog_ok: if not options.missing_changelog_ok:
print >> sys.stderr, ("E: Did not retrieve any changelog entries. " 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 # Map status to the values expected by LP API
mapping = {'new': 'New', 'confirmed': 'Confirmed'} mapping = {'new': 'New', 'confirmed': 'Confirmed'}
# Post sync request using LP API # Post sync request using LP API
postBug(srcpkg, subscribe, mapping[status], title, report) post_bug(srcpkg, subscribe, mapping[status], title, report)
else: else:
email_from = ubu_email(export=False)[1] email_from = ubu_email(export=False)[1]
# Mail sync request # Mail sync request
mailBug(srcpkg, subscribe, status, title, report, bug_mail_domain, mail_bug(srcpkg, subscribe, status, title, report, bug_mail_domain,
options.keyid, email_from, mailserver_host, mailserver_port, options.keyid, email_from, mailserver_host, mailserver_port,
mailserver_user, mailserver_pass) mailserver_user, mailserver_pass)
if __name__ == '__main__': if __name__ == '__main__':
try: try:

View File

@ -36,10 +36,10 @@ from lazr.restfulclient.errors import HTTPError
from ubuntutools.archive import (DebianSourcePackage, UbuntuSourcePackage, from ubuntutools.archive import (DebianSourcePackage, UbuntuSourcePackage,
DownloadError) DownloadError)
from ubuntutools.config import UDTConfig, ubu_email from ubuntutools.config import UDTConfig, ubu_email
from ubuntutools.requestsync.common import getDebianChangelog from ubuntutools.requestsync.common import get_debian_changelog
from ubuntutools.requestsync.mail import (getDebianSrcPkg from ubuntutools.requestsync.mail import (get_debian_srcpkg
as requestsync_mail_getDebianSrcPkg) as requestsync_mail_get_debian_srcpkg)
from ubuntutools.requestsync.lp import getDebianSrcPkg, getUbuntuSrcPkg from ubuntutools.requestsync.lp import get_debian_srcpkg, get_ubuntu_srcpkg
from ubuntutools.lp import udtexceptions from ubuntutools.lp import udtexceptions
from ubuntutools.lp.lpapicache import (Distribution, Launchpad, from ubuntutools.lp.lpapicache import (Distribution, Launchpad,
SourcePackagePublishingHistory) 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"]) new_ver = Version(src_pkg.dsc["Version"])
try: try:
ubuntu_source = getUbuntuSrcPkg(src_pkg.source, release) ubuntu_source = get_ubuntu_srcpkg(src_pkg.source, release)
ubuntu_ver = Version(ubuntu_source.getVersion()) ubuntu_ver = Version(ubuntu_source.getVersion())
ubu_pkg = UbuntuSourcePackage(src_pkg.source, ubuntu_ver.full_version, ubu_pkg = UbuntuSourcePackage(src_pkg.source, ubuntu_ver.full_version,
ubuntu_source.getComponent(), 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: if version is None or component is None:
try: try:
debian_srcpkg = getDebianSrcPkg(package, dist) debian_srcpkg = get_debian_srcpkg(package, dist)
except (udtexceptions.PackageNotFoundException, except (udtexceptions.PackageNotFoundException,
udtexceptions.SeriesNotFoundException), e: udtexceptions.SeriesNotFoundException), e:
Logger.error(str(e)) Logger.error(str(e))
@ -286,7 +286,7 @@ def fetch_source_pkg(package, dist, version, component, ubuntu_release, mirror):
if version is None: if version is None:
version = Version(debian_srcpkg.getVersion()) version = Version(debian_srcpkg.getVersion())
try: try:
ubuntu_srcpkg = getUbuntuSrcPkg(package, ubuntu_release) ubuntu_srcpkg = get_ubuntu_srcpkg(package, ubuntu_release)
ubuntu_version = Version(ubuntu_srcpkg.getVersion()) ubuntu_version = Version(ubuntu_srcpkg.getVersion())
except udtexceptions.PackageNotFoundException: except udtexceptions.PackageNotFoundException:
ubuntu_version = Version('~') ubuntu_version = Version('~')
@ -295,7 +295,7 @@ def fetch_source_pkg(package, dist, version, component, ubuntu_release, mirror):
sys.exit(1) sys.exit(1)
if ubuntu_version >= version: if ubuntu_version >= version:
# The LP importer is maybe out of date # 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: if requested_version is None:
version = Version(debian_srcpkg.getVersion()) version = Version(debian_srcpkg.getVersion())
if ubuntu_version >= version: if ubuntu_version >= version:
@ -335,8 +335,8 @@ def copy(src_pkg, release, bugs, simulate=False, force=False):
sys.exit(1) sys.exit(1)
try: try:
ubuntu_spph = getUbuntuSrcPkg(src_pkg.source, ubuntu_spph = get_ubuntu_srcpkg(src_pkg.source,
ubuntu_series, ubuntu_pocket) ubuntu_series, ubuntu_pocket)
ubuntu_pkg = UbuntuSourcePackage(src_pkg.source, ubuntu_pkg = UbuntuSourcePackage(src_pkg.source,
ubuntu_spph.getVersion(), ubuntu_spph.getVersion(),
ubuntu_spph.getComponent(), 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.source, ubuntu_series, ubuntu_pocket,
src_pkg.version) src_pkg.version)
changes = getDebianChangelog(debian_spph, base_version).strip() changes = get_debian_changelog(debian_spph, base_version).strip()
if changes: if changes:
Logger.normal("New changes:\n%s", changes) Logger.normal("New changes:\n%s", changes)
@ -542,7 +542,7 @@ def main():
+ ', '.join(args)) + ', '.join(args))
try: try:
options.bugs = map(int, options.bugs) options.bugs = [int(b) for b in options.bugs]
except TypeError: except TypeError:
parser.error('Invalid bug number(s) specified.') parser.error('Invalid bug number(s) specified.')

View File

@ -38,7 +38,7 @@ def raw_input_exit_on_ctrlc(*args, **kwargs):
print '\nAbort requested. No sync request filed.' print '\nAbort requested. No sync request filed.'
sys.exit(1) sys.exit(1)
def getChangelog(srcpkg, distro): def get_changelog(srcpkg, distro):
''' '''
Download and return a parsed changelog for srcpackage, from Download and return a parsed changelog for srcpackage, from
packages.debian.org or changelogs.ubuntu.com 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 # TODO: Move this into requestsync.mail, and implement an LP version
# when LP: #833384 is fixed # when LP: #833384 is fixed
def getDebianChangelog(srcpkg, version): def get_debian_changelog(srcpkg, version):
''' '''
Return the new changelog entries since 'version'. Return the new changelog entries since 'version'.
''' '''
changelog = getChangelog(srcpkg, 'debian') changelog = get_changelog(srcpkg, 'debian')
if changelog is None: if changelog is None:
return None return None
new_entries = [] new_entries = []

View File

@ -30,7 +30,7 @@ from ubuntutools.requestsync.common import raw_input_exit_on_ctrlc
from ubuntutools.lp.lpapicache import (Launchpad, Distribution, PersonTeam, from ubuntutools.lp.lpapicache import (Launchpad, Distribution, PersonTeam,
DistributionSourcePackage) DistributionSourcePackage)
def getDebianSrcPkg(name, release): def get_debian_srcpkg(name, release):
debian = Distribution('debian') debian = Distribution('debian')
debian_archive = debian.getArchive() debian_archive = debian.getArchive()
@ -38,13 +38,13 @@ def getDebianSrcPkg(name, release):
return debian_archive.getSourcePackage(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 = Distribution('ubuntu')
ubuntu_archive = ubuntu.getArchive() ubuntu_archive = ubuntu.getArchive()
return ubuntu_archive.getSourcePackage(name, release, pocket) 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 Check if the user has upload permissions for either the package
itself or the component itself or the component
@ -64,7 +64,7 @@ team.'''
return need_sponsor return need_sponsor
def checkExistingReports(srcpkg): def check_existing_reports(srcpkg):
''' '''
Check existing bug reports on Launchpad for a possible sync request. 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 # Fetch the package's bug list from Launchpad
pkg = Distribution('ubuntu').getSourcePackage(name=srcpkg) pkg = Distribution('ubuntu').getSourcePackage(name=srcpkg)
pkgBugList = pkg.searchTasks(status=["Incomplete", "New", "Confirmed", pkg_bug_list = pkg.searchTasks(status=["Incomplete", "New", "Confirmed",
"Triaged", "In Progress", "Triaged", "In Progress",
"Fix Committed"], "Fix Committed"],
omit_duplicates=True) omit_duplicates=True)
# Search bug list for other sync requests. # 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 # check for Sync or sync and the package name
if not bug.is_complete and 'ync %s' % srcpkg in bug.title: if not bug.is_complete and 'ync %s' % srcpkg in bug.title:
print ('The following bug could be a possible duplicate sync bug ' 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] ' raw_input_exit_on_ctrlc('Press [Enter] to continue or [Ctrl-C] '
'to abort. ') 'to abort. ')
def getUbuntuDeltaChangelog(srcpkg): def get_ubuntu_delta_changelog(srcpkg):
''' '''
Download the Ubuntu changelog and extract the entries since the last sync Download the Ubuntu changelog and extract the entries since the last sync
from Debian. from Debian.
@ -125,7 +125,7 @@ def getUbuntuDeltaChangelog(srcpkg):
return '\n'.join(delta) 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. Use the LP API to file the sync request.
''' '''

View File

@ -30,21 +30,21 @@ from devscripts.logger import Logger
from distro_info import DebianDistroInfo from distro_info import DebianDistroInfo
from ubuntutools.archive import rmadison, FakeSPPH from ubuntutools.archive import rmadison, FakeSPPH
from ubuntutools.requestsync.common import (getChangelog, from ubuntutools.requestsync.common import (get_changelog,
raw_input_exit_on_ctrlc) raw_input_exit_on_ctrlc)
from ubuntutools import subprocess from ubuntutools import subprocess
from ubuntutools.lp.udtexceptions import PackageNotFoundException from ubuntutools.lp.udtexceptions import PackageNotFoundException
__all__ = [ __all__ = [
'getDebianSrcPkg', 'get_debian_srcpkg',
'getUbuntuSrcPkg', 'get_ubuntu_srcpkg',
'needSponsorship', 'need_sponsorship',
'checkExistingReports', 'check_existing_reports',
'getUbuntuDeltaChangelog', 'get_ubuntu_delta_changelog',
'mailBug', 'mail_bug',
] ]
def getSrcPkg(distro, name, release): def _get_srcpkg(distro, name, release):
if distro == 'debian': if distro == 'debian':
# Canonicalise release: # Canonicalise release:
debian_info = DebianDistroInfo() debian_info = DebianDistroInfo()
@ -59,13 +59,13 @@ def getSrcPkg(distro, name, release):
return FakeSPPH(pkg['source'], pkg['version'], pkg['component']) return FakeSPPH(pkg['source'], pkg['version'], pkg['component'])
def getDebianSrcPkg(name, release): def get_debian_srcpkg(name, release):
return getSrcPkg('debian', name, release) return _get_srcpkg('debian', name, release)
def getUbuntuSrcPkg(name, release): def get_ubuntu_srcpkg(name, release):
return getSrcPkg('ubuntu', 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 Ask the user if he has upload permissions for the package or the
component. component.
@ -83,7 +83,7 @@ def needSponsorship(name, component, release):
else: else:
print 'Invalid answer' print 'Invalid answer'
def checkExistingReports(srcpkg): def check_existing_reports(srcpkg):
''' '''
Point the user to the URL to manually check for duplicate bug reports. 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) 'for duplicate sync requests before continuing.' % srcpkg)
raw_input_exit_on_ctrlc('Press [Enter] to continue or [Ctrl-C] to abort. ') 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 Download the Ubuntu changelog and extract the entries since the last sync
from Debian. from Debian.
''' '''
changelog = getChangelog(srcpkg, 'ubuntu') changelog = get_changelog(srcpkg, 'ubuntu')
if changelog is None: if changelog is None:
return u'' return u''
delta = [] delta = []
@ -111,9 +111,9 @@ def getUbuntuDeltaChangelog(srcpkg):
return u'\n'.join(delta) return u'\n'.join(delta)
def mailBug(srcpkg, subscribe, status, bugtitle, bugtext, bug_mail_domain, def mail_bug(srcpkg, subscribe, status, bugtitle, bugtext, bug_mail_domain,
keyid, myemailaddr, mailserver_host, mailserver_port, keyid, myemailaddr, mailserver_host, mailserver_port,
mailserver_user, mailserver_pass): mailserver_user, mailserver_pass):
''' '''
Submit the sync request per email. Submit the sync request per email.
''' '''