~rachidbm/ubuntu-l10n-tools/search

« back to all changes in this revision

Viewing changes to ul10n_tools/launchpadmanager.py

  • Committer: David Planella
  • Date: 2011-05-23 14:48:55 UTC
  • Revision ID: david.planella@ubuntu.com-20110523144855-5gj1udh7xmstbwvr
Implemented searching in plurals too. The output of the script is also a bit nicer. Moved the search functions to a class in a separate module

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
 
### BEGIN LICENSE
3
 
# This file is in the public domain
4
 
### END LICENSE
5
 
 
6
 
import shutil
7
 
import atexit
8
 
import tempfile
9
 
import logging
10
 
try:
11
 
    from launchpadlib.launchpad import Launchpad
12
 
except ImportError:
13
 
    print >> sys.stderr, "In order to use the Launchpad API you'll need to \
14
 
    install https://help.launchpad.net/API/launchpadlib"
15
 
 
16
 
 
17
 
def no_credential():
18
 
    print >> sys.stderr, "Can't proceed without a Launchpad credential."
19
 
    sys.exit(1)
20
 
 
21
 
 
22
 
def get_launchpad(use_staging = False):
23
 
    cachedir = tempfile.mkdtemp()
24
 
    atexit.register(shutil.rmtree, cachedir)
25
 
    logging.info('Logging in to Launchpad...')
26
 
    server = (lambda s: 'staging' if s else 'production')(use_staging)
27
 
    launchpad = Launchpad.login_with('ul10n_tools',
28
 
                                     server,
29
 
                                     cachedir,
30
 
                                     credential_save_failed=no_credential)
31
 
 
32
 
    return launchpad
33