Make pylint happier.

This commit is contained in:
Benjamin Drung 2010-12-27 21:54:31 +01:00
parent b05b4aa5ce
commit b09ddfee2f
12 changed files with 346 additions and 322 deletions

View File

@ -29,16 +29,17 @@ from ubuntutools.lp.libsupport import get_launchpad
USAGE = "grab-attachments <bug numbers>"
def main():
p = OptionParser('Usage: %prog [options] <bug numbers>')
p.add_option('-l', '--lpinstance', metavar='INSTANCE',
dest='lpinstance', default=None,
help='Launchpad instance to connect to (default: production)')
p.add_option('--no-conf',
dest='no_conf', default=False, action='store_true',
help="Don't read config files or environment variables")
opts, args = p.parse_args()
parser = OptionParser('Usage: %prog [options] <bug numbers>')
parser.add_option('-l', '--lpinstance', metavar='INSTANCE',
dest='lpinstance', default=None,
help='Launchpad instance to connect to '
'(default: production)')
parser.add_option('--no-conf',
dest='no_conf', default=False, action='store_true',
help="Don't read config files or environment variables")
opts, args = parser.parse_args()
if len(args) < 1:
p.error('No bug numbers provided')
parser.error('No bug numbers provided')
config = UDTConfig(opts.no_conf)
if opts.lpinstance is None:
opts.lpinstance = config.get_value('LPINSTANCE')
@ -49,13 +50,13 @@ def main():
for arg in args:
try:
number = int(arg)
except:
p.error("'%s' is not a valid bug number." % arg)
except ValueError:
parser.error("'%s' is not a valid bug number." % arg)
b = launchpad.bugs[number]
bug = launchpad.bugs[number]
for a in b.attachments:
f = a.data.open()
for attachment in bug.attachments:
f = attachment.data.open()
filename = os.path.join(os.getcwd(), f.filename)
local_file = open(filename, "w")
local_file.write(f.read())
@ -63,10 +64,9 @@ def main():
local_file.close()
# no LP credentials
except IOError, e:
print e
except IOError, error:
print error
sys.exit(1)
if __name__ == '__main__':
main()

View File

@ -23,24 +23,28 @@ import sys
import urllib2
import json
if len(sys.argv) > 1:
match = sys.argv[1]
else:
match = None
def main():
if len(sys.argv) > 1:
match = sys.argv[1]
else:
match = None
for component in ('main', 'main-manual',
'restricted', 'restricted-manual',
'universe', 'universe-manual',
'multiverse', 'multiverse-manual'):
page = urllib2.urlopen('http://merges.ubuntu.com/%s.json' % component)
for merge in json.load(page):
package = merge['source_package']
author, uploader = '', ''
if 'user' in merge:
author = merge['user']
if 'uploader' in merge:
uploader = '(%s)' % merge['uploader']
pretty_uploader = ' '.join((author, uploader)).strip()
if (match is None or
match in package or match in author or match in uploader):
print '%s\t%s' % (package, pretty_uploader)
for component in ('main', 'main-manual',
'restricted', 'restricted-manual',
'universe', 'universe-manual',
'multiverse', 'multiverse-manual'):
page = urllib2.urlopen('http://merges.ubuntu.com/%s.json' % component)
for merge in json.load(page):
package = merge['source_package']
author, uploader = '', ''
if 'user' in merge:
author = merge['user']
if 'uploader' in merge:
uploader = '(%s)' % merge['uploader']
pretty_uploader = ' '.join((author, uploader)).strip()
if (match is None or
match in package or match in author or match in uploader):
print '%s\t%s' % (package, pretty_uploader)
if __name__ == '__main__':
main()

View File

