move pbuilder-dist to pbuilder-dist.new and restore published pbuilder-dist so the bzr tree is publishable

This commit is contained in:
Kees Cook 2008-06-13 11:22:01 -07:00
parent ea9597604b
commit 62c5cb5f0b
3 changed files with 618 additions and 306 deletions

8
debian/changelog vendored
View File

@ -1,9 +1,8 @@
ubuntu-dev-tools (0.31) UNRELEASED; urgency=low ubuntu-dev-tools (0.31) UNRELEASED; urgency=low
[ Siegfried-Angel Gevatter Pujals (RainCT) ] [ Siegfried-Angel Gevatter Pujals (RainCT) ]
* pbuilder-dist: * pbuilder-dist.new:
- Rewrite the script in Python to make it more robust and faster. - Rewrite the script in Python to make it more robust and faster.
- ^^^ NOT FINISHED YET, DO NOT UPLOAD THIS! ^^^
* what-patch: * what-patch:
- If cdbs-edit-patch is used, output "cdbs (patchsys.mk)" instead of - If cdbs-edit-patch is used, output "cdbs (patchsys.mk)" instead of
just "cdbs" (LP: #195795). just "cdbs" (LP: #195795).
@ -38,8 +37,11 @@ ubuntu-dev-tools (0.31) UNRELEASED; urgency=low
* mk-sbuild-lv * mk-sbuild-lv
- don't install recommended packages during chroot install. - don't install recommended packages during chroot install.
- allow customization of schroot.conf suffix and LV/snapshot sizes. - allow customization of schroot.conf suffix and LV/snapshot sizes.
* what-patch:
- restore previous output behavior, added logic to verbose test instead.
- added details for each patch system report.
-- Kees Cook <kees@ubuntu.com> Fri, 13 Jun 2008 10:52:14 -0700 -- Kees Cook <kees@ubuntu.com> Fri, 13 Jun 2008 11:10:44 -0700
ubuntu-dev-tools (0.30) hardy; urgency=low ubuntu-dev-tools (0.30) hardy; urgency=low

View File

@ -1,9 +1,8 @@
#! /usr/bin/env python #!/bin/sh
# -*- coding: utf-8 -*-
# #
# Copyright (C) Jamin W. Collins <jcollins@asgardsrealm.net>
# Copyright (C) Jordan Mantha <mantha@ubuntu.com>
# Copyright (C) 2007-2008 Siegfried-A. Gevatter <rainct@ubuntu.com> # Copyright (C) 2007-2008 Siegfried-A. Gevatter <rainct@ubuntu.com>
# With some changes by Iain Lane <iain@orangesquash.org.uk>
# Based upon pbuilder-dist-simple by Jamin Collins and Jordan Mantha.
# #
# License: GPLv2 or later # License: GPLv2 or later
# #
@ -12,311 +11,300 @@
# #
# You can create symlinks to a pbuilder-dist executable to get different # You can create symlinks to a pbuilder-dist executable to get different
# configurations. For example, a symlink called pbuilder-hardy will assume # configurations. For example, a symlink called pbuilder-hardy will assume
# that the target distribution is always meant to be Ubuntu Hardy. # that the target distribution is always Ubuntu Hardy.
import sys ######################################################################
import os
# Base directory where pbuilder will put all the files it creates.
class pbuilder_dist: # This is overriden by the global variable $PBUILDFOLDER
BASE_DIR="$HOME/pbuilder"
def __init__(self):
# Change this to 0 if you don't want additional components to be used.
# Base directory where pbuilder will put all the files it creates. # That is, 'universe' and 'multiverse' for Ubuntu chroots and 'contrib'
self.base = None # and 'non-free' for Debian. (This option can be overwriten at runtime).
EXTRACOMP=1
# Name of the operation which pbuilder should perform.
self.operation = None # Change this to 1 if you want the log for the last operation to be saved
# in the base directory by default (it will be named '.lastlog').
# Wheter additional components should be used or not. That is, SAVELOG=0
# 'universe' and 'multiverse' for Ubuntu chroots and 'contrib'
# and 'non-free' for Debian. # Allow this script to use /var/cache/apt/archives/ when possible.
self.extra_components = True if [ -z $SYSCACHE ]
then
# File where the log of the last operation will be saved. SYSCACHE=1
self.logfile = None fi
# System architecture ######################################################################
self.system_architecture = None
# Detect system architecture
# Build architecture REALARCH=$(dpkg-architecture -qDEB_HOST_ARCH)
self.build_architecture = None
# Detect Ubuntu distribution (wheter it is gutsy, hardy, etc.)
# System's distribution SYSDIST=$(lsb_release -cs 2>/dev/null)
self.system_distro = None
# Overwrite hardcoded base directory by that one in the global variable
# Target distribution if [ $PBUILDFOLDER ] && [ $PBUILDFOLDER != "" ]
self.target_distro = None then
BASE_DIR=$PBUILDFOLDER
# This is an identificative string which will either take the form fi
# 'distribution' or 'distribution-architecture'.
self.chroot_string = None ######################################################################
# Proxy # Abort if the name of the executable has hypens but it doesn't
self.proxy = None # start with "pbuilder-".
if [ -n $(basename $0 | grep '-') ] && [ $(basename $0 | cut -d'-' -f1) != 'pbuilder' ]
# Authentication method then
self.auth = 'sudo' echo "Error: " $(basename $0) " is not a valid name for a pbuilder-dist executable."
exit 1
############################################################## fi
if 'PBUILDFOLDER' in os.environ: # Detect if the script has it's original name or if a symlink is being used,
self.base = os.environ['PBUILDFOLDER'] # and if it's a symlink extract the information that it contains.
else: if [ -n $(basename $0 | grep '-') ] && [ `basename $0` != 'pbuilder-dist' ]
self.base = os.path.expanduser('~/pbuilder/') then
ORIGINAL_NAME=0
if not os.path.exists(self.base): DISTRIBUTION=$(basename $0 | cut -d'-' -f2)
os.makedirs(self.base) ARCHITECTURE=$(basename $0 | cut -d'-' -f3)
else
if 'PBUILDAUTH' in os.environ: ORIGINAL_NAME=1
self.auth = os.environ['PBUILDAUTH'] DISTRIBUTION=$1
shift 1
self.system_architecture = host_architecture() fi
if not self.system_architecture or 'not found' in self.system_architecture: # Check if the choosen architecture is supported on the user's system.
print 'Error: Not running on a Debian based system; could not detect its architecture.' if [ "$1" = 'i386' ] || [ "$1" = 'amd64' ]
then
if not os.path.isfile('/etc/lsb-release'): if [ $REALARCH = 'amd64' ]; then
print 'Error: Not running on a Debian based system; could not find /etc/lsb-release.' ARCHITECTURE=$1
exit(1) else
echo "Warning: Architecture switching is not supported on your system; ignoring argument '$1'."
for line in open('/etc/lsb-release'): fi
line = line.strip()
if line.startswith('DISTRIB_CODENAME'): shift 1
self.system_distro = line[17:] fi
break
# If architecture hasn't been set yet, use the system's one.
if not self.system_distro: if [ -z "$ARCHITECTURE" ]
print 'Error: Could not determine what distribution you are running.' then
exit(1) ARCHITECTURE=$REALARCH
fi
self.target_distro = self.system_distro
# Check if there's a component modifier
if 'http_proxy' in os.environ: if [ "$1" = 'mainonly' ]; then
self.base = os.environ['http_proxy'] EXTRACOMP=0
elif 'HTTP_PROXY' in os.environ: shift 1
self.base = os.environ['HTTP_PROXY'] elif [ "$1" = 'allcomp' ]; then
EXTRACOMP=1
############################################################## shift 1
fi
def __getitem__(self, name):
# Check if the default logging preferences should be overwriten
return getattr(self, name) if [ "$1" = 'withlog' ]; then
SAVELOG=1
def _calculate(self): shift 1
""" pbuilder_dist.calculate(distro) -> None elif [ "$1" = 'nolog' ]; then
SAVELOG=0
Do all necessary variable changes (and therefore required checks) shift 1
before the string that will be executed is generated. At this fi
point it's expected that no more variables will be modified
outside this class. # Check if some proxy should be used.
if [ -n "$http_proxy" ]
""" then
PROXY=$http_proxy
if not self.build_architecture: fi
self.chroot_string = self.target_distro
self.build_architecture = self.system_architecture if [ -z "$PROXY" ] && [ -n "$HTTP_PROXY" ]
else: then
self.chroot_string = '%(target_distro)s-%(build_architecture)s' % self PROXY=$HTTP_PROXY
fi
if not self.logfile:
self.logfile = '%(base)s.%(chroot_string)s.log' % self ######################################################################
def set_target_distro(self, distro): usage()
""" pbuilder_dist.set_target_distro(distro) -> None {
echo "Usage: $0 "$( [ $ORIGINAL_NAME = 0 ] || echo "<distribution> " )$( [ $ARCHITECTURE != "amd64" ] || echo "[i386|amd64] " )"[mainonly|allcomp] [withlog|nolog] <operation>"
Check if the given target distribution name is correct, if it }
isn't know to the system ask the user for confirmation before
proceeding, and finally either save the value into the appropiate distdata()
variable or finalize pbuilder-dist's execution. {
# Populate variables with Debian / Ubuntu specific data
""" if [ "$1" = "debian" ]
then
if not distro.isalpha(): # Set Debian specific data
print 'Error: «%s» is an invalid distribution codename.' % distro
sys.exit(1) ISDEBIAN=True
if not os.path.isfile(os.path.join('/usr/share/debootstrap/scripts/', distro)): if [ -z $ARCHIVE ]
answer = ask('Warning: Unknown distribution «%s». Do you want to continue [y/N]? ' % distro) then
if answer not in ('y', 'Y'): ARCHIVE="http://ftp.debian.org"
sys.exit(0) fi
self.target_distro = distro COMPONENTS="main"$( [ $EXTRACOMP = 0 ] || echo " contrib non-free" )
else
def set_operation(self, operation): # Set Ubuntu specific data
""" pbuilder_dist.set_operation -> None
ISDEBIAN=False
Check if the given string is a valid pbuilder operation and
depending on this either save it into the appropiate variable if [ -z $ARCHIVE ]
or finalize pbuilder-dist's execution. then
ARCHIVE="http://archive.ubuntu.com/ubuntu"
""" fi
arguments = ('create', 'update', 'build', 'clean', 'login', 'execute') COMPONENTS="main restricted"$( [ $EXTRACOMP = 0 ] || echo " universe multiverse" )
fi
if operation not in arguments: }
if item_ends_with(arguments, '.dsc'):
self.operation = 'build' ######################################################################
else:
print 'Error: «%s» is not a recognized argument.' % operation # Check if there is at least one argument remaining.
print 'Please use one of those: ' + ', '.join(arguments) + '.' if [ $# -lt 1 ]
sys.exit(1) then
else: echo "You provided an insufficent number of arguments."
self.operation = operation usage
exit 1
def get_command(self, remaining_arguments = None): fi
""" pbuilder_dist.get_command -> string
######################################################################
Generate the pbuilder command which matches the given configuration
and return it as a string. # Check if the distribution exists, and fill the variables that change
# depending on wheter the target distribution is Ubuntu or Debian.
""" case $DISTRIBUTION in
dapper|edgy|feisty|gutsy|hardy)
# Calculate variables which depend on arguments given at runtime. distdata ubuntu
self._calculate() ;;
arguments = [ oldstable|sarge|stable|etch|testing|lenny|unstable|sid|experimental)
self.operation, distdata debian
'--basetgz "%(base)s%(chroot_string)s-base.tgz"' % self, ;;
'--distribution "%(target_distro)s"' % self,
'--buildresult "%(base)s%(chroot_string)s_result/"' % self, *)
'--logfile "%(logfile)s"' % self, if [ ! -d $BASE_DIR/${DISTRIBUTION}-* ]
'--aptcache "/var/cache/apt/archives/"', then
### --mirror "${ARCHIVE}" \ echo -n "Warning: Unknown distribution «$DISTRIBUTION». Do you want to continue [y/N]? "
] read continue
if self.build_architecture != self.system_architecture: if [ "$continue" != 'y' ] && [ "$continue" != 'Y' ]
arguments.append('--debootstrapopts --arch') then
arguments.append('--debootstrapopts "%(build_architecture)s"' % self) echo "Aborting..."
exit 1
if self.proxy: fi
arguments.append('--http-proxy "%(proxy)s"' % self) fi
### $( [ $ISDEBIAN != "False" ] || echo "--aptconfdir \"${BASE_DIR}/etc/${DISTRIBUTION}/apt.conf/\"" ) \ distdata ubuntu
;;
# Append remaining arguments esac
if remaining_arguments:
arguments.extend(remaining_arguments) # Save the selected operation in a variable.
OPERATION=$1
return self.auth + ' /usr/sbin/pbuilder ' + ' '.join(arguments) shift 1
def host_architecture(): # Check if the selected operation is an alias for another one.
""" host_architecture -> string case "$OPERATION" in
upgrade)
Detect the host's architecture and return it as a string OPERATION=update
(i386/amd64/other values). ;;
esac
"""
# Check if the selected operation is correct, or if it is an alias for
return os.uname()[4].replace('x86_64', 'amd64').replace('i586', 'i386').replace('i686', 'i386') # another one.
case "$OPERATION" in
def item_ends_with(list, string): create|update|build|clean|login|execute)
""" item_ends_with(list, string) -> bool # Allright.
;;
Return True if one of the items in list ends with the given string,
or else return False. upgrade)
OPERATION=update
""" ;;
for item in list: *)
if item.endswith(string): if [ ${OPERATION##*.} = 'dsc' ]
return True then
OPERATION=build
return False else
echo "Unrecognized argument '$OPERATION'. Please use one of those:"
def ask(question): echo " create"
""" ask(question) -> string echo " update"
echo " build"
Ask the given question and return the answer. Also catch echo " clean"
KeyboardInterrupt (Ctrl+C) and EOFError (Ctrl+D) exceptions and echo " login"
immediately return None if one of those is found. echo " execute"
exit 1
""" fi
;;
try: esac
answer = raw_input(question)
except (KeyboardInterrupt, EOFError): # Determine the base name for the chroot tarball and the folder where the
print # resulting files will be stored.
answer = None FOLDERBASE="${DISTRIBUTION}-$ARCHITECTURE"
return answer # Create the folder where the resulting files will be placed (if the
# option is build), if it doesn't exist yet.
def help(exit_code = 0): if [ ! -d $BASE_DIR/${FOLDERBASE}_result ]
""" help() -> None then
mkdir -p $BASE_DIR/${FOLDERBASE}_result
Print a help message for pbuilder-dist, and exit with the given code. fi
""" # Determine wheter system cache should be used or not.
if [ $SYSCACHE = 1 ] && [ "$SYSDIST" = "$DISTRIBUTION" ] && [ "$REALARCH" = "$ARCHITECTURE" ]
print 'Bad...' then
DEBCACHE='/var/cache/apt/archives/'
sys.exit(exit_code) fi
def main(): # If it's an Ubuntu system, create an editable configuration file,
""" main() -> None # and if it's a stable release add the -security and -updates repositories.
if [ $ISDEBIAN = "False" ]
This is pbuilder-dist's main function. It creates a pbuilder_dist then
object, modifies all necessary settings taking data from the if [ ! -d $BASE_DIR/etc/$DISTRIBUTION/apt.conf/ ]
executable's name and command line options and finally either ends then
the script and runs pbuilder itself or exists with an error message. mkdir -p $BASE_DIR/etc/$DISTRIBUTION/apt.conf
fi
""" if [ ! -e $BASE_DIR/etc/$DISTRIBUTION/apt.conf/sources.list ]
then
script_name = os.path.basename(sys.argv[0]) echo "deb $ARCHIVE $DISTRIBUTION $COMPONENTS" > $BASE_DIR/etc/$DISTRIBUTION/apt.conf/sources.list
parts = script_name.split('-') case $DISTRIBUTION in
dapper|edgy|feisty|gutsy )
# Copy arguments into another list for save manipulation cat >> $BASE_DIR/etc/$DISTRIBUTION/apt.conf/sources.list <<EOF
args = sys.argv[1:] deb $ARCHIVE $DISTRIBUTION-security $COMPONENTS
deb $ARCHIVE $DISTRIBUTION-updates $COMPONENTS
if '-' in script_name and parts[0] != 'pbuilder' or len(parts) > 3: EOF
print 'Error: «%s» is not a valid name for a «pbuilder-dist» executable.' % script_name ;;
sys.exit(1) * )
;;
if len(args) < 1: esac
print 'Insufficient number of arguments.' fi
help(1) fi
if args[0] in ('-h', '--help', 'help'): #if [ -z "$PBUILDAUTH" ]
help(0) #then
# if [ -n "$DESKTOP_SESSION" ]
app = pbuilder_dist() # then
# case $DESKTOP_SESSION in
if len(parts) > 1: # gnome )
app.set_target_distro(parts[1]) # SUDOREPLACE="gksudo -D \"Pbuilder\""
else: # ;;
app.set_target_distro(args.pop(0)) # kde|kde4 )
# SUDOREPLACE="kdesudo -d --comment \"Pbuilder\""
if len(parts) > 2: # ;;
requested_arch = parts[2] # * )
elif args[0] in ('i386', 'amd64'): # SUDOREPLACE="sudo"
requested_arch = args.pop(0) # ;;
else: # esac
requested_arch = None # else
# SUDOREPLACE=sudo
if requested_arch: # fi
if requested_arch in ('i386', 'amd64') and app.system_architecture == 'amd64': #else
app.build_architecture = requested_arch # SUDOREPLACE=$PBUILDAUTH
else: #fi
print 'Error: Architecture switching is not supported on your system; wrong filename.'
sys.exit(1) sudo pbuilder $OPERATION \
--basetgz "$BASE_DIR/${FOLDERBASE}-base.tgz" \
if 'mainonly' in sys.argv: --distribution "$DISTRIBUTION" \
app.extra_components = False --debootstrapopts --arch \
args.remove('mainonly') --debootstrapopts "$ARCHITECTURE" \
$( [ "$SAVELOG" = 0 ] || echo "--logfile ${BASE_DIR}/.lastlog" ) \
if len(args) < 1: $( [ -z "$PROXY" ] || echo "--http-proxy ${PROXY}" ) \
print 'Insufficient number of arguments.' $( [ -z "$DEBCACHE" ] || echo "--aptcache ${DEBCACHE}" ) \
help(1) --buildresult "${BASE_DIR}/${FOLDERBASE}_result" \
--mirror "${ARCHIVE}" \
# Parse the operation $( [ $ISDEBIAN != "False" ] || echo "--aptconfdir ${BASE_DIR}/etc/${DISTRIBUTION}/apt.conf/" ) \
app.set_operation(args.pop(0)) $@
# Execute the pbuilder command
sys.exit(os.system(app.get_command(args)))
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print 'Manually aborted.'
sys.exit(1)

322
pbuilder-dist.new Executable file
View File

@ -0,0 +1,322 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007-2008 Siegfried-A. Gevatter <rainct@ubuntu.com>
# With some changes by Iain Lane <iain@orangesquash.org.uk>
# Based upon pbuilder-dist-simple by Jamin Collins and Jordan Mantha.
#
# License: GPLv2 or later
#
# This script is a wrapper to be able to easily use pbuilder for
# different distributions (eg, Gutsy, Hardy, Debian unstable, etc).
#
# You can create symlinks to a pbuilder-dist executable to get different
# configurations. For example, a symlink called pbuilder-hardy will assume
# that the target distribution is always meant to be Ubuntu Hardy.
import sys
import os
class pbuilder_dist:
def __init__(self):
# Base directory where pbuilder will put all the files it creates.
self.base = None
# Name of the operation which pbuilder should perform.
self.operation = None
# Wheter additional components should be used or not. That is,
# 'universe' and 'multiverse' for Ubuntu chroots and 'contrib'
# and 'non-free' for Debian.
self.extra_components = True
# File where the log of the last operation will be saved.
self.logfile = None
# System architecture
self.system_architecture = None
# Build architecture
self.build_architecture = None
# System's distribution
self.system_distro = None
# Target distribution
self.target_distro = None
# This is an identificative string which will either take the form
# 'distribution' or 'distribution-architecture'.
self.chroot_string = None
# Proxy
self.proxy = None
# Authentication method
self.auth = 'sudo'
##############################################################
if 'PBUILDFOLDER' in os.environ:
self.base = os.environ['PBUILDFOLDER']
else:
self.base = os.path.expanduser('~/pbuilder/')
if not os.path.exists(self.base):
os.makedirs(self.base)
if 'PBUILDAUTH' in os.environ:
self.auth = os.environ['PBUILDAUTH']
self.system_architecture = host_architecture()
if not self.system_architecture or 'not found' in self.system_architecture:
print 'Error: Not running on a Debian based system; could not detect its architecture.'
if not os.path.isfile('/etc/lsb-release'):
print 'Error: Not running on a Debian based system; could not find /etc/lsb-release.'
exit(1)
for line in open('/etc/lsb-release'):
line = line.strip()
if line.startswith('DISTRIB_CODENAME'):
self.system_distro = line[17:]
break
if not self.system_distro:
print 'Error: Could not determine what distribution you are running.'
exit(1)
self.target_distro = self.system_distro
if 'http_proxy' in os.environ:
self.base = os.environ['http_proxy']
elif 'HTTP_PROXY' in os.environ:
self.base = os.environ['HTTP_PROXY']
##############################################################
def __getitem__(self, name):
return getattr(self, name)
def _calculate(self):
""" pbuilder_dist.calculate(distro) -> None
Do all necessary variable changes (and therefore required checks)
before the string that will be executed is generated. At this
point it's expected that no more variables will be modified
outside this class.
"""
if not self.build_architecture:
self.chroot_string = self.target_distro
self.build_architecture = self.system_architecture
else:
self.chroot_string = '%(target_distro)s-%(build_architecture)s' % self
if not self.logfile:
self.logfile = '%(base)s.%(chroot_string)s.log' % self
def set_target_distro(self, distro):
""" pbuilder_dist.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
proceeding, and finally either save the value into the appropiate
variable or finalize pbuilder-dist's execution.
"""
if not distro.isalpha():
print 'Error: «%s» is an invalid distribution codename.' % distro
sys.exit(1)
if not os.path.isfile(os.path.join('/usr/share/debootstrap/scripts/', distro)):
answer = ask('Warning: Unknown distribution «%s». Do you want to continue [y/N]? ' % distro)
if answer not in ('y', 'Y'):
sys.exit(0)
self.target_distro = distro
def set_operation(self, operation):
""" pbuilder_dist.set_operation -> None
Check if the given string is a valid pbuilder operation and
depending on this either save it into the appropiate variable
or finalize pbuilder-dist's execution.
"""
arguments = ('create', 'update', 'build', 'clean', 'login', 'execute')
if operation not in arguments:
if item_ends_with(arguments, '.dsc'):
self.operation = 'build'
else:
print 'Error: «%s» is not a recognized argument.' % operation
print 'Please use one of those: ' + ', '.join(arguments) + '.'
sys.exit(1)
else:
self.operation = operation
def get_command(self, remaining_arguments = None):
""" pbuilder_dist.get_command -> string
Generate the pbuilder command which matches the given configuration
and return it as a string.
"""
# Calculate variables which depend on arguments given at runtime.
self._calculate()
arguments = [
self.operation,
'--basetgz "%(base)s%(chroot_string)s-base.tgz"' % self,
'--distribution "%(target_distro)s"' % self,
'--buildresult "%(base)s%(chroot_string)s_result/"' % self,
'--logfile "%(logfile)s"' % self,
'--aptcache "/var/cache/apt/archives/"',
### --mirror "${ARCHIVE}" \
]
if self.build_architecture != self.system_architecture:
arguments.append('--debootstrapopts --arch')
arguments.append('--debootstrapopts "%(build_architecture)s"' % self)
if self.proxy:
arguments.append('--http-proxy "%(proxy)s"' % self)
### $( [ $ISDEBIAN != "False" ] || echo "--aptconfdir \"${BASE_DIR}/etc/${DISTRIBUTION}/apt.conf/\"" ) \
# Append remaining arguments
if remaining_arguments:
arguments.extend(remaining_arguments)
return self.auth + ' /usr/sbin/pbuilder ' + ' '.join(arguments)
def host_architecture():
""" host_architecture -> string
Detect the host's architecture and return it as a string
(i386/amd64/other values).
"""
return os.uname()[4].replace('x86_64', 'amd64').replace('i586', 'i386').replace('i686', 'i386')
def item_ends_with(list, string):
""" item_ends_with(list, string) -> bool
Return True if one of the items in list ends with the given string,
or else return False.
"""
for item in list:
if item.endswith(string):
return True
return False
def ask(question):
""" ask(question) -> string
Ask the given question and return the answer. Also catch
KeyboardInterrupt (Ctrl+C) and EOFError (Ctrl+D) exceptions and
immediately return None if one of those is found.
"""
try:
answer = raw_input(question)
except (KeyboardInterrupt, EOFError):
print
answer = None
return answer
def help(exit_code = 0):
""" help() -> None
Print a help message for pbuilder-dist, and exit with the given code.
"""
print 'Bad...'
sys.exit(exit_code)
def main():
""" main() -> None
This is pbuilder-dist's main function. It creates a pbuilder_dist
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.
"""
script_name = os.path.basename(sys.argv[0])
parts = script_name.split('-')
# Copy arguments into another list for save manipulation
args = sys.argv[1:]
if '-' in script_name and parts[0] != 'pbuilder' or len(parts) > 3:
print 'Error: «%s» is not a valid name for a «pbuilder-dist» executable.' % script_name
sys.exit(1)
if len(args) < 1:
print 'Insufficient number of arguments.'
help(1)
if args[0] in ('-h', '--help', 'help'):
help(0)
app = pbuilder_dist()
if len(parts) > 1:
app.set_target_distro(parts[1])
else:
app.set_target_distro(args.pop(0))
if len(parts) > 2:
requested_arch = parts[2]
elif args[0] in ('i386', 'amd64'):
requested_arch = args.pop(0)
else:
requested_arch = None
if requested_arch:
if requested_arch in ('i386', 'amd64') and app.system_architecture == 'amd64':
app.build_architecture = requested_arch
else:
print 'Error: Architecture switching is not supported on your system; wrong filename.'
sys.exit(1)
if 'mainonly' in sys.argv:
app.extra_components = False
args.remove('mainonly')
if len(args) < 1:
print 'Insufficient number of arguments.'
help(1)
# Parse the operation
app.set_operation(args.pop(0))
# Execute the pbuilder command
sys.exit(os.system(app.get_command(args)))
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print 'Manually aborted.'
sys.exit(1)