~ubuntu-branches/ubuntu/vivid/mago/vivid

« back to all changes in this revision

Viewing changes to mago/application/seahorse.py

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2011-02-08 13:32:13 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110208133213-m1og7ey0m990chg6
Tags: 0.3+bzr20-0ubuntu1
* debian/rules:
  - updated to debhelper 7
  - use dh_python2 instead of python-central
* debian/pycompat:
  - removed, no longer needed
* debian/control:
  - dropped cdbs and python-central dependencies
* bzr snapshot of the current trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
 
3
 
PACKAGE = "mago"
4
 
 
5
 
"""
6
 
This is the "Seahorse" module.
7
 
 
8
 
This module provides a wrapper for LDTP to make the writing of Seahorse tests
9
 
easier.
10
 
"""
11
 
import ooldtp
12
 
import ldtp
13
 
from .main import Application
14
 
from ..gconfwrapper import GConf
15
 
import time
16
 
from ..cmd import globals
17
 
import gettext
18
 
 
19
 
gettext.install (True)
20
 
gettext.bindtextdomain (PACKAGE, globals.LOCALE_SHARE)
21
 
gettext.textdomain (PACKAGE)
22
 
t = gettext.translation(PACKAGE, globals.LOCALE_SHARE, fallback = True)
23
 
_ = t.gettext
24
 
 
25
 
class Seahorse(Application):
26
 
    """
27
 
    Seahorse manages the Seahorse application.
28
 
    """
29
 
    WINDOW       = _("frmPasswordsandEncryptionKeys")
30
 
    LAUNCHER     = "seahorse"
31
 
    MNU_NEWKEY   = _("mnuNew")
32
 
    NEWKEY_DLG   = _("Create New*")
33
 
    BTN_CONTINUE = _("btnContinue")
34
 
    TYPE_PGP            = _("PGP Key")
35
 
    NEWPGP_DLG          = _("dlgNewPGPKey")
36
 
    DLG_NEWPGP_FULLNAME = _("txtFullName")
37
 
    DLG_NEWPGP_EMAIL    = _("txtEmailAddress")
38
 
    DLG_NEWPGP_COMMENT  = _("txtComment")
39
 
    BTN_NEWPGP_CREATE   = _("btnCreate")
40
 
    DLG_NEWKEY_PASS     = _("dlgPassphrasefor*")
41
 
    BTN_PASS_OK         = _("btnOK")
42
 
    DLG_GENERATING_KEY  = _("dlgGeneratingkey")
43
 
    DLG_CREATING_SSH    = _("dlgCreatingSecureShellKey")
44
 
    TYPE_SSH            = _("Secure Shell Key")
45
 
    NEWSSH_DLG          = _("New Secure Shell Key") 
46
 
    DLG_NEWSSH_DESC     = _("txtKeyDescription")
47
 
    BTN_NEWSSH_CREATE_AND_SETUP = _("Create and Set Up")
48
 
    DLG_SET_UP          = _("Set Up Computer for SSH Connection")
49
 
    TXT_SET_UP_COMPUTER = _("txtThehostnameoraddressoftheserver.")
50
 
    TXT_SET_UP_LOGIN    = _("txtLoginName")
51
 
    BTN_SET_UP          = _("btnSetUp")
52
 
    BTN_NEWSSH_CREATE   = _("Just Create Key")
53
 
    TAB_PERSONAL_KEYS   = _("My Personal Keys")
54
 
    TAB_LIST            = "ptl0"
55
 
    TBL_PERSONAL_KEYS   = "ttbl1"
56
 
    LBL_DELETE_KEY_Q   = _("lblOneormoreofthedeletedkeysareprivatekeys.Areyousureyouwanttoproceed?")
57
 
 
58
 
    def __init__(self):
59
 
        Application.__init__(self)
60
 
        self.generated_keys = []
61
 
 
62
 
    def new_key(self, key_type):
63
 
        """
64
 
        It opens up the list of available new keys, and select the one to create.
65
 
        
66
 
        @type key_type: string
67
 
        @param key_type: The type of key to create. 
68
 
        """
69
 
        
70
 
        seahorse = ooldtp.context(self.name)
71
 
        
72
 
        mnu_new_key = seahorse.getchild(self.MNU_NEWKEY)
73
 
        mnu_new_key.selectmenuitem() 
74
 
 
75
 
        ldtp.waittillguiexist(self.NEWKEY_DLG)
76
 
        dlg_new_key = ooldtp.context(self.NEWKEY_DLG)
77
 
 
78
 
        table  = dlg_new_key.getchild(role = 'table')
79
 
        types_table = table[0]