@ -41,15 +41,14 @@ def check_args():
# Our usage options.
usage = "usage: %prog [-n <number>] launchpad-buglist-url"
optParser = OptionParser(usage)
argsParsed = 0
opt_parser = OptionParser(usage)
# Options - namely just the number of bugs to output.
optParser.add_option("-n", "--number", type = "int",
dest = "number", help = "Number of entries to output.")
opt_parser.add_option("-n", "--number", type="int",
dest="number", help="Number of entries to output.")
# Parse arguments.
(options, args) = optParser.parse_args()
(options, args) = opt_parser.parse_args()
# Check if we want a number other than the default.
howmany = options.number
@ -58,10 +57,10 @@ def check_args():
if not args:
print >> sys.stderr, "An URL pointing to a Launchpad bug list is " \
"required."
optParser.print_help()
opt_parser.print_help()
sys.exit(1)
else:
url = args[argsParsed]
url = args[0]
return (howmany, url)
@ -90,31 +89,29 @@ def main():
launchpad = None
try:
launchpad = get_launchpad("ubuntu-dev-tools")
except IOError, e:
print e
except IOError, error:
print error
sys.exit(1)
api_url = translate_web_api(url, launchpad)
try:
product = launchpad.load(api_url)
except Exception, e:
x = getattr(e, "response", {})
if x.get("status", None) == "404":
except Exception, error:
response = getattr(error, "response", {})
if response.get("status", None) == "404":
print >> sys.stderr, ("The URL at '%s' does not appear to be a "
"valid url to a product") % url
sys.exit(1)
else:
raise
bl = product.searchTasks()
bug_list = [b for b in product.searchTasks() if filter_unsolved(b)]
l = filter(filter_unsolved, bl)
if not l:
if not bug_list:
print "Bug list of %s is empty." % url
sys.exit(0)
if howmany == -1:
howmany = len(l)
howmany = len(bug_list)
print """
## ||<rowbgcolor="#CCFFCC"> This task is done || somebody || ||
@ -124,7 +121,7 @@ def main():
|| Bug || Subject || Triager ||"""
for i in list(l)[:howmany]:
for i in list(bug_list)[:howmany]:
bug = i.bug
print '||<rowbgcolor="#FFEBBB"> [%s %s] || %s || ||' % \
(translate_api_web(bug.self_link), bug.id, bug.title)

View File

