Config file support in requestsync

This commit is contained in:
Stefano Rivera 2010-12-21 17:02:36 +02:00
parent 660209473b
commit 82eab1c349
4 changed files with 77 additions and 39 deletions

View File

@ -67,6 +67,14 @@ This disables the upload permissions check described above.
Use this flag after FeatureFreeze for non-bug fix syncs. \fBrequestsync\fR will Use this flag after FeatureFreeze for non-bug fix syncs. \fBrequestsync\fR will
subscribe ubuntu-release team instead of sponsorship team. subscribe ubuntu-release team instead of sponsorship team.
.TP .TP
.B \-\-lpinstance\fR=\fIINSTANCE\fR
Use the specified instance of Launchpad (e.g. "staging"), instead of
the default of "production".
.TP
.B \-\-no\-conf
Do not read any configuration files, or configuration from environment
variables.
.TP
.B <source package> .B <source package>
This is the source package that you would like to be synced from Debian. This is the source package that you would like to be synced from Debian.
.TP .TP
@ -80,27 +88,40 @@ In some cases, the base version (where the Ubuntu package started differing
from the Debian package) cannot be automatically determined. from the Debian package) cannot be automatically determined.
Specify this option in this case. Specify this option in this case.
.SH ENVIRONMENT VARIABLES .SH ENVIRONMENT
\fBrequestsync\fR uses the following variables which should be set in your \fBrequestsync\fR uses the following variables which should be set in your
shell's configuration by adding \fIexport VARIABLE=\fR lines, where VARIABLE is shell's configuration by adding \fIexport VARIABLE=\fR lines, where VARIABLE is
one of the following: one of the following:
.TP .TP
.B DEBEMAIL .BR UBUMAIL ", " DEBEMAIL
Specifies which email should be used when sending to Launchpad. Specifies which email should be used when sending to Launchpad.
.P
All of the \fBCONFIGURATION VARIABLES\fR below are also supported as
environment variables.
Variables in the environment take precedence to those in configuration
files.
.SH CONFIGURATION VARIABLES
.TP .TP
.B DEBSMTP .B REQUESTSYNC_SMTP_SERVER
Set which SMTP server to use when sending mail. Set which SMTP server to use when sending mail.
If unspecified this defaults to fiordland.ubuntu.com. If unspecified this defaults to fiordland.ubuntu.com.
.TP .TP
.B DEBSMTP_PORT .B REQUESTSYNC_SMTP_PORT
Sets which port of the SMTP server to use. Default is 25. Sets which port of the SMTP server to use. Default is 25.
.TP .TP
.B DEBSMTP_USER \fRand\fB DEBSMTP_PASS .BR REQUESTSYNC_SMTP_USER " and " REQUESTSYNC_SMTP_PASS
Sets the username and password to use when authenticating to the SMTP server. Sets the username and password to use when authenticating to the SMTP server.
.TP
.BR REQUESTSYNC_USE_LPAPI
Setting this to \fIyes\fR is equivalent to running with \fB--lp\fR.
.TP
.BR REQUESTSYNC_LPINSTANCE ", " UBUNTUTOOLS_LPINSTANCE
The default value for \fB--lpinstance\fR.
.SH SEE ALSO .SH SEE ALSO
.BR rmadison (1) .BR rmadison (1),
.BR ubuntu\-dev\-tools (5)
.SH AUTHOR .SH AUTHOR
.B requestsync .B requestsync

View File

