~ubuntu-branches/ubuntu/natty/quickly/natty

« back to all changes in this revision

Viewing changes to quickly/launchpadaccess.py

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-03-29 19:00:48 UTC
  • mfrom: (8.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100329190048-olhobq492x3xnztz
Tags: 0.3.90-0ubuntu1
* New release:
  Quickly core:
  - check now that --template has one argument
  - -- enables to give options to templates (unknown options and arguments
    are still given to templates but -- specify explicity what to give to
    templates commands like -h, --version...)
  - check and enable recreation of the credential if user deletes it on
    Launchpad
  - Use realpath so that we can symlink to the binary in trunk.
    (Jonathan Lange)
  - project_path_not_found is raised when data_path_not_found should be
    (originated from Philip Peitsch's patch). (LP: #497688)
  - importing command in one template from another template is now possible
    support as well "all" keyword to import all commands from a template
    into another one (take care of overridden commands too)
    (LP: #452306, #487301)
  - add an apport hook to get installed templates (LP: #411127)
  - enable option completion for templates
  - handle now version upgrade, launching script for templates and handling
    versionning on them
  - change getstarted wording (LP: #486180) - Grant
  - Quickly ship now "version" tag instead of "format" tag
  - add some templatetools to check X display
  - if a commands exit with 4, do not show "ERROR:" (case of wrong command
    usage, for instance)
  - Rewrote importing module in both bin/quickly and ubuntu-project binary
  - Add get_camel_case_name() and get_sentence_name() to templatetools
  - Refactor some code in pre_create hook()
  - Now dashes and spaces support in project name! Dealing with python and
    packaging issues for you. (LP: #493130)
  - Provide Quickly API (LP: #426480)
  - Fix some issues in the man page
  ubuntu-application Template:
  - Enabling upload to team or user ppa, as well as any ppa.
    Use --ppa ppaname or --ppa team/ppaname
    .quickly file can be used as well with ppa = ppaname or
    ppa = team/ppaname (LP: #470192)
    ppa completion is also available
  - Change BSD header by full license
  - Add MIT license
  - Fixes an error when launchpad display name contains unicode character
    (Petar Vasić)
  - Fix typo in quickly help save (Petar Vasić)
  - Adds logo.png as logo property in about dialog (LP: #478389)
    (Petar Vasić)
  - Remove lp-project-change command and add configure command.
    configure lp-project [project_name] to set/reset lp project binded to
    your Quickly project
    ppa <ppa name> to set a default ppa with your project
  - Fix ~/.selected-editor being ignored (LP: #484730)
  - Fix wrong shell completion when in a template (it wrongly proposed
    all commands followed by templates)
  - Check if we have a X display available before running "run" or launching
    GUI in "create" command.
  - add -- support in quickly run to pass options like --help, --version so
    that Quickly core don't take them.
  - enable preferences save call being called multiple times (Philip Peitsch)
  - Use realpath so that we can symlink to the binary in trunk.
  - Fixed some errors in the tutorial (Brian) (LP: #499356)
  - Fix missing import sys in setup.py (Philip Peitsch) (LP: #499712)
  - rename ubuntu-project to ubuntu-application
  - enhance quickly license (no more Copyright file, only one AUTHORS file)
    personal license needs COPYING file now (and the header will be copied in
    every files). No more # needed in those files too. Some other little
    refactoring too (LP: #469330)
  - autolicence by default on first share/release (with LP info and on GPL-3)
  - change versionning support in ubuntu application: (LP: #476814)
   + quickly share just adds -publicX to current version where X is bumped
     at each "quicky share" execution
   + quickly release remove -publicX (if any) and release with current YY.MM.
     If there is already a release with that version, it will be YY.MM.1, 
     then YY.MM.2
  - add accelerators to menu items (jens persson)
  - set correctly title dialog (Philip Peitsch) (LP: #501999)
  - about dialog box is now fully automated: (LP: #478414)
   + update copyright, authors, license (when licensing)
   + version (when sharing and releasing)
   + homepage (when changing launchpad project: release and configure)
  - add an 'add' command. $ quickly dialog … is now $ quickly add dialog …
    (LP: #438320)
  - enable automatic release and milestone built in LP, releasing and pushing
    upstream tarball (LP: #470344)
  - automatic collect and publish changelog message from commits and save
    messages used during devlopment. (LP: #476572)
  - add i18n to boiler plate (LP: #423529)
  - enable adding manual depdencies to quickly project (LP: #474639)
  - enable configure its own bzr branch and resetting parent branch even once
    already configured (quickly configure bzr <branch-path>)
  - now recommends seahorse-plugins to have a graphical prompt for signing
    package
  - rename quickly glade to quickly design (LP: #528664)
  - create command is now more flexible and enable people to inherit from
    other template more easily
  - add translation domain to gtkbuilder and fix some items that shouldn't
    been translatable (Łukasz Jernaś)
  - add apport and launchpadintegration to new and existing project once
    bounded to LP (Philip Peitsch)
  - fix spelling mistake "connexion" (Łukasz Jernaś) (LP: #532667)
  - the ubuntu-application tutorial is now internationalized and use docbook
    format. Translators, it's yours! (Shane Fagan) (LP: #525168)
  - package/share/release are now more quiet and only print something on error
    warning as a summary as with unfound packages, and so on (LP: #482915)
  - new algorithm to select good email automatically. Try to get the preferred
    email and update the AUTHOR file with it.
  - test GPG key and create one automatically if none is available. The
    corresponding public key availabity in launchpad is also checked.
    (LP: #427730, #408993)
  - add devscripts as a dependency (bug #465833), will fix all the depends
    mess later
  - bump python-distutils-extra (>= 2.18bzr1)
  ubuntu-cli Template:
  - first release using import command feature (no command written into the
    template itself). This is a basic ubuntu CLI application
  ubuntu-pygame Template:
  - first release using import command feature. python-pygame added as a
    depends
* debian/control:
  - renamed and separate in multiple packages to get a -common used with
    Quickly widgets (LP: #519633)
  - suggests python-quickly-widgets

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
 
# Copyright 2009 Canonical Ltd.
3
 
# Author 2009 Didier Roche
 
2
# Copyright 2009 Didier Roche
4
3
#
5
4
# This file is part of Quickly
6
5
#
25
24
LAUNCHPAD_STAGING_URL = "https://staging.launchpad.net"
26
25
LAUNCHPAD_CODE_STAGING_URL = "https://code.staging.launchpad.net"
27
26
 
28
 
 
29
 
def die(message):
30
 
    print >> sys.stderr, _("Fatal: ") + message
31
 
    sys.exit(1)
 
27
# TODO: see how to export this error on import launchpadaccess (in init.py ?)
 
28
class launchpad_connection_error(Exception):
 
29
    pass
 
30
class launchpad_project_error(Exception):
 
31
    pass
32
32
 
33
33
try:
34
34
    from launchpadlib.launchpad import Launchpad, EDGE_SERVICE_ROOT, STAGING_SERVICE_ROOT
35
35
    from launchpadlib.errors import HTTPError
36
36
    from launchpadlib.credentials import Credentials
 
37
    import httplib2
37
38
except ImportError:
38
 
    die(_("Check whether python-launchpadlib is installed"))
 
39
    print(_("Check whether python-launchpadlib is installed"))
 
40
    sys.exit(1)
39
41
 
40
42
 
41
43
from quickly import bzrbinding
45
47
from gettext import gettext as _
46
48
 
47
49
 
48
 
# if config not already loaded
49
 
if not configurationhandler.project_config:
50
 
    configurationhandler.loadConfig()
51
 
 
52
50
# check if there is no global variable specifying staging
53
 
if os.getenv('QUICKLY') is not None and "staging" in os.getenv('QUICKLY').lower():
 
51
if os.getenv('QUICKLY') and "staging" in os.getenv('QUICKLY').lower():
54
52
    launchpad_url = LAUNCHPAD_STAGING_URL
55
53
    lp_server = "staging"
56
54
else:
59
57
 
60
58
 
61
59
 
62
 
def initialize_lpi():
 
60
def initialize_lpi(interactive = True):
63
61
    ''' Initialize launchpad binding, asking for crendential
64
62
 
65
 
            :return the launchpad object
 
63
        interactive is True by default if we want to ask the user to setup LP
 
64
        :return the launchpad object
66
65
    '''
67
66
 
 
67
    # if config not already loaded
 
68
    if not configurationhandler.project_config:
 
69
        configurationhandler.loadConfig()
 
70
 
68
71
    launchpad = None
69
72
    return_code = 0
70
73
 
89
92
 
90
93
    # load stored LP credentials
91
94
    try:
92
 
        print _("Get Launchpad Settings")
 
95
        if interactive:
 
96
            print _("Get Launchpad Settings")
 
97
        lp_cred_file = None
93
98
        lp_cred_file = open(lp_cred, 'r')
94
99
        credentials = Credentials()
95
100
        credentials.load(lp_cred_file)
96
101
        lp_cred_file.close()
97
 
        launchpad = Launchpad(credentials, SERVICE_ROOT, lp_cache_dir)
98
 
    except IOError:
99
 
        print _('Initial Launchpad binding. You must choose "Change Anything"')
100
 
        launchpad = Launchpad.get_token_and_login('quickly', SERVICE_ROOT, lp_cache_dir)
101
 
        lp_cred_file = open(lp_cred, 'w')
102
 
        launchpad.credentials.save(lp_cred_file)
103
 
        lp_cred_file.close()
104
 
 
105
 
        # try to setup bzr
106
 
        me = launchpad.me
107
 
        (return_code, suggestion) = bzrbinding.bzr_set_login(me.display_name, me.preferred_email_address.email, me.name)
108
 
 
109
 
    if launchpad is None or return_code != 0:
110
 
        if suggestion is None:
111
 
             suggestion = _("Unknown reason")
112
 
        os.remove(lp_cred)
113
 
        die(_("Couldn't setup Launchpad for quickly ; %s") % suggestion)
114
 
    print _("Launchpad connexion is ok")
 
102
        try:
 
103
            launchpad = Launchpad(credentials, SERVICE_ROOT, lp_cache_dir)
 
104
        except httplib2.ServerNotFoundError, e:
 
105
            raise launchpad_connection_error(e)
 
106
    except (IOError, HTTPError):
 
107
        if interactive:
 
108
            # case where autorization on Launchpad was removed
 
109
            if lp_cred_file:
 
110
                os.remove(lp_cred_file.name)
 
111
                print _('Previous Launchpad values seems to have been removed. You must choose again "Change Anything"')
 
112
            else:
 
113
                print _('Initial Launchpad binding. You must choose "Change Anything"')
 
114
            launchpad = Launchpad.get_token_and_login('quickly', SERVICE_ROOT, lp_cache_dir)
 
115
            lp_cred_file = open(lp_cred, 'w')
 
116
            launchpad.credentials.save(lp_cred_file)
 
117
            lp_cred_file.close()
 
118
 
 
119
            # try to setup bzr
 
120
            me = launchpad.me
 
121
            (return_code, suggestion) = bzrbinding.bzr_set_login(me.display_name, me.preferred_email_address.email, me.name)
 
122
 
 
123
    if interactive:
 
124
        if launchpad is None or return_code != 0:
 
125
            if suggestion is None:
 
126
                 suggestion = _("Unknown reason")
 
127
            os.remove(lp_cred)
 
128
            raise launchpad_connection_error(_("Couldn't setup Launchpad for quickly ; %s") % suggestion)
 
129
        print _("Launchpad connection is ok")
115
130
 
116
131
    return launchpad
117
132
 
118
133
 
119
 
def link_project(launchpad, question):
 
134
def link_project(launchpad, question, lp_project_name=None):
120
135
    ''' Link to launchpad project, erasing previous one if already set
121
136
    
122
137
    
123
138
        :return project object'''
124
139
 
125
 
    choice = "0"
126
 
    while choice == "0":    
127
 
        
128
 
        lp_id = raw_input("%s, leave blank to abort.\nLaunchpad project name: " % question)
129
 
        if lp_id == "":
130
 
            print _("No launchpad project give, aborting.")
131
 
            exit(1)
132
 
            
133
 
        prospective_projects = launchpad.projects.search(text=lp_id)
134
 
        project_number = 1
135
 
        project_names = []
136
 
        for project in prospective_projects:
137
 
            print ("---------------- [%s] ----------------") % project_number
138
 
            print "  " + project.title
139
 
            print ("--------------------------------------")
140
 
            print _("Project name: %s") % project.display_name
141
 
            print _("Launchpad url: %s/%s") % (launchpad_url, project.name)
142
 
            project_names.append(project.name)
143
 
            print project.summary
144
 
            project_number += 1            
145
 
        print
146
 
 
147
 
        if not list(prospective_projects):
148
 
            message = _("No project found")
149
 
        else:
150
 
            message = _("Choose your project number")
151
 
        choice = raw_input("%s, leave blank to abort, 0 for another search.\nYour choice: " % message)
152
 
 
153
 
    try:
154
 
        choice = int(choice)
155
 
        if choice in range(1, project_number):
156
 
            project = launchpad.projects[project_names[choice - 1]]
157
 
        else:
158
 
            raise ValueError
159
 
    except ValueError:
160
 
        print _("No right number given, aborting.")
161
 
        exit(1)
 
140
    # if config not already loaded
 
141
    if not configurationhandler.project_config:
 
142
        configurationhandler.loadConfig()
 
143
 
 
144
    if not lp_project_name:
 
145
        choice = "0"
 
146
        while choice == "0":
 
147
 
 
148
            lp_id = raw_input("%s, leave blank to abort.\nLaunchpad project name: " % question)
 
149
            if lp_id == "":
 
150
                raise launchpad_project_error(_("No launchpad project given, aborting."))
 
151
                
 
152
            prospective_projects = launchpad.projects.search(text=lp_id)
 
153
            project_number = 1
 
154
            project_names = []
 
155
            for project in prospective_projects:
 
156
                print (_('''---------------- [%s] ----------------
 
157
   %s
 
158
--------------------------------------
 
159
Project name: %s
 
160
Launchpad url: %s/%s
 
161
%s
 
162
''') % (project_number, project.title, project.display_name, launchpad_url, project.name, project.summary))
 
163
                project_names.append(project.name)
 
164
                project_number += 1            
 
165
 
 
166
            if not list(prospective_projects):
 
167
                message = _("No project found")
 
168
            else:
 
169
                message = _("Choose your project number")
 
170
            choice = raw_input("%s, leave blank to abort, 0 for another search.\nYour choice: " % message)
 
171
 
 
172
        try:
 
173
            choice = int(choice)
 
174
            if choice in range(1, project_number):
 
175
                project = launchpad.projects[project_names[choice - 1]]
 
176
            else:
 
177
                raise ValueError
 
178
        except ValueError:
 
179
            raise launchpad_project_error(_("No right number given, aborting."))
 
180
 
 
181
    # we got a project name, check that it exists
 
182
    else:
 
183
        try:
 
184
            project = launchpad.projects[lp_project_name]
 
185
        except KeyError:
 
186
            raise launchpad_project_error(_("Can't find %s project on Launchpad. You can try to find it interactively without providing a project name.") % lp_project_name)       
 
187
 
162
188
    configurationhandler.project_config['lp_id'] = project.name
163
189
    configurationhandler.saveConfig()
164
190
    
169
195
    
170
196
        :return project object
171
197
    '''
172
 
        
 
198
 
 
199
    # if config not already loaded
 
200
    if not configurationhandler.project_config:
 
201
        configurationhandler.loadConfig()
 
202
       
173
203
    # try to get project
174
204
    try:
175
205
        lp_id = configurationhandler.project_config['lp_id']
176
206
        project = launchpad.projects[lp_id]
177
207
       
178
208
    # else, bind the project to LP
179
 
    except KeyError:        
 
209
    except KeyError:
180
210
        project = link_project(launchpad, "No Launchpad project set")
181
211
        
182
212
    return project