@ -32,84 +32,89 @@ import SOAPpy
from ubuntutools.config import UDTConfig
from ubuntutools.lp.libsupport import get_launchpad, translate_api_web
bug_re = re.compile(r"bug=(\d+)")
def main():
bug_re = re.compile(r"bug=(\d+)")
url = 'http://bugs.debian.org/cgi-bin/soap.cgi'
namespace = 'Debbugs/SOAP'
debbugs = SOAPpy.SOAPProxy(url, namespace)
url = 'http://bugs.debian.org/cgi-bin/soap.cgi'
namespace = 'Debbugs/SOAP'
debbugs = SOAPpy.SOAPProxy(url, namespace)
# debug
#debbugs.config.dumpSOAPOut = 1
#debbugs.config.dumpSOAPIn = 1
# debug
#debbugs.config.dumpSOAPOut = 1
#debbugs.config.dumpSOAPIn = 1
parser = OptionParser(usage="%prog [option] bug ...")
parser.add_option("-b", "--browserless",
help="Don't open the bug in the browser at the end",
dest="browserless", action="store_true")
parser.add_option("-l", "--lpinstance", metavar="INSTANCE",
help="Launchpad instance to connect to (default: production)",
dest="lpinstance", default=None)
parser.add_option("-n", "--dry-run",
help=SUPPRESS_HELP,
dest="lpinstance", action="store_const", const="staging")
parser.add_option("--no-conf", dest="no_conf", default=False,
help="Don't read config files or environment variables.",
action="store_true")
(options, args) = parser.parse_args()
parser = OptionParser(usage="%prog [option] bug ...")
parser.add_option("-b", "--browserless",
help="Don't open the bug in the browser at the end",
dest="browserless", action="store_true")
parser.add_option("-l", "--lpinstance", metavar="INSTANCE",
help="Launchpad instance to connect to "
"(default: production)",
dest="lpinstance", default=None)
parser.add_option("-n", "--dry-run",
help=SUPPRESS_HELP,
dest="lpinstance", action="store_const", const="staging")
parser.add_option("--no-conf", dest="no_conf", default=False,
help="Don't read config files or environment variables.",
action="store_true")
(options, args) = parser.parse_args()
config = UDTConfig(options.no_conf)
if options.lpinstance is None:
options.lpinstance = config.get_value("LPINSTANCE")
config = UDTConfig(options.no_conf)
if options.lpinstance is None:
options.lpinstance = config.get_value("LPINSTANCE")
try:
lp = get_launchpad("ubuntu-dev-tools", options.lpinstance)
except IOError, msg:
print msg
print "No credentials, can't continue"
sys.exit(1)
try:
launchpad = get_launchpad("ubuntu-dev-tools", options.lpinstance)
except IOError, msg:
print msg
print "No credentials, can't continue"
sys.exit(1)
debian = lp.distributions['debian']
ubuntu = lp.distributions['ubuntu']
lp_debbugs = lp.bug_trackers.getByName(name='debbugs')
debian = launchpad.distributions['debian']
ubuntu = launchpad.distributions['ubuntu']
lp_debbugs = launchpad.bug_trackers.getByName(name='debbugs')
bug_nums = []
bug_nums = []
for bug_num in args:
if bug_num.startswith("http"):
# bug URL
match = bug_re.search(bug_num)
if match is None:
raise ValueError("Can't determine bug number from %s" % bug_num)
bug_num = match.groups()[0]
bug_num = bug_num.lstrip("#")
bug_num = int(bug_num)
bug_nums.append(bug_num)
for bug_num in args:
if bug_num.startswith("http"):
# bug URL
match = bug_re.search(bug_num)
if match is None:
raise ValueError("Can't determine bug number from %s" % bug_num)
bug_num = match.groups()[0]
bug_num = bug_num.lstrip("#")
bug_num = int(bug_num)
bug_nums.append(bug_num)
bugs = debbugs.get_status(*bug_nums)
bugs = debbugs.get_status(*bug_nums)
if len(bug_nums) > 1:
bugs = bugs[0]
if len(bug_nums) > 1:
bugs = bugs[0]
#import pdb; pdb.set_trace()
for bug in bugs:
bug = bug.value
package = bug.package
bug_num = bug.bug_num
subject = bug.subject
log = debbugs.get_bug_log(bug_num)
summary = log[0][0]
target = ubuntu.getSourcePackage(name=package)
u_bug = lp.bugs.createBug(target=target, title=subject,
description="Imported from Debian bug %d:\n\n%s"
% (bug_num, summary))
d_task = u_bug.addTask(target=debian.getSourcePackage(name=package))
d_watch = u_bug.addWatch(remote_bug=bug_num, bug_tracker=lp_debbugs)
d_task.bug_watch = d_watch
d_task.lp_save()
web_url = translate_api_web(u_bug.self_link)
print "Opened %s" % web_url
if not options.browserless:
subprocess.call(["xdg-open", web_url])
#import pdb; pdb.set_trace()
for bug in bugs:
bug = bug.value
package = bug.package
bug_num = bug.bug_num
subject = bug.subject
log = debbugs.get_bug_log(bug_num)
summary = log[0][0]
target = ubuntu.getSourcePackage(name=package)
u_bug = launchpad.bugs.createBug(target=target, title=subject,
description="Imported from Debian bug %d:\n\n%s"
% (bug_num, summary))
d_task = u_bug.addTask(target=debian.getSourcePackage(name=package))
d_watch = u_bug.addWatch(remote_bug=bug_num, bug_tracker=lp_debbugs)
d_task.bug_watch = d_watch
d_task.lp_save()
web_url = translate_api_web(u_bug.self_link)
print "Opened %s" % web_url
if not options.browserless:
subprocess.call(["xdg-open", web_url])
if __name__ == '__main__':
main()
#def get_status(*args):
# result = server.get_status(*args)

View File

@ -29,33 +29,36 @@ from optparse import OptionParser
from ubuntutools.lp.libsupport import get_launchpad
from launchpadlib.errors import HTTPError
if __name__ == '__main__':
def main():
usage = "Usage: %prog <bug> [...]"
parser = OptionParser(usage)
options, args = parser.parse_args()
args = parser.parse_args()[1]
if len(args) < 1:
parser.error("Need at least one bug number")
try:
lp = get_launchpad('ubuntu-dev-tools')
except Exception, e:
print >> sys.stderr, 'Could not connect to Launchpad:', str(e)
launchpad = get_launchpad('ubuntu-dev-tools')
except Exception, error:
print >> sys.stderr, 'Could not connect to Launchpad:', str(error)
sys.exit(2)
for bugnum in args:
try:
bug = lp.bugs[bugnum]
bug = launchpad.bugs[bugnum]
print "Bug %s: %s" % (bugnum, bug.title)
for task in bug.bug_tasks:
print " %s: %s" % (task.bug_target_name, task.status)
except HTTPError, e:
if e.response.status == 401:
except HTTPError, error:
if error.response.status == 401:
print >> sys.stderr, \
("E: Don't have enough permissions to access bug %s" %
bugnum)
print >> sys.stderr, e.content
print >> sys.stderr, error.content
continue
elif e.response.status == 404:
elif error.response.status == 404:
print >> sys.stderr, "E: Bug %s not found" % bugnum
else:
raise
if __name__ == '__main__':
main()

