From 86facf23c2b1b2a17ada08797b1c3bfc16762415 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Tue, 21 Dec 2010 22:42:29 +0200 Subject: [PATCH] Config file support for grab-attachments (almost doubling its size) :P --- doc/grab-attachments.1 | 35 +++++++++++++++++++++++++++++------ grab-attachments | 15 +++++++++++++-- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/doc/grab-attachments.1 b/doc/grab-attachments.1 index d66339e..97a71bc 100644 --- a/doc/grab-attachments.1 +++ b/doc/grab-attachments.1 @@ -2,7 +2,7 @@ .SH NAME grab\-attachments \- downloads attachments from a Launchpad bug .SH SYNOPSIS -.B grab\-attachments\fR <\fIbug-number\fR> +.B grab\-attachments\fR [\fIoptions\fR] \fIbug-number\fR... .br .B grab\-attachments \-h .SH DESCRIPTION @@ -12,13 +12,36 @@ Launchpad bug report into the current directory. .SH OPTIONS Listed below are the command line options for grab\-attachments: .TP -.B \-h -Display a help message and exit. -.TP -.B +.I bug-number Specifies the Launchpad bug number that the script should download attachments from. - +.TP +.BR \-h ", " \-\-help +Display a help message and exit. +.TP +.B \-l \fIINSTANCE\fR, \fB\-\-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. +.SH ENVIRONMENT +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 +The following variables can be set in the environment or in +.BR ubuntu\-dev\-tools (5) +configuration files. +In each case, the script\-specific variable takes precedence over the +package\-wide variable. +.TP +.BR GRAB_ATTACHMENTS_LPINSTANCE ", " UBUNTUTOOLS_LPINSTANCE +The default value for \fB--lpinstance\fR. +.SH SEE ALSO +.BR ubuntu\-dev\-tools (5) .SH AUTHOR \fBgrab\-attachments\fR was written by Daniel Holbach and this manual page was written by Jonathan Patrick Davies. diff --git a/grab-attachments b/grab-attachments index e4c2218..00f46fd 100755 --- a/grab-attachments +++ b/grab-attachments @@ -1,7 +1,8 @@ #!/usr/bin/python # # Copyright (C) 2007, Canonical Ltd. -# Written by Daniel Holbach +# Written by Daniel Holbach, +# Stefano Rivera # # ################################################################## # @@ -22,18 +23,28 @@ from optparse import OptionParser import os import sys +from ubuntutools.config import UDTConfig from ubuntutools.lp.libsupport import get_launchpad USAGE = "grab-attachments " def main(): p = OptionParser('Usage: %prog [options] ') + 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() if len(args) < 1: p.error('No bug numbers provided') + config = UDTConfig(opts.no_conf) + if opts.lpinstance is None: + opts.lpinstance = config.get_value('LPINSTANCE') try: - launchpad = get_launchpad("ubuntu-dev-tools") + launchpad = get_launchpad("ubuntu-dev-tools", server=opts.lpinstance) for arg in args: try: