0.54 upload.

* manage-credentials:
  - Save credentials to ~/.cache/lp_credentials/ by
    default.
  - Set service option default to edge.
* doc/manage-credentials.1: Update as necessary for the above.
* common.py:
  - When credentials are not found, ask user to see
    manage-credentials manpage.
  - Load all token files for the consumer specified in the above
    directory as necessary.
This commit is contained in:
Jonathan Davies 2009-01-14 19:49:18 +00:00
parent 2c0d695127
commit da7a71e54f
4 changed files with 48 additions and 17 deletions

View File

@ -290,18 +290,25 @@ def find_credentials(consumer, files, level=None):
continue
if cred.consumer.key == consumer:
return cred
raise IOError("No credentials found")
raise IOError("No credentials found, please see the manage-credentials " \
"manpage for help on how to create them.")
def get_credentials(consumer, cred_file=None, level=None):
files = list()
if cred_file:
files.append(cred_file)
if "LPCREDENTIALS" in os.environ:
files.append(os.environ["LPCREDENTIALS"])
files.extend([
os.path.join(os.getcwd(), ".lp_credentials.txt"),
os.path.expanduser("~/.lp_credentials.txt"),
])
files.append(os.path.join(os.getcwd(), "lp_credentials.txt"))
# Add all files which have our consumer name to file listing.
for x in glob.glob(os.path.expanduser("~/.cache/lp_credentials/%s*.txt" % \
consumer)):
files.append(x)
return find_credentials(consumer, files, level)
def get_launchpad(consumer, server=EDGE_SERVICE_ROOT, cache=None,
@ -376,10 +383,10 @@ def translate_service(service):
_service = service.lower()
if _service in (STAGING_SERVICE_ROOT, EDGE_SERVICE_ROOT):
return _service
elif _service == "staging":
return STAGING_SERVICE_ROOT
elif _service == "edge":
return EDGE_SERVICE_ROOT
elif _service == "staging":
return STAGING_SERVICE_ROOT
else:
raise ValueError("unknown service '%s'" %service)

15
debian/changelog vendored
View File

@ -1,3 +1,18 @@
ubuntu-dev-tools (0.54) jaunty; urgency=low
* manage-credentials:
- Save credentials to ~/.cache/lp_credentials/ by
default.
- Set service option default to edge.
* doc/manage-credentials.1: Update as necessary for the above.
* common.py:
- When credentials are not found, ask user to see
manage-credentials manpage.
- Load all token files for the consumer specified in the above
directory as necessary.
-- Jonathan Davies <jpds@ubuntu.com> Wed, 14 Jan 2009 19:39:35 +0000
ubuntu-dev-tools (0.53) jaunty; urgency=low
[ Siegfried-Angel Gevatter Pujals ]

View File

@ -37,7 +37,9 @@ If we should use the edge or staging root of the Launchpad API.
Where to store the cache.
.TP
.B \-o
Which file we should save the credentials to.
Which file we should save the credentials to. By default
\fBmanage-credentials\fR writes the credentials tokens to the
~/.cache/lp_credentials/ directory.
.TP
.B \-l \-\-level <number>
A number representing the access-level you wish to give to the new
@ -64,7 +66,7 @@ If you intend to use manage-credentials for Ubuntu development (such as
the ubuntu-dev-tools package). Please by sure to run the following:
.TP
manage-credentials create -c ubuntu-dev-tools -l 2 -o ~/.lp_credentials.txt
manage-credentials create -c ubuntu-dev-tools -l 2
.SH AUTHOR
.B manage-credentials

View File

@ -19,6 +19,7 @@
#
# ##################################################################
import os
import sys
from optparse import OptionParser, make_option
from common import Credentials, Launchpad, translate_service
@ -38,7 +39,7 @@ class CmdOptions(OptionParser):
make_option("-p", "--password", action="store", type="string",
dest="password", default=None),
make_option("-s", "--service", action="store", type="string",
dest="service", default="staging"),
dest="service", default="edge"),
make_option("--cache", action="store", type="string",
dest="cache", default=None),
make_option("-o", action="store", type="string",
@ -73,17 +74,17 @@ class CmdOptions(OptionParser):
self.error("Unknown tool '%s'" %tool)
needed_options = set(self.TOOLS[tool][0]) - given_options
if needed_options:
self.error("please define the following options: %s" %", ".join(needed_options))
self.error("Please define the following options: %s" %", ".join(needed_options))
optional_options = given_options - set(sum(self.TOOLS[tool], ()))
if optional_options:
self.error("the following options are not allowed for this tool: %s" %", ".join(optional_options))
self.error("The following options are not allowed for this tool: %s" %", ".join(optional_options))
options.service = translate_service(options.service)
if options.level in LEVEL:
options.level = LEVEL[options.level]
elif options.level.upper() in LEVEL.values():
options.level = options.level.upper()
else:
self.error("unknown access-level '%s', level must be in %s" %(options.level, self.LEVEL))
self.error("Unknown access-level '%s', level must be in %s" %(options.level, self.LEVEL))
return tool, options
def create_credentials(options):
@ -97,18 +98,25 @@ def create_credentials(options):
launchpad = Launchpad.get_token_and_login(options.consumer,
options.service, options.cache)
credentials = launchpad.credentials
if options.output:
f = file(options.output, "w")
else:
f = sys.stdout
if not os.path.isdir(os.path.expanduser("~/.cache/lp_credentials")):
os.mkdir(os.path.expanduser("~/.cache/lp_credentials/"))
filepath = os.path.expanduser("~/.cache/lp_credentials/%s-%s.txt" % \
(options.consumer, str(options.level).lower()))
f = file(filepath, "w")
credentials.save(f)
print "Credentials sucessfully written to %s." % filepath
return
def list_tokens(options):
print "Not implemented yet"
print "Not implemented yet."
print "To get a list of your tokens, please visit %speople/+me/+oauth-tokens" %translate_api_web(options.service)
return 1
def main():
cmdoptions = CmdOptions()
@ -118,6 +126,5 @@ def main():
elif tool == "list":
return list_tokens(options)
if __name__ == "__main__":
sys.exit(main())