View File

@ -18,7 +18,11 @@
'''Upload a release tarball to a Launchpad project.'''
import sys, datetime, os.path, subprocess, tempfile, os
import datetime
import os
import subprocess
import sys
import tempfile
from ubuntutools.lp.libsupport import get_launchpad
from launchpadlib.errors import HTTPError
@ -32,19 +36,19 @@ def create_release(project, version):
if answer.startswith('n'):
sys.exit(0)
n_series = len(proj.series)
n_series = len(project.series)
if n_series == 1:
series = proj.series[0]
series = project.series[0]
elif n_series > 1:
msg = 'More than one series exist. Which one would you like to ' \
'upload to? Possible series are (listed as index, name):'
print msg
for idx, serie in enumerate(proj.series):
for idx, serie in enumerate(project.series):
print '\t%i - %s' % (idx, serie.name)
print 'Enter series index: '
answer = sys.stdin.readline().strip()
try:
series = proj.series[int(answer)]
series = project.series[int(answer)]
except (ValueError, IndexError):
print >> sys.stderr, 'The series index is invalid (%s).' % answer
sys.exit(3)
@ -67,75 +71,74 @@ def edit_file(prefix, description):
os.close(fd)
subprocess.call(['sensible-editor', f])
content = ''
for l in open(f):
if l.startswith('#'):
for line in open(f):
if line.startswith('#'):
continue
content += l
content += line
return content.strip()
#
# main
#
def main():
if len(sys.argv) != 4:
print >> sys.stderr, '''Upload a release tarball to a Launchpad project.
if len(sys.argv) != 4:
print >> sys.stderr, '''Upload a release tarball to a Launchpad project.
Usage: %s <project name> <version> <tarball>''' % sys.argv[0]
sys.exit(1)
Usage: %s <project name> <version> <tarball>''' % sys.argv[0]
sys.exit(1)
(project, version, tarball) = sys.argv[1:]
(project, version, tarball) = sys.argv[1:]
try:
launchpad = get_launchpad('ubuntu-dev-tools')
except Exception, error:
print >> sys.stderr, 'Could not connect to Launchpad:', str(error)
sys.exit(2)
try:
lp = get_launchpad('ubuntu-dev-tools')
except Exception, e:
print >> sys.stderr, 'Could not connect to Launchpad:', str(e)
sys.exit(2)
try:
# Look up the project using the Launchpad instance.
proj = launchpad.projects[project]
# Find the release in the project's releases collection.
release = None
for rel in proj.releases:
if rel.version == version:
release = rel
break
if not release:
release = create_release(proj, version)
try:
# Look up the project using the Launchpad instance.
proj = lp.projects[project]
# Find the release in the project's releases collection.
release = None
for rel in proj.releases:
if rel.version == version:
release = rel
break
if not release:
release = create_release(proj, version)
# Get the file contents.
file_content = open(tarball, 'r').read()
# Get the signature, if available.
signature = tarball + '.asc'
if not os.path.exists(signature):
print 'Calling GPG to create tarball signature...'
cmd = ['gpg', '--armor', '--sign', '--detach-sig', tarball]
if subprocess.call(cmd) != 0:
print >> sys.stderr, 'gpg failed, aborting'
# Get the file contents.
file_content = open(tarball, 'r').read()
# Get the signature, if available.
signature = tarball + '.asc'
if not os.path.exists(signature):
print 'Calling GPG to create tarball signature...'
cmd = ['gpg', '--armor', '--sign', '--detach-sig', tarball]
if subprocess.call(cmd) != 0:
print >> sys.stderr, 'gpg failed, aborting'
if os.path.exists(signature):
signature_content = open(signature, 'r').read()
else:
signature_content = None
if os.path.exists(signature):
signature_content = open(signature, 'r').read()
else:
signature_content = None
# Create a new product release file.
filename = os.path.basename(tarball)
release.add_file(filename=filename, description='release tarball',
file_content=file_content, content_type='appplication/x-gzip',
file_type='Code Release Tarball', signature_filename=signature,
signature_content=signature_content)
# Create a new product release file.
filename = os.path.basename(tarball)
release.add_file(filename=filename, description='release tarball',
file_content=file_content, content_type='appplication/x-gzip',
file_type='Code Release Tarball', signature_filename=signature,
signature_content=signature_content)
changelog = edit_file('changelog', 'changelog')
if changelog:
release.changelog = changelog
release_notes = edit_file('releasenotes', 'release notes')
if release_notes:
release.release_notes = release_notes
changelog = edit_file('changelog', 'changelog')
if changelog:
release.changelog = changelog
release_notes = edit_file('releasenotes', 'release notes')
if release_notes:
release.release_notes = release_notes
release.lp_save()
release.lp_save()
except HTTPError, e:
print 'An error happened in the upload:', e.content
sys.exit(1)
except HTTPError, error:
print 'An error happened in the upload:', error.content
sys.exit(1)
if __name__ == '__main__':
main()