80
 
 
81
 
        for i in range(0, types_table.getrowcount(), 1):
82
 
            text = types_table.getcellvalue(i, 1)
83
 
            candidate = text.split('\n')[0]
84
 
            if candidate == key_type:
85
 
                types_table.selectrowindex(i)
86
 
                break
87
 
            ldtp.wait(1)
88
 
 
89
 
        btn_continue = dlg_new_key.getchild(self.BTN_CONTINUE)
90
 
 
91
 
        btn_continue.click() 
92
 
        
93
 
    def new_pgp_key(self, full_name, email, comment, passphrase):
94
 
        """
95
 
        It creates a new PGP key with the default settings.
96
 
 
97
 
        TODO: Allow advanced options
98
 
        TODO: Check the list afterwards for the newly created key
99
 
 
100
 
        @type full_name: string 
101
 
        @param full_name: Full name to type for the PGP key
102
 
 
103
 
        @type email: string 
104
 
        @param email: Email to type for the PGP key
105
 
 
106
 
        @type comment: string 
107
 
        @param comment: Comment to type for the PGP key
108
 
 
109
 
        @type passphrase: string 
110
 
        @param passphrase: Passphrase to type for the PGP key
111
 
        """
112
 
        
113
 
        self.new_key(self.TYPE_PGP)
114
 
 
115
 
        ldtp.waittillguiexist(self.NEWPGP_DLG)
116
 
        dlg_new_pgp = ooldtp.context(self.NEWPGP_DLG)
117
 
 
118
 
        txt_field = dlg_new_pgp.getchild(self.DLG_NEWPGP_FULLNAME)
119
 
        txt_field.settextvalue(full_name)
120
 
 
121
 
        txt_field = dlg_new_pgp.getchild(self.DLG_NEWPGP_EMAIL)
122
 
        txt_field.settextvalue(email)
123
 
   
124
 
        txt_field = dlg_new_pgp.getchild(self.DLG_NEWPGP_COMMENT)
125
 
        txt_field.settextvalue(comment)
126
 
 
127
 
        btn_create = dlg_new_pgp.getchild(self.BTN_NEWPGP_CREATE)
128
 
        btn_create.click() 
129
 
       
130
 
        ldtp.waittillguiexist(self.DLG_NEWKEY_PASS)
131
 
        dlg_new_pgp_pass = ooldtp.context(self.DLG_NEWKEY_PASS)
132
 
 
133
 
        # Entering the passphrase
134
 
        ldtp.enterstring(passphrase)
135
 
        ldtp.enterstring("<tab>")
136
 
        ldtp.enterstring(passphrase)
137
 
 
138
 
        btn_pass_ok = dlg_new_pgp_pass.getchild(self.BTN_PASS_OK)
139
 
 
140
 
        btn_pass_ok.click() 
141
 
 
142
 
        ldtp.waittillguiexist(self.DLG_GENERATING_KEY)
143
 
        while ldtp.guiexist(self.DLG_GENERATING_KEY) == 1:
144
 
            ldtp.wait(1)
145
 
 
146
 
        # Add key name to generated key list, so we know to delete it later.
147
 
        self.generated_keys.append('  '.join([full_name, email, "'"+comment+"'"]))
148
 
 
149
 
    def new_ssh_key(self, description, passphrase, set_up = False, computer = '', login = ''):
150
 
        """
151
 
        It creates a new SSH key with the default settings.
152
 
 
153
 
        TODO: Setting up the key is not working yet
154
 
 
155
 
        @type description: string 
156
 
        @param description: Description to type in the SSH key
157
 
 
158
 
        @type passphrase: string 
159
 
        @param passphrase: Passphrase to type for the SSH key
160
 
 
161
 
        @type set_up: boolean 
162
 
        @param passphrase: True, to set up the SSH key
163
 
 
164
 
        @type computer: string 
165
 
        @param computer: URL or IP of the computer to set up the key
166
 
        
167
 
        @type login: string
168
 
        @param login: Login to use in the remote computer
169
 
        """
170
 
        
171
 
        self.new_key(self.TYPE_SSH)
172
 
 
173
 
        ldtp.waittillguiexist(self.NEWSSH_DLG)
174
 
        dlg_new_ssh = ooldtp.context(self.NEWSSH_DLG)
175
 
 
176
 
        txt_field = dlg_new_ssh.getchild(self.DLG_NEWSSH_DESC)
177
 
        txt_field.settextvalue(description)
178
 
 
179
 
        if set_up == True:
180
 
            btn_create = dlg_new_ssh.getchild(self.BTN_NEWSSH_CREATE_AND_SETUP)
181
 
        else:
182
 
            btn_create = dlg_new_ssh.getchild(self.BTN_NEWSSH_CREATE)
183
 
 
184
 
        btn_create.click() 
185
 
      
186
 
 
187
 
        ldtp.waittillguiexist(self.DLG_NEWKEY_PASS)
188
 
        dlg_new_key_pass = ooldtp.context(self.DLG_NEWKEY_PASS)
189
 
 
190
 
        # Entering the passphrase
191
 
        ldtp.enterstring(passphrase)
192
 
        ldtp.enterstring("<tab>")
193
 
        ldtp.enterstring(passphrase)
194
 
 
195
 
        btn_pass_ok = dlg_new_key_pass.getchild(self.BTN_PASS_OK)
196
 
        btn_pass_ok.click() 
197
 
 
198
 
        if set_up == True and login is not None:
199
 
 
200
 
            ldtp.waittillguiexist(self.DLG_SET_UP)
201
 
            dlg_set_up_computer = ooldtp.context(self.DLG_SET_UP)
202
 
 
203
 
            txt_field = dlg_set_up_computer.getchild(self.TXT_SET_UP_LOGIN)
204
 
            txt_field.settextvalue(login)
205
 
 
206
 
        if set_up == True:
207
 
            txt_field = dlg_set_up_computer.getchild(self.TXT_SET_UP_COMPUTER)
208
 
            txt_field.settextvalue(computer)
209
 
 
210
 
            btn_set_up = dlg_set_up_computer.getchild(self.BTN_SET_UP)
211
 
            btn_set_up.click() 
212
 
            
213
 
        while ldtp.guiexist(self.DLG_CREATING_SSH) == 1:
214
 
            ldtp.wait(1)
215
 
            
216
 
        # Add key name to generated key list, so we know to delete it later.
217
 
        self.generated_keys.append(description)
218
 
 
219
 
        # It is too fast to grab the main window afterwards
220
 
        ldtp.wait(3)
221
 
 
222
 
    def go_to_tab(self, tab_name):
223
 
        """
224
 
        Go to the specified tab.
225
 
        """
226
 
        seahorse = ooldtp.context(self.name)
227
 
        page_list = seahorse.getchild(self.TAB_LIST)
228
 
        page_list.selecttab(self.TAB_PERSONAL_KEYS)
229
 
        
230
 
 
231
 
    def assert_exists_key(self, name, tab_name = None):
232
 
        """
233
 
        It checks that the KEY with description 'description' is
234
 
        part of the keys of the current user
235
 
 
236
 
        @type name: string
237
 
        @param name: The name of the key to search
238
 
        
239
 
        @type tab_name: string
240
 
        @param tab_name: The tab name to search for the key.
241
 
        """
242
 
        if not tab_name:
243
 
            tab_name = self.TAB_PERSONAL_KEYS
244
 
 
245
 
        self.go_to_tab(tab_name)
246
 
        seahorse = ooldtp.context(self.name)
247
 
 
248
 
        selected_tab = seahorse.getchild(tab_name)
249
 
        table = selected_tab.getchild(role="tree_table")
250
 
        
251
 
        return bool(table[0].doesrowexist(name))
252
 
 
253
 
    def remove_key(self, key):
254
 
        seahorse = ooldtp.context(self.name)
255
 
 
256
 
        tbl_personal_keys = seahorse.getchild(self.TBL_PERSONAL_KEYS)
257
 
        mnu_delete = seahorse.getchild(_('mnuDelete'))
258
 
        dlg_question = ooldtp.context('dlgQuestion')
259
 
 
260
 
        try:
261
 
            tbl_personal_keys.selectrow(key)
262
 
        except ldtp.LdtpExecutionError:
263
 
            # Doesn't exist, return False.
264
 
            return False
265
 
 
266
 
        mnu_delete.selectmenuitem()
267
 
        # General 'private key' verification.
268
 
        dlg_question.waittillguiexist(self.LBL_DELETE_KEY_Q)
269
 
        dlg_question.click(_('btnDelete'))
270
 
        dlg_question.waittillguinotexist(self.LBL_DELETE_KEY_Q)
271
 
 
272
 
        # Specific key type verification.
273
 
        dlg_question.waittillguiexist()
274
 
        dlg_question.click(_('btnDelete'))
275
 
        dlg_question.waittillguinotexist()
276
 
        
277
 
        return True
278
 
 
279
 
    def remove_keys(self, keys=None, tab_name=None):
280
 
        self.go_to_tab(tab_name or self.TAB_PERSONAL_KEYS)
281
 
 
282
 
        keys = keys or self.generated_keys
283
 
 
284
 
        for key in keys:
285
 
            self.remove_key(key)