~leonardr/launchpadlib/use-1.0

« back to all changes in this revision

Viewing changes to src/launchpadlib/bin/launchpad-request-token

  • Committer: Leonard Richardson
  • Date: 2009-10-27 16:29:16 UTC
  • mfrom: (66.1.4 json-token-format)
  • Revision ID: leonard.richardson@canonical.com-20091027162916-j2neti3rj7yuzza5
[r=bac] Added a command-line script for creating a request token.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
# Copyright 2009 Canonical Ltd.
 
4
 
 
5
# This file is part of launchpadlib.
 
6
#
 
7
# launchpadlib is free software: you can redistribute it and/or modify it
 
8
# under the terms of the GNU Lesser General Public License as published by the
 
9
# Free Software Foundation, version 3 of the License.
 
10
#
 
11
# launchpadlib is distributed in the hope that it will be useful, but WITHOUT
 
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 
14
# for more details.
 
15
#
 
16
# You should have received a copy of the GNU Lesser General Public License
 
17
# along with launchpadlib. If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
"""A script to retrieve a Launchpad request token.
 
20
 
 
21
This script will create a Launchpad request token and print to STDOUT
 
22
some JSON data about the token and the available access levels.
 
23
"""
 
24
 
 
25
__metaclass__ = type
 
26
 
 
27
from optparse import OptionParser
 
28
from launchpadlib.apps import RequestTokenApp
 
29
 
 
30
parser = OptionParser()
 
31
parser.usage = "%prog CONSUMER_NAME [-r SITE NAME] [-c CONTEXT]"
 
32
parser.add_option("-s", "--site", dest="web_root",
 
33
                  help=("The name of the Launchpad site to ask for a request "
 
34
                        "token (default: %default). This can also be the "
 
35
                        "URL to the root of the site."),
 
36
                  metavar="SITE", default="staging")
 
37
parser.add_option("-c", "--context", dest="context",
 
38
                  help="Restrict the token to a specific context "
 
39
                  "(example: firefox)", metavar="CONTEXT", default="")
 
40
 
 
41
if __name__ == '__main__':
 
42
    (options, args) = parser.parse_args()
 
43
    if len(args) < 1:
 
44
        parser.error("No consumer name supplied")
 
45
    consumer_name = args[0]
 
46
    app = RequestTokenApp(
 
47
        options.web_root, consumer_name, options.context)
 
48
    print app.run()