View File

@ -84,15 +84,15 @@ def main():
raise
new_main_dup_of = new_main_bug.duplicate_of
if new_main_dup_of is not None:
s = None
answer = None
try:
s = raw_input("Bug %s is a duplicate of %s; would you like to use "
"%s as the new main bug instead? [y/N]" % \
(new_main_bug.id, new_main_dup_of.id,
new_main_dup_of.id))
answer = raw_input("Bug %s is a duplicate of %s; would you like to "
"use %s as the new main bug instead? [y/N]" % \
(new_main_bug.id, new_main_dup_of.id,
new_main_dup_of.id))
except:
die("Aborted")
if s.lower() not in ("y", "yes"):
if answer.lower() not in ("y", "yes"):
die("User aborted")
new_main_bug = new_main_dup_of
@ -121,12 +121,12 @@ def main():
(new_main_bug.id, " ".join([str(b.id) for b in bugs_to_process]))
if not options.force:
s = None
answer = None
try:
s = raw_input("Proceed? [y/N]")
answer = raw_input("Proceed? [y/N]")
except:
die("Aborted")
if s.lower() not in ("y", "yes"):
if answer.lower() not in ("y", "yes"):
die("User aborted")
for bug in bugs_to_process:

104
lp-shell
View File

@ -23,60 +23,64 @@ from optparse import OptionParser
from launchpadlib.launchpad import Launchpad
from launchpadlib.uris import lookup_service_root
instance = 'production'
valid_api_versions = ('beta', '1.0', 'devel')
api_version = '1.0'
def main():
instance = 'production'
valid_api_versions = ('beta', '1.0', 'devel')
api_version = '1.0'
usage = 'Usage: %prog [-a] [instance] [LP API version]'
optParser = OptionParser(usage)
optParser.add_option('-a', action='store_true',
dest='anonymous', default=False,
help='Login anonymously into LP.')
usage = 'Usage: %prog [-a] [instance] [LP API version]'
opt_parser = OptionParser(usage)
opt_parser.add_option('-a', action='store_true',
dest='anonymous', default=False,
help='Login anonymously into LP.')
(options, args) = optParser.parse_args()
(options, args) = opt_parser.parse_args()
if len(args) >= 1:
try:
instance = lookup_service_root(args[0])
except ValueError, err:
print 'E: %s' % (err)
print 'I: Falling back to "production".'
if len(args) >= 2:
if args[1] in valid_api_versions:
api_version = args[1]
else:
print 'E: "%s" is not a valid LP API version.' % (args[1])
print 'I: Falling back to "1.0".'
if options.anonymous:
lp = Launchpad.login_anonymously('udt-lp-shell', instance,
version=api_version)
banner = 'Connected anonymously to LP service "%s" with API version "%s":' \
% (instance, api_version)
else:
lp = Launchpad.login_with('udt-lp-shell', instance, version=api_version)
banner = 'Connected to LP service "%s" with API version "%s":' % \
(instance, api_version)
banner += '\nNote: LP can be accessed through the "lp" object.'
class CompleterConsole(code.InteractiveConsole):
def __init__(self):
local = {'lp': lp}
code.InteractiveConsole.__init__(self,
locals=local)
if len(args) >= 1:
try:
import readline
except ImportError:
print 'I: readline module not available.'
instance = lookup_service_root(args[0])
except ValueError, err:
print 'E: %s' % (err)
print 'I: Falling back to "production".'
if len(args) >= 2:
if args[1] in valid_api_versions:
api_version = args[1]
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
print 'E: "%s" is not a valid LP API version.' % (args[1])
print 'I: Falling back to "1.0".'
# Disable default apport hook, as lp-shell is intended for interactive use
# and thus exceptions often bubble up to the top level.
sys.excepthook = sys.__excepthook__
if options.anonymous:
launchpad = Launchpad.login_anonymously('udt-lp-shell', instance,
version=api_version)
banner = ('Connected anonymously to LP service "%s" with API version '
'"%s":' % (instance, api_version))
else:
launchpad = Launchpad.login_with('udt-lp-shell', instance,
version=api_version)
banner = 'Connected to LP service "%s" with API version "%s":' % \
(instance, api_version)
console = CompleterConsole()
console.interact(banner)
banner += '\nNote: LP can be accessed through the "lp" object.'
class CompleterConsole(code.InteractiveConsole):
def __init__(self):
local = {'lp': launchpad}
code.InteractiveConsole.__init__(self, locals=local)
try:
import readline
except ImportError:
print 'I: readline module not available.'
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
# Disable default apport hook, as lp-shell is intended for interactive use
# and thus exceptions often bubble up to the top level.
sys.excepthook = sys.__excepthook__
console = CompleterConsole()
console.interact(banner)
if __name__ == '__main__':
main()

View File

@ -96,12 +96,13 @@ def create_credentials(options):
if options.output:
filepath = options.output
else:
credentialsDir = os.path.expanduser("~/.cache/lp_credentials")
if not os.path.isdir(credentialsDir):
os.makedirs(credentialsDir)
os.chmod(credentialsDir, 0700)
filepath = os.path.expanduser("%s/%s-%s.txt" % \
(credentialsDir, options.consumer, str(options.level).lower()))
credentials_dir = os.path.expanduser("~/.cache/lp_credentials")
if not os.path.isdir(credentials_dir):
os.makedirs(credentials_dir)
os.chmod(credentials_dir, 0700)
filepath = os.path.expanduser("%s/%s-%s.txt" %
(credentials_dir, options.consumer,
str(options.level).lower()))
f = open(filepath, "w")
# Make credentials file non-world readable.

View File

@ -88,16 +88,16 @@ def file_bug(config, launchpad):
product_url = "%subuntu/+source/%s" % \
(launchpad._root_uri, config["sourcepackage"])
tags = filter(None, map(lambda t: t.strip("\n").strip(),
config["tags"].split(",")))
tags = [t for t in [t.strip("\n").strip() for t in
config["tags"].split(",")] if t]
bug = launchpad.bugs.createBug(description=description, title=summary,
target=product_url, tags=tags)
print "Successfully filed bug %i: %s" % \
(bug.id, translate_api_web(bug.self_link))
subscribers = filter(None, map(lambda t: t.strip("\n").strip(),
config["subscribers"].split(",")))
subscribers = [s for s in [s.strip("\n").strip() for s in
config["subscribers"].split(",")] if s]
for sub in subscribers:
subscribe_url = "%s~%s" % (launchpad._root_uri, sub)
bug.subscribe(person=subscribe_url)
@ -145,18 +145,19 @@ def read_buglist(url, launchpad):
return packages
def main():
p = optparse.OptionParser(description=
'Files bugs against multiple packages in Ubuntu. '
'Reads the bug from "instructions" and files them against '
'packages listed in "list". '
"If these files aren't preset they are created.")
p.add_option('-l', '--lpinstance', metavar='INSTANCE',
dest='lpinstance', default=None,
help='Launchpad instance to connect to (default: production)')
p.add_option('--no-conf',
dest='no_conf', default=False, action='store_true',
help="Don't read config files or environment variables")
options, args = p.parse_args()
description = ('Files bugs against multiple packages in Ubuntu. '
'Reads the bug from "instructions" and files them against '
'packages listed in "list". '
"If these files aren't preset they are created.")
parser = optparse.OptionParser(description=description)
parser.add_option('-l', '--lpinstance', metavar='INSTANCE',
dest='lpinstance', default=None,
help='Launchpad instance to connect to '
'(default: production)')
parser.add_option('--no-conf',
dest='no_conf', default=False, action='store_true',
help="Don't read config files or environment variables")
options = parser.parse_args()[0]
udtconfig = UDTConfig(options.no_conf)
if options.lpinstance is None:
options.lpinstance = udtconfig.get_value('LPINSTANCE')

