Merge lp:~jelmer/lptools/command-option into lp:lptools

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 30
Merged at revision: 30
Proposed branch: lp:~jelmer/lptools/command-option
Merge into: lp:lptools
Diff against target: 56 lines (+15/-0)
2 files modified
bin/lp-shell (+10/-0)
doc/lp-shell.1 (+5/-0)
To merge this branch: bzr merge lp:~jelmer/lptools/command-option
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+76770@code.launchpad.net

Description of the change

Add a -c option to lp-shell.

Example:

Am I a Ubuntu developer ?
$ ./bin/lp-shell -c 'print lp.me in lp.people["ubuntu-dev"].participants'

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

> run the specified Python program

[query] I wonder if people would expect 'program' is a file containing a program. You could add an example or say eg 'code'.

review: Approve
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Thanks, merged with a tweak to the option description.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/lp-shell'
2--- bin/lp-shell 2011-09-01 17:44:46 +0000
3+++ bin/lp-shell 2011-09-23 16:11:18 +0000
4@@ -23,6 +23,9 @@
5 from launchpadlib.launchpad import Launchpad
6 from launchpadlib.uris import lookup_service_root
7
8+def run_command(command, lp):
9+ exec(command)
10+
11 def main():
12 instance = 'production'
13 valid_api_versions = ('beta', '1.0', 'devel')
14@@ -33,6 +36,9 @@
15 opt_parser.add_option('-a', action='store_true',
16 dest='anonymous', default=False,
17 help='Login anonymously into LP.')
18+ opt_parser.add_option('-c', type=str,
19+ dest='command', default=None,
20+ help='Program passed as string.')
21 opt_parser.add_option('--ipython', action='store_const',
22 dest='shell', const='ipython', default="ipython",
23 help='Use ipython shell (default).')
24@@ -68,6 +74,10 @@
25 banner = 'Connected to LP service "%s" with API version "%s":' % \
26 (instance, api_version)
27
28+ if options.command is not None:
29+ run_command(options.command, launchpad)
30+ return
31+
32 banner += '\nNote: LP can be accessed through the "lp" object.'
33
34 sh = None
35
36=== modified file 'doc/lp-shell.1'
37--- doc/lp-shell.1 2011-08-23 12:57:52 +0000
38+++ doc/lp-shell.1 2011-09-23 16:11:18 +0000
39@@ -5,6 +5,7 @@
40 .SH SYNOPSIS
41 .B lp\-shell
42 .RB [ \-a ]
43+.RB [ \-c PROGRAM ]
44 .RB [ \-\-python ]
45 .RB [ \-\-ipython ]
46 .RI [ service ]
47@@ -37,6 +38,10 @@
48 Login anonymously into Launchpad.
49
50 .TP
51+.B \-c PROGRAM
52+Don't enter a shell but only run the specified Python program and exit.
53+
54+.TP
55 .B \-\-ipython
56 Use an ipython shell if available (default).
57

Subscribers

People subscribed via source and target branches