From cc8ec956b0edc5af381797efbf10daf16f83250d Mon Sep 17 00:00:00 2001 From: Michael Bienia Date: Sat, 20 Mar 2010 19:45:04 +0100 Subject: [PATCH] Factor our the spliting of the release name and the pocket name into its own function. --- ubuntu-build | 29 ++++++++++++----------------- ubuntutools/misc.py | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/ubuntu-build b/ubuntu-build index 7d17825..b252d3d 100755 --- a/ubuntu-build +++ b/ubuntu-build @@ -26,8 +26,10 @@ import sys from optparse import OptionGroup from optparse import OptionParser -from ubuntutools.lp.udtexceptions import SeriesNotFoundException, PackageNotFoundException +from ubuntutools.lp.udtexceptions import (SeriesNotFoundException, + PackageNotFoundException, PocketDoesNotExistError,) from ubuntutools.lp.lpapicache import Distribution, PersonTeam +from ubuntutools.misc import splitReleasePocket # Usage. usage = "%prog \n\n" @@ -114,13 +116,10 @@ if not options.batch: oneArch = False # split release and pocket - if '-' in release: - (release, pocket) = release.split('-') - else: - pocket = 'Release' - pocket = pocket.capitalize() - if pocket not in ('Release', 'Security', 'Updates', 'Proposed', 'Backports'): - print 'Unknown pocket: %s' % pocket + try: + (release, pocket) = splitReleasePocket(release) + except PocketDoesNotExistError, e: + print 'E: %s' % e sys.exit(1) # Get the ubuntu archive @@ -205,15 +204,11 @@ else: archs.intersection_update(valid_archs) release = options.series or Distribution('ubuntu').getDevelopmentSeries().name -pocket = 'Release' -if release and '-' in release: - # split release and pocket - (release, pocket) = options.series.split('-') - pocket = pocket.capitalize() - - if pocket not in ('Release', 'Security', 'Updates', 'Proposed', 'Backports'): - print 'Unknown pocket: %s' % pocket - sys.exit(1) +try: + (release, pocket) = splitReleasePocket(release) +except PocketDoesNotExistError, e: + print 'E: %s' % e + sys.exit(1) ubuntu_archive = Distribution('ubuntu').getArchive() try: diff --git a/ubuntutools/misc.py b/ubuntutools/misc.py index 11ed5f1..cabaa8d 100644 --- a/ubuntutools/misc.py +++ b/ubuntutools/misc.py @@ -23,6 +23,8 @@ # Modules. import os +from ubuntutools.lp.udtexceptions import PocketDoesNotExistError + def system_distribution(): """ system_distro() -> string @@ -90,3 +92,26 @@ def readlist(filename, uniq=True): items = list(set(items)) return items + +def splitReleasePocket(release): + '''Splits the release and pocket name. + + If the argument doesn't contain a pocket name then the 'Release' pocket + is assumed. + + Returns the release and pocket name. + ''' + pocket = 'Release' + + if release is None: + raise ValueError('No release name specified') + + if '-' in release: + (release, pocket) = release.split('-') + pocket = pocket.capitalize() + + if pocket not in ('Release', 'Security', 'Updates', 'Proposed', + 'Backports'): + raise PocketDoesNotExistError("Pocket '%s' does not exist." % pocket) + + return (release, pocket)