mirror of
				https://git.launchpad.net/ubuntu-dev-tools
				synced 2025-11-04 07:54:03 +00:00 
			
		
		
		
	Config file support in requestsync
This commit is contained in:
		
							parent
							
								
									660209473b
								
							
						
					
					
						commit
						82eab1c349
					
				@ -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
 | 
			
		||||
subscribe ubuntu-release team instead of sponsorship team.
 | 
			
		||||
.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>
 | 
			
		||||
This is the source package that you would like to be synced from Debian.
 | 
			
		||||
.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.
 | 
			
		||||
Specify this option in this case.
 | 
			
		||||
 | 
			
		||||
.SH ENVIRONMENT VARIABLES
 | 
			
		||||
.SH ENVIRONMENT
 | 
			
		||||
\fBrequestsync\fR uses the following variables which should be set in your
 | 
			
		||||
shell's configuration by adding \fIexport VARIABLE=\fR lines, where VARIABLE is
 | 
			
		||||
one of the following:
 | 
			
		||||
 | 
			
		||||
.TP
 | 
			
		||||
.B DEBEMAIL
 | 
			
		||||
.BR UBUMAIL ", " DEBEMAIL
 | 
			
		||||
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
 | 
			
		||||
.B DEBSMTP
 | 
			
		||||
.B REQUESTSYNC_SMTP_SERVER
 | 
			
		||||
Set which SMTP server to use when sending mail.
 | 
			
		||||
If unspecified this defaults to fiordland.ubuntu.com.
 | 
			
		||||
.TP
 | 
			
		||||
.B DEBSMTP_PORT
 | 
			
		||||
.B REQUESTSYNC_SMTP_PORT
 | 
			
		||||
Sets which port of the SMTP server to use. Default is 25.
 | 
			
		||||
.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.
 | 
			
		||||
.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
 | 
			
		||||
.BR rmadison (1)
 | 
			
		||||
.BR rmadison (1),
 | 
			
		||||
.BR ubuntu\-dev\-tools (5)
 | 
			
		||||
 | 
			
		||||
.SH AUTHOR
 | 
			
		||||
.B requestsync
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										43
									
								
								requestsync
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								requestsync
									
									
									
									
									
								
							@ -26,11 +26,13 @@
 | 
			
		||||
#
 | 
			
		||||
# ##################################################################
 | 
			
		||||
 | 
			
		||||
import sys
 | 
			
		||||
from optparse import OptionParser
 | 
			
		||||
import os
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
from debian.changelog import Version
 | 
			
		||||
 | 
			
		||||
# ubuntu-dev-tools modules
 | 
			
		||||
from ubuntutools.config import UDTConfig, ubu_email
 | 
			
		||||
from ubuntutools.lp import udtexceptions
 | 
			
		||||
from ubuntutools.requestsync.common import (edit_report, getDebianChangelog,
 | 
			
		||||
                                            raw_input_exit_on_ctrlc)
 | 
			
		||||
@ -57,6 +59,9 @@ if __name__ == '__main__':
 | 
			
		||||
	optParser.add_option('--lp', action='store_true',
 | 
			
		||||
		dest='lpapi', default=False,
 | 
			
		||||
		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',
 | 
			
		||||
		dest='sponsorship', default=False,
 | 
			
		||||
		help='Force sponsorship')
 | 
			
		||||
@ -67,6 +72,9 @@ if __name__ == '__main__':
 | 
			
		||||
		dest='ffe', default=False,
 | 
			
		||||
		help='Use this after FeatureFreeze for non-bug fix syncs, changes ' \
 | 
			
		||||
			'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()
 | 
			
		||||
 | 
			
		||||
@ -74,8 +82,19 @@ if __name__ == '__main__':
 | 
			
		||||
		optParser.print_help()
 | 
			
		||||
		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
 | 
			
		||||
	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,
 | 
			
		||||
		                                        getDebianSrcPkg,
 | 
			
		||||
		                                        getUbuntuSrcPkg,
 | 
			
		||||
@ -90,10 +109,12 @@ if __name__ == '__main__':
 | 
			
		||||
	else:
 | 
			
		||||
		from ubuntutools.requestsync.mail import (checkExistingReports,
 | 
			
		||||
		                                          getDebianSrcPkg,
 | 
			
		||||
		                                          getEmailAddress,
 | 
			
		||||
		                                          getUbuntuSrcPkg,
 | 
			
		||||
		                                          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)
 | 
			
		||||
 | 
			
		||||
	newsource = options.newpkg
 | 
			
		||||
@ -242,5 +263,17 @@ if __name__ == '__main__':
 | 
			
		||||
		# Post sync request using LP API
 | 
			
		||||
		postBug(srcpkg, subscribe, mapping[status], title, report)
 | 
			
		||||
	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
 | 
			
		||||
		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)
 | 
			
		||||
 | 
			
		||||
@ -49,7 +49,7 @@ def needSponsorship(name, component, release):
 | 
			
		||||
	itself or the component
 | 
			
		||||
	'''
 | 
			
		||||
	archive = Distribution('ubuntu').getArchive()
 | 
			
		||||
        distroseries = Distribution('ubuntu').getSeries(release)
 | 
			
		||||
	distroseries = Distribution('ubuntu').getSeries(release)
 | 
			
		||||
 | 
			
		||||
	need_sponsor = not PersonTeam.me.canUploadPackage(archive, distroseries, name, component)
 | 
			
		||||
	if need_sponsor:
 | 
			
		||||
 | 
			
		||||
@ -31,7 +31,6 @@ from ubuntutools.lp.udtexceptions import PackageNotFoundException
 | 
			
		||||
__all__ = [
 | 
			
		||||
	'getDebianSrcPkg',
 | 
			
		||||
	'getUbuntuSrcPkg',
 | 
			
		||||
	'getEmailAddress',
 | 
			
		||||
	'needSponsorship',
 | 
			
		||||
	'checkExistingReports',
 | 
			
		||||
	'mailBug',
 | 
			
		||||
@ -106,18 +105,6 @@ def getDebianSrcPkg(name, release):
 | 
			
		||||
def getUbuntuSrcPkg(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):
 | 
			
		||||
	'''
 | 
			
		||||
	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
 | 
			
		||||
	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.
 | 
			
		||||
	'''
 | 
			
		||||
 | 
			
		||||
	to = 'new@bugs.launchpad.net'
 | 
			
		||||
 | 
			
		||||
	# getEmailAddress() can't fail here as the main code in requestsync
 | 
			
		||||
	# already checks its return value
 | 
			
		||||
	myemailaddr = getEmailAddress()
 | 
			
		||||
	if lpinstance == 'production':
 | 
			
		||||
		to = 'new@bugs.launchpad.net'
 | 
			
		||||
	elif lpinstance == 'staging':
 | 
			
		||||
		to = 'new@bugs.staging.launchpad.net'
 | 
			
		||||
	else:
 | 
			
		||||
		print >> sys.stderr, 'Error: Unknown launchpad instance:', lpinstance
 | 
			
		||||
		sys.exit(1)
 | 
			
		||||
 | 
			
		||||
	# generate mailbody
 | 
			
		||||
	if srcpkg:
 | 
			
		||||
@ -195,10 +186,6 @@ Content-Type: text/plain; charset=UTF-8
 | 
			
		||||
	print 'The final report is:\n%s' % mail
 | 
			
		||||
	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
 | 
			
		||||
	try:
 | 
			
		||||
		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])
 | 
			
		||||
		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:
 | 
			
		||||
		try:
 | 
			
		||||
			s.login(mailserver_user, mailserver_pass)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user