@ -26,11 +26,13 @@
# #
# ################################################################## # ##################################################################
import sys
from optparse import OptionParser from optparse import OptionParser
import os
import sys
from debian.changelog import Version from debian.changelog import Version
# ubuntu-dev-tools modules from ubuntutools.config import UDTConfig, ubu_email
from ubuntutools.lp import udtexceptions from ubuntutools.lp import udtexceptions
from ubuntutools.requestsync.common import (edit_report, getDebianChangelog, from ubuntutools.requestsync.common import (edit_report, getDebianChangelog,
raw_input_exit_on_ctrlc) raw_input_exit_on_ctrlc)
@ -57,6 +59,9 @@ if __name__ == '__main__':
optParser.add_option('--lp', action='store_true', optParser.add_option('--lp', action='store_true',
dest='lpapi', default=False, dest='lpapi', default=False,
help='Specify whether to use the LP API for filing the sync request (recommended).') help='Specify whether to use the LP API for filing the sync request (recommended).')
optParser.add_option('--lpinstance', type='string', metavar='INSTANCE',
dest='lpinstance', default=None,
help='Launchpad instance to connect to (default: production).')
optParser.add_option('-s', action='store_true', optParser.add_option('-s', action='store_true',
dest='sponsorship', default=False, dest='sponsorship', default=False,
help='Force sponsorship') help='Force sponsorship')
@ -67,6 +72,9 @@ if __name__ == '__main__':
dest='ffe', default=False, dest='ffe', default=False,
help='Use this after FeatureFreeze for non-bug fix syncs, changes ' \ help='Use this after FeatureFreeze for non-bug fix syncs, changes ' \
'default subscription to the appropriate release team.') 'default subscription to the appropriate release team.')
optParser.add_option('--no-conf', action='store_true',
dest='no_conf', default=False,
help="Don't read config files or environment variables")
(options, args) = optParser.parse_args() (options, args) = optParser.parse_args()
@ -74,8 +82,19 @@ if __name__ == '__main__':
optParser.print_help() optParser.print_help()
sys.exit(1) sys.exit(1)
config = UDTConfig(options.no_conf)
if not options.lpapi:
options.lpapi = config.get_value('USE_LPAPI', default=False,
boolean=True)
if options.lpinstance is None:
options.lpinstance = config.get_value('LPINSTANCE')
# import the needed requestsync module # import the needed requestsync module
if options.lpapi: if options.lpapi:
# Needs to be set before lpapicache is imported:
import ubuntutools.lp
ubuntutools.lp.service = options.lpinstance
from ubuntutools.requestsync.lp import (checkExistingReports, from ubuntutools.requestsync.lp import (checkExistingReports,
getDebianSrcPkg, getDebianSrcPkg,
getUbuntuSrcPkg, getUbuntuSrcPkg,
@ -90,10 +109,12 @@ if __name__ == '__main__':
else: else:
from ubuntutools.requestsync.mail import (checkExistingReports, from ubuntutools.requestsync.mail import (checkExistingReports,
getDebianSrcPkg, getDebianSrcPkg,
getEmailAddress,
getUbuntuSrcPkg, getUbuntuSrcPkg,
mailBug, needSponsorship) mailBug, needSponsorship)
if not getEmailAddress(): 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 '
'to be set to let this script mail the sync request.')
sys.exit(1) sys.exit(1)
newsource = options.newpkg newsource = options.newpkg
@ -242,5 +263,17 @@ if __name__ == '__main__':
# Post sync request using LP API # Post sync request using LP API
postBug(srcpkg, subscribe, mapping[status], title, report) postBug(srcpkg, subscribe, mapping[status], title, report)
else: else:
email_from = ubu_email(export=False)[1]
mailserver_host = config.get_value('SMTP_SERVER',
default='fiordland.ubuntu.com',
compat_keys=['UBUSMTP', 'DEBSMTP'])
mailserver_port = config.get_value('SMTP_PORT', default=25,
compat_keys=['UBUSMTP_PORT', 'DEBSMTP_PORT'])
mailserver_user = config.get_value('SMTP_USER',
compat_keys=['UBUSMTP_USER', 'DEBSMTP_USER'])
mailserver_pass = config.get_value('SMTP_PASS',
compat_keys=['UBUSMTP_PASS', 'DEBSMTP_PASS'])
# Mail sync request # Mail sync request
mailBug(srcpkg, subscribe, status, title, report, options.keyid) mailBug(srcpkg, subscribe, status, title, report, options.lpinstance,
options.keyid, email_from, mailserver_host, mailserver_port,
mailserver_user, mailserver_pass)

View File

@ -49,7 +49,7 @@ def needSponsorship(name, component, release):
itself or the component itself or the component
''' '''
archive = Distribution('ubuntu').getArchive() archive = Distribution('ubuntu').getArchive()
distroseries = Distribution('ubuntu').getSeries(release) distroseries = Distribution('ubuntu').getSeries(release)
need_sponsor = not PersonTeam.me.canUploadPackage(archive, distroseries, name, component) need_sponsor = not PersonTeam.me.canUploadPackage(archive, distroseries, name, component)
if need_sponsor: if need_sponsor:

View File

@ -31,7 +31,6 @@ from ubuntutools.lp.udtexceptions import PackageNotFoundException
__all__ = [ __all__ = [
'getDebianSrcPkg', 'getDebianSrcPkg',
'getUbuntuSrcPkg', 'getUbuntuSrcPkg',
'getEmailAddress',
'needSponsorship', 'needSponsorship',
'checkExistingReports', 'checkExistingReports',
'mailBug', 'mailBug',
@ -106,18 +105,6 @@ def getDebianSrcPkg(name, release):
def getUbuntuSrcPkg(name, release): def getUbuntuSrcPkg(name, release):
return getSrcPkg('ubuntu', name, release) return getSrcPkg('ubuntu', name, release)
def getEmailAddress():
'''
Get the From email address from the UBUMAIL, DEBEMAIL or EMAIL
environment variable or give an error.
'''
myemailaddr = os.getenv('UBUMAIL') or os.getenv('DEBEMAIL') or os.getenv('EMAIL')
if not myemailaddr:
print >> sys.stderr, 'E: The environment variable UBUMAIL, ' \
'DEBEMAIL or EMAIL needs to be set to let this script ' \
'mail the sync request.'
return myemailaddr
def needSponsorship(name, component, release): def needSponsorship(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
@ -143,16 +130,20 @@ 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 mailBug(srcpkg, subscribe, status, bugtitle, bugtext, keyid = None): def mailBug(srcpkg, subscribe, status, bugtitle, bugtext, lpinstance, keyid,
myemailaddr, mailserver_host, mailserver_port, mailserver_user,
mailserver_pass):
''' '''
Submit the sync request per email. Submit the sync request per email.
''' '''
to = 'new@bugs.launchpad.net' if lpinstance == 'production':
to = 'new@bugs.launchpad.net'
# getEmailAddress() can't fail here as the main code in requestsync elif lpinstance == 'staging':
# already checks its return value to = 'new@bugs.staging.launchpad.net'
myemailaddr = getEmailAddress() else:
print >> sys.stderr, 'Error: Unknown launchpad instance:', lpinstance
sys.exit(1)
# generate mailbody # generate mailbody
if srcpkg: if srcpkg:
@ -195,10 +186,6 @@ Content-Type: text/plain; charset=UTF-8
print 'The final report is:\n%s' % mail print 'The final report is:\n%s' % mail
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. ')
# get server address and port
mailserver_host = os.getenv('UBUSMTP') or os.getenv('DEBSMTP') or 'fiordland.ubuntu.com'
mailserver_port = os.getenv('UBUSMTP_PORT') or os.getenv('DEBSMTP_PORT') or 25
# connect to the server # connect to the server
try: try:
print 'Connecting to %s:%s ...' % (mailserver_host, mailserver_port) print 'Connecting to %s:%s ...' % (mailserver_host, mailserver_port)
@ -208,9 +195,6 @@ Content-Type: text/plain; charset=UTF-8
(mailserver_host, mailserver_port, s[1], s[0]) (mailserver_host, mailserver_port, s[1], s[0])
return return
# authenticate to the server
mailserver_user = os.getenv('UBUSMTP_USER') or os.getenv('DEBSMTP_USER')
mailserver_pass = os.getenv('UBUSMTP_PASS') or os.getenv('DEBSMTP_PASS')
if mailserver_user and mailserver_pass: if mailserver_user and mailserver_pass:
try: try:
s.login(mailserver_user, mailserver_pass) s.login(mailserver_user, mailserver_pass)