View File

@ -18,9 +18,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys, re
import re
import sys
def usage(exit=1):
def usage(exit_code=1):
print '''Usage: merge-changelog <left changelog> <right changelog>
merge-changelog takes two changelogs that once shared a common source,
@ -28,7 +29,7 @@ merges them back together, and prints the merged result to stdout. This
is useful if you need to manually merge a ubuntu package with a new
Debian release of the package.
'''
sys.exit(exit)
sys.exit(exit_code)
########################################################################
# Changelog Management
@ -54,7 +55,7 @@ def merge_changelog(left_changelog, right_changelog):
print right_text
for left_ver, left_text in left_cl:
for _, left_text in left_cl:
print left_text
return False
@ -63,10 +64,10 @@ def read_changelog(filename):
"""Return a parsed changelog file."""
entries = []
cl = open(filename)
changelog_file = open(filename)
try:
(ver, text) = (None, "")
for line in cl:
for line in changelog_file:
match = CL_RE.search(line)
if match:
try:
@ -85,7 +86,7 @@ def read_changelog(filename):
elif len(line.strip()) or ver is not None:
text += line
finally:
cl.close()
changelog_file.close()
if len(text):
entries.append((ver, text))
@ -96,12 +97,12 @@ def read_changelog(filename):
# Version parsing code
########################################################################
# Regular expressions make validating things easy
valid_epoch = re.compile(r'^[0-9]+$')
valid_upstream = re.compile(r'^[A-Za-z0-9+:.~-]*$')
valid_revision = re.compile(r'^[A-Za-z0-9+.~]+$')
VALID_EPOCH = re.compile(r'^[0-9]+$')
VALID_UPSTREAM = re.compile(r'^[A-Za-z0-9+:.~-]*$')
VALID_REVISION = re.compile(r'^[A-Za-z0-9+.~]+$')
# Character comparison table for upstream and revision components
cmp_table = "~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+-.:"
CMP_TABLE = "~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+-.:"
class Version(object):
@ -137,7 +138,7 @@ class Version(object):
self.epoch = ver[:idx]
if not len(self.epoch):
raise ValueError
if not valid_epoch.search(self.epoch):
if not VALID_EPOCH.search(self.epoch):
raise ValueError
ver = ver[idx+1:]
@ -147,7 +148,7 @@ class Version(object):
self.revision = ver[idx+1:]
if not len(self.revision):
raise ValueError
if not valid_revision.search(self.revision):
if not VALID_REVISION.search(self.revision):
raise ValueError
ver = ver[:idx]
@ -155,29 +156,29 @@ class Version(object):
self.upstream = ver
if not len(self.upstream):
raise ValueError
if not valid_upstream.search(self.upstream):
if not VALID_UPSTREAM.search(self.upstream):
raise ValueError
self.epoch = int(self.epoch)
def getWithoutEpoch(self):
def get_without_epoch(self):
"""Return the version without the epoch."""
str = self.upstream
string = self.upstream
if self.revision is not None:
str += "-%s" % (self.revision,)
return str
string += "-%s" % (self.revision,)
return string
without_epoch = property(getWithoutEpoch)
without_epoch = property(get_without_epoch)
def __str__(self):
"""Return the class as a string for printing."""
str = ""
string = ""
if self.epoch > 0:
str += "%d:" % (self.epoch,)
str += self.upstream
string += "%d:" % (self.epoch,)
string += self.upstream
if self.revision is not None:
str += "-%s" % (self.revision,)
return str
string += "-%s" % (self.revision,)
return string
def __repr__(self):
"""Return a debugging representation of the object."""
@ -190,34 +191,37 @@ class Version(object):
other = Version(other)
result = cmp(self.epoch, other.epoch)
if result != 0: return result
if result != 0:
return result
result = deb_cmp(self.upstream, other.upstream)
if result != 0: return result
if result != 0:
return result
result = deb_cmp(self.revision or "", other.revision or "")
if result != 0: return result
if result != 0:
return result
return 0
def strcut(str, idx, accept):
"""Cut characters from str that are entirely in accept."""
def strcut(string, idx, accept):
"""Cut characters from string that are entirely in accept."""
ret = ""
while idx < len(str) and str[idx] in accept:
ret += str[idx]
while idx < len(string) and string[idx] in accept:
ret += string[idx]
idx += 1
return (ret, idx)
def deb_order(str, idx):
def deb_order(string, idx):
"""Return the comparison order of two characters."""
if idx >= len(str):
if idx >= len(string):
return 0
elif str[idx] == "~":
elif string[idx] == "~":
return -1
else:
return cmp_table.index(str[idx])
return CMP_TABLE.index(string[idx])
def deb_cmp_str(x, y):
"""Compare two strings in a deb version."""
@ -238,25 +242,27 @@ def deb_cmp(x, y):
x_idx = y_idx = 0
while x_idx < len(x) or y_idx < len(y):
# Compare strings
(x_str, x_idx) = strcut(x, x_idx, cmp_table)
(y_str, y_idx) = strcut(y, y_idx, cmp_table)
(x_str, x_idx) = strcut(x, x_idx, CMP_TABLE)
(y_str, y_idx) = strcut(y, y_idx, CMP_TABLE)
result = deb_cmp_str(x_str, y_str)
if result != 0: return result
if result != 0:
return result
# Compare numbers
(x_str, x_idx) = strcut(x, x_idx, "0123456789")
(y_str, y_idx) = strcut(y, y_idx, "0123456789")
result = cmp(int(x_str or "0"), int(y_str or "0"))
if result != 0: return result
if result != 0:
return result
return 0
def main():
if len(sys.argv) > 1 and sys.argv[1] in ('-h', '--help'):
usage(exit=0)
usage(0)
if len(sys.argv) != 3:
usage(exit=1)
usage(1)
left_changelog = sys.argv[1]
right_changelog = sys.argv[2]

