~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to plugins/launchpad_prompt.py

  • Committer: Zygmunt Krynicki
  • Date: 2013-05-17 13:54:25 UTC
  • mto: This revision was merged to the branch mainline in revision 2130.
  • Revision ID: zygmunt.krynicki@canonical.com-20130517135425-cxcenxx5t0qrtbxd
checkbox-ng: add CheckBoxNG sub-project

CheckBoxNG (or lowercase as checkbox-ng, pypi:checkbox-ng) is a clean
implementation of CheckBox on top of PlainBox. It provides a new
executable, 'checkbox' that has some of the same commands that were
previously implemented in the plainbox package.

In particular CheckBoxNG comes with the 'checkbox sru' command
(the same one as in plainbox). Later on this sub-command will be removed
from plainbox.

CheckBoxNG depends on plainbox >= 0.3

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# This file is part of Checkbox.
 
3
#
 
4
# Copyright 2008 Canonical Ltd.
 
5
#
 
6
# Checkbox is free software: you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation, either version 3 of the License, or
 
9
# (at your option) any later version.
 
10
#
 
11
# Checkbox is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
 
18
#
 
19
import re
 
20
import posixpath
 
21
 
 
22
from gettext import gettext as _
 
23
 
 
24
from checkbox.plugin import Plugin
 
25
from checkbox.properties import String
 
26
from checkbox.user_interface import PREV
 
27
 
 
28
 
 
29
class LaunchpadPrompt(Plugin):
 
30
 
 
31
    # Email address used to sign in to Launchpad.
 
32
    email = String(required=False)
 
33
 
 
34
    # Default email address used for anonymous submissions.
 
35
    default_email = String(default="ubuntu-friendly-squad@lists.launchpad.net")
 
36
 
 
37
    def register(self, manager):
 
38
        super(LaunchpadPrompt, self).register(manager)
 
39
 
 
40
        self.persist = None
 
41
 
 
42
        for (rt, rh) in [
 
43
             ("begin-persist", self.begin_persist),
 
44
             ("launchpad-report", self.launchpad_report),
 
45
             ("prompt-exchange", self.prompt_exchange)]:
 
46
            self._manager.reactor.call_on(rt, rh)
 
47
 
 
48
    def begin_persist(self, persist):
 
49
        self.persist = persist.root_at("launchpad_prompt")
 
50
 
 
51
    def launchpad_report(self, report):
 
52
        self.report = report
 
53
 
 
54
    def prompt_exchange(self, interface):
 
55
        if self.persist and self.persist.has("email"):
 
56
            email = self.persist.get("email")
 
57
        else:
 
58
            email = self.email
 
59
 
 
60
        # Register temporary handler for exchange-error events
 
61
        errors = []
 
62
 
 
63
        def exchange_error(e):
 
64
            errors.append(e)
 
65
 
 
66
        event_id = self._manager.reactor.call_on("exchange-error",
 
67
                                                 exchange_error)
 
68
 
 
69
        while True:
 
70
            if errors or not self.email:
 
71
                for error in errors:
 
72
                    self._manager.reactor.fire("prompt-error",
 
73
                                               interface, error)
 
74
 
 
75
                url = "file://%s" % posixpath.abspath(self.report)
 
76
 
 
77
                # Ignore whether to submit to HEXR
 
78
                email = interface.show_entry(_("""\
 
79
The following report has been generated for submission to the Launchpad \
 
80
hardware database:
 
81
 
 
82
  [[%s|View Report]]
 
83
 
 
84
You can submit this information about your system by providing the email \
 
85
address you use to sign in to Launchpad. If you do not have a Launchpad \
 
86
account, please register here:
 
87
 
 
88
  https://launchpad.net/+login""") % url, email, label=_("Email") + ":")[0]
 
89
 
 
90
            if interface.direction == PREV:
 
91
                break
 
92
 
 
93
            if not email:
 
94
                email = self.default_email
 
95
 
 
96
            if not re.match(r"^\S+@\S+\.\S+$", email, re.I):
 
97
                errors.append(_("Email address must be in a proper format."))
 
98
                continue
 
99
 
 
100
            errors = []
 
101
            self._manager.reactor.fire("launchpad-email", email)
 
102
            interface.show_progress(
 
103
                _("Exchanging information with the server..."),
 
104
                self._manager.reactor.fire, "launchpad-exchange", interface)
 
105
            if not errors:
 
106
                break
 
107
 
 
108
        self._manager.reactor.cancel_call(event_id)
 
109
        if self.persist:
 
110
            self.persist.set("email", email)
 
111
 
 
112
 
 
113
factory = LaunchpadPrompt