1
# -*- coding: utf-8 -*-
6
This is the "Seahorse" module.
8
This module provides a wrapper for LDTP to make the writing of Seahorse tests
13
from .main import Application
14
from ..gconfwrapper import GConf
16
from ..cmd import globals
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)
25
class Seahorse(Application):
27
Seahorse manages the Seahorse application.
29
WINDOW = _("frmPasswordsandEncryptionKeys")
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")
55
TBL_PERSONAL_KEYS = "ttbl1"
56
LBL_DELETE_KEY_Q = _("lblOneormoreofthedeletedkeysareprivatekeys.Areyousureyouwanttoproceed?")
59
Application.__init__(self)
60
self.generated_keys = []
62
def new_key(self, key_type):
64
It opens up the list of available new keys, and select the one to create.
66
@type key_type: string
67
@param key_type: The type of key to create.
70
seahorse = ooldtp.context(self.name)
72
mnu_new_key = seahorse.getchild(self.MNU_NEWKEY)
73
mnu_new_key.selectmenuitem()
75
ldtp.waittillguiexist(self.NEWKEY_DLG)
76
dlg_new_key = ooldtp.context(self.NEWKEY_DLG)
78
table = dlg_new_key.getchild(role = 'table')
79
types_table = table[0]
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)
89
btn_continue = dlg_new_key.getchild(self.BTN_CONTINUE)
93
def new_pgp_key(self, full_name, email, comment, passphrase):
95
It creates a new PGP key with the default settings.
97
TODO: Allow advanced options
98
TODO: Check the list afterwards for the newly created key
100
@type full_name: string
101
@param full_name: Full name to type for the PGP key
104
@param email: Email to type for the PGP key
106
@type comment: string
107
@param comment: Comment to type for the PGP key
109
@type passphrase: string
110
@param passphrase: Passphrase to type for the PGP key
113
self.new_key(self.TYPE_PGP)
115
ldtp.waittillguiexist(self.NEWPGP_DLG)
116
dlg_new_pgp = ooldtp.context(self.NEWPGP_DLG)
118
txt_field = dlg_new_pgp.getchild(self.DLG_NEWPGP_FULLNAME)
119
txt_field.settextvalue(full_name)
121
txt_field = dlg_new_pgp.getchild(self.DLG_NEWPGP_EMAIL)
122
txt_field.settextvalue(email)
124
txt_field = dlg_new_pgp.getchild(self.DLG_NEWPGP_COMMENT)
125
txt_field.settextvalue(comment)
127
btn_create = dlg_new_pgp.getchild(self.BTN_NEWPGP_CREATE)
130
ldtp.waittillguiexist(self.DLG_NEWKEY_PASS)
131
dlg_new_pgp_pass = ooldtp.context(self.DLG_NEWKEY_PASS)
133
# Entering the passphrase
134
ldtp.enterstring(passphrase)
135
ldtp.enterstring("<tab>")
136
ldtp.enterstring(passphrase)
138
btn_pass_ok = dlg_new_pgp_pass.getchild(self.BTN_PASS_OK)
142
ldtp.waittillguiexist(self.DLG_GENERATING_KEY)
143
while ldtp.guiexist(self.DLG_GENERATING_KEY) == 1:
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+"'"]))
149
def new_ssh_key(self, description, passphrase, set_up = False, computer = '', login = ''):
151
It creates a new SSH key with the default settings.
153
TODO: Setting up the key is not working yet
155
@type description: string
156
@param description: Description to type in the SSH key
158
@type passphrase: string
159
@param passphrase: Passphrase to type for the SSH key
161
@type set_up: boolean
162
@param passphrase: True, to set up the SSH key
164
@type computer: string
165
@param computer: URL or IP of the computer to set up the key
168
@param login: Login to use in the remote computer
171
self.new_key(self.TYPE_SSH)
173
ldtp.waittillguiexist(self.NEWSSH_DLG)
174
dlg_new_ssh = ooldtp.context(self.NEWSSH_DLG)
176
txt_field = dlg_new_ssh.getchild(self.DLG_NEWSSH_DESC)
177
txt_field.settextvalue(description)
180
btn_create = dlg_new_ssh.getchild(self.BTN_NEWSSH_CREATE_AND_SETUP)
182
btn_create = dlg_new_ssh.getchild(self.BTN_NEWSSH_CREATE)
187
ldtp.waittillguiexist(self.DLG_NEWKEY_PASS)
188
dlg_new_key_pass = ooldtp.context(self.DLG_NEWKEY_PASS)
190
# Entering the passphrase
191
ldtp.enterstring(passphrase)
192
ldtp.enterstring("<tab>")
193
ldtp.enterstring(passphrase)
195
btn_pass_ok = dlg_new_key_pass.getchild(self.BTN_PASS_OK)
198
if set_up == True and login is not None:
200
ldtp.waittillguiexist(self.DLG_SET_UP)
201
dlg_set_up_computer = ooldtp.context(self.DLG_SET_UP)
203
txt_field = dlg_set_up_computer.getchild(self.TXT_SET_UP_LOGIN)
204
txt_field.settextvalue(login)
207
txt_field = dlg_set_up_computer.getchild(self.TXT_SET_UP_COMPUTER)
208
txt_field.settextvalue(computer)
210
btn_set_up = dlg_set_up_computer.getchild(self.BTN_SET_UP)
213
while ldtp.guiexist(self.DLG_CREATING_SSH) == 1:
216
# Add key name to generated key list, so we know to delete it later.
217
self.generated_keys.append(description)
219
# It is too fast to grab the main window afterwards
222
def go_to_tab(self, tab_name):
224
Go to the specified tab.
226
seahorse = ooldtp.context(self.name)
227
page_list = seahorse.getchild(self.TAB_LIST)
228
page_list.selecttab(self.TAB_PERSONAL_KEYS)
231
def assert_exists_key(self, name, tab_name = None):
233
It checks that the KEY with description 'description' is
234
part of the keys of the current user
237
@param name: The name of the key to search
239
@type tab_name: string
240
@param tab_name: The tab name to search for the key.
243
tab_name = self.TAB_PERSONAL_KEYS
245
self.go_to_tab(tab_name)
246
seahorse = ooldtp.context(self.name)
248
selected_tab = seahorse.getchild(tab_name)
249
table = selected_tab.getchild(role="tree_table")
251
return bool(table[0].doesrowexist(name))
253
def remove_key(self, key):
254
seahorse = ooldtp.context(self.name)
256
tbl_personal_keys = seahorse.getchild(self.TBL_PERSONAL_KEYS)
257
mnu_delete = seahorse.getchild(_('mnuDelete'))
258
dlg_question = ooldtp.context('dlgQuestion')
261
tbl_personal_keys.selectrow(key)
262
except ldtp.LdtpExecutionError:
263
# Doesn't exist, return False.
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)
272
# Specific key type verification.
273
dlg_question.waittillguiexist()
274
dlg_question.click(_('btnDelete'))
275
dlg_question.waittillguinotexist()
279
def remove_keys(self, keys=None, tab_name=None):
280
self.go_to_tab(tab_name or self.TAB_PERSONAL_KEYS)
282
keys = keys or self.generated_keys