View File

@ -38,7 +38,7 @@ import ubuntutools.misc
DEBIAN_DISTROS = ['etch', 'lenny', 'squeeze', 'sid', 'stable', 'testing',
'unstable', 'experimental']
class pbuilder_dist:
class PbuilderDist:
def __init__(self, builder):
# Base directory where pbuilder will put all the files it creates.
self.base = None
@ -116,7 +116,7 @@ class pbuilder_dist:
self.target_distro = self.system_distro
def set_target_distro(self, distro):
""" pbuilder_dist.set_target_distro(distro) -> None
""" PbuilderDist.set_target_distro(distro) -> None
Check if the given target distribution name is correct, if it
isn't know to the system ask the user for confirmation before
@ -145,7 +145,7 @@ class pbuilder_dist:
self.target_distro = distro
def set_operation(self, operation):
""" pbuilder_dist.set_operation -> None
""" PbuilderDist.set_operation -> None
Check if the given string is a valid pbuilder operation and
depending on this either save it into the appropiate variable
@ -172,7 +172,7 @@ class pbuilder_dist:
return []
def get_command(self, remaining_arguments = None):
""" pbuilder_dist.get_command -> string
""" PbuilderDist.get_command -> string
Generate the pbuilder command which matches the given configuration
and return it as a string.
@ -329,7 +329,7 @@ def show_help(exit_code = 0):
def main():
""" main() -> None
This is pbuilder-dist's main function. It creates a pbuilder_dist
This is pbuilder-dist's main function. It creates a PbuilderDist
object, modifies all necessary settings taking data from the
executable's name and command line options and finally either ends
the script and runs pbuilder itself or exists with an error message.
@ -353,7 +353,7 @@ def main():
if args[0] in ('-h', '--help', 'help'):
show_help(0)
app = pbuilder_dist(parts[0])
app = PbuilderDist(parts[0])
if len(parts) > 1 and parts[1] != 'dist' and '.' not in parts[1]:
app.set_target_distro(parts[1])