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