4
This is the "update_manager" module.
6
This module provides a wrapper for LDTP to make the writing of Update Manager
11
from .main import Application
12
from .policykit import PolicyKit
13
from ..cmd import globals
16
gettext.install (True)
17
gettext.bindtextdomain (PACKAGE, globals.LOCALE_SHARE)
18
gettext.textdomain (PACKAGE)
19
t = gettext.translation(PACKAGE, globals.LOCALE_SHARE, fallback = True)
23
class UpdateManager(Application):
25
UpdateManager class manages the Ubuntu Update Manager application.
27
If the test is going to need admin permissions, you need to provide the su password
28
when creating an instance of the class.
30
i.e. C{updateManager = UpdateManager("my_password")}
32
MNU_ITEM = _("mnuUpdateManager")
33
WINDOW = _("frmUpdateManager")
34
LAUNCHER = "update-manager"
35
BTN_CLOSE = _("btnClose")
36
BTN_CHECK = _("btnCheck")
37
BTN_INSTALL = _("btnInstallUpdates")
38
TBL_UPDATES = _("updates")
39
BAN_LIST = _(" updates")
40
TAB_CHANGES = _("Changes")
41
TXT_DESCRIPTION = _("Description")
42
LBL_WAIT = _("lblKeepyoursystemup-to-date")
43
LBL_UPTODATE = _("lblYoursystemisup-to-date")
44
LBL_N_UPDATES = _(r'lbl(\d+)updates?hasbeenselected')
45
LBL_DOWNLOADSIZE = _(r'lblDownloadsize((\d+)((\.)(\d+))?)(.*)')
49
def __init__(self, password = ""):
51
UpdateManager class init method
53
If the test is going to need admin permissions, you need to provide the su password
54
when creating an instance of the class.
56
i.e. C{updateManager = UpdateManager("my_password")}
58
@type password: string
59
@param password: User's password for administrative tasks.
62
Application.__init__(self)
63
self.password = password
65
def set_password(self, password):
66
self.password = password
68
def open(self, dist_upgrade=False):
70
It opens the update-manager application and raises an error if the application
71
didn't start properly.
76
ldtp.launchapp(self.LAUNCHER, ['-d'], 0)
77
response = ldtp.waittillguiexist(self.name, '', 20)
80
raise ldtp.LdtpExecutionError, "The " + self.name + " window was not found."
83
Application.open(self)
85
# Wait the population of the list
86
updateManager = ooldtp.context(self.name)
94
label = updateManager.getchild(role = 'label')
96
label_name = i.getName()
97
if label_name == self.LBL_WAIT:
102
It closes the update-manager window using the close button.
105
updateManager = ooldtp.context(self.name)
107
closeButton = updateManager.getchild(self.BTN_CLOSE)
110
ldtp.waittillguinotexist (self.name)
112
def number_updates(self):
114
With the available repositories, it returns the number of available
115
updates for the system.
117
@return: An integer with the number of available updates.
120
updateManager = ooldtp.context(self.name)
122
label = updateManager.getchild(role = 'label')
124
label_name = i.getName()
125
if label_name == self.LBL_UPTODATE:
128
groups = re.match(self.LBL_N_UPDATES, label_name)
130
number = groups.group(1)
134
def download_size(self):
136
It returns the download size of the selected updates.
138
@return: A float with the download size in bytes
140
updateManager = ooldtp.context(self.name)
142
label = updateManager.getchild(role = 'label')
144
label_name = i.getName()
145
groups = re.match(self.LBL_DOWNLOADSIZE, label_name)
148
# Calculate size based on the tag after the number
149
tag_size = groups.group(6)
152
elif tag_size == 'KB':
154
elif tag_size == 'MB':
156
elif tag_size == 'GB':
161
total_size = float(groups.group(1)) * size
166
def select_all(self):
168
It selects all the available updates
170
updateManager = ooldtp.context(self.name)
172
table = updateManager.getchild(self.TBL_UPDATES, role = 'table')
173
updates_table = table[0]
175
for i in range(0, updates_table.getrowcount(), 1):
176
updates_table.checkrow(i)
181
def unselect_all(self):
183
It unselects all the available updates
185
updateManager = ooldtp.context(self.name)
187
table = updateManager.getchild(self.TBL_UPDATES, role = 'table')
188
updates_table = table[0]
190
# TODO: When table admits right click, use the context menu
192
size_updates = self.download_size()
193
while size_updates > 0:
194
for i in range(0, updates_table.getrowcount(), 1):
195
updates_table.uncheckrow(i)
198
size_updates = self.download_size()
202
def get_available_updates(self):
204
It gets the name of the packages of the available updates
206
@return: A list with the available updates
209
updateManager = ooldtp.context(self.name)
211
available_updates = []
213
table = updateManager.getchild(self.TBL_UPDATES, role = 'table')
214
updates_table = table[0]
216
for i in range(0, updates_table.getrowcount(), 1):
217
text = updates_table.getcellvalue(i, 1)
218
candidate = text.split('\n')[0]
219
if candidate.find(self.BAN_LIST) == -1:
220
available_updates.append(candidate)
223
return available_updates
225
def select_update(self, name):
227
It selects a particular package in the list (not for update, just the list).
230
@param name: The name of the package to select
233
updateManager = ooldtp.context(self.name)
235
table = updateManager.getchild(self.TBL_UPDATES, role = 'table')
236
updates_table = table[0]
238
for i in range(0, updates_table.getrowcount(), 1):
239
text = updates_table.getcellvalue(i, 1)
240
candidate = text.split('\n')[0]
241
if candidate == name:
242
updates_table.selectrowindex(i)
246
def tick_update(self, name):
248
It selects a particular package for update.
251
@param name: The name of the package to select
254
updateManager = ooldtp.context(self.name)
256
table = updateManager.getchild(self.TBL_UPDATES, role = 'table')
257
updates_table = table[0]
259
for i in range(0, updates_table.getrowcount(), 1):
260
text = updates_table.getcellvalue(i, 1)
261
candidate = text.split('\n')[0]
262
if candidate == name:
263
updates_table.checkrow(i)
267
def check_updates(self):
269
It checks the repositories for new updates in the update-manager application.
271
This action requires administrative permissions, therefore this method will
272
raise an error if the UpdateManager instance was created without password.
275
updateManager = ooldtp.context(self.name)
277
if self.password == "":
278
raise ldtp.LdtpExecutionError, "Checking for updates requires administrative permissions."
281
# We will need administrative permission
282
polKit = PolicyKit(self.password)
284
checkButton = updateManager.getchild(self.BTN_CHECK)
287
# Administrative permissions
291
polKit.set_password()
293
# HACK to wait for repositories
296
def install_updates(self):
298
It installs the selected updates.
300
If no updates are available, it won't do anything.
303
updateManager = ooldtp.context(self.name)
305
# If there is any update available, install it
306
if self.number_updates() > 0:
307
btnInstall = updateManager.getchild(self.BTN_INSTALL)
309
if btnInstall.stateenabled():
312
# We will need administrative permission
313
polKit = PolicyKit(self.password)
315
# Administrative permissions
319
polKit.set_password()
321
# Wait for the the close button to be ready
322
btnClose = updateManager.getchild(self.BTN_CLOSE)
323
while not btnClose.stateenabled():
326
def test_install_state(self):
328
It checks if the install button is enabled or not
330
@return: True if the install button is enabled. False, otherwise.
333
updateManager = ooldtp.context(self.name)
335
btnTest = updateManager.getchild(self.BTN_INSTALL)
336
state = btnTest.stateenabled()
340
def show_changes(self):
342
It shows the Description of the updates
344
self.toggle_changes(True)
346
def hide_changes(self):
348
It hides the Description of the updates
350
self.toggle_changes(False)
352
def get_description(self, name=''):
354
It returns the description of a package for a given update.
355
If no update is mentioned, then the description for the
356
selected application is returned.
359
@param name: The package to show the description. If left blank, the current
360
selection will be chosen.
362
@return: The decription of the packages, as shown in the application
364
updateManager = ooldtp.context(self.name)
367
self.select_update(name)
369
# Get the description text field
370
text_field = updateManager.getchild(self.TXT_DESCRIPTION, role='text')
372
text = ldtp.gettextvalue(self.name, text_field[0].getName())
377
def get_changes(self, name=''):
379
It returns the changes description for a given update.
380
If no update is mentioned, then the changes description for the
381
selected application is returned.
384
@param name: The package to show changes. If left blank, the current
385
selection will be chosen.
387
@return: The decription of the changes
389
ooldtp.context(self.name)
392
self.select_update(name)
395
filler = ldtp.getobjectproperty(self.name , self.TAB_CHANGES, 'children')
396
# Get the scroll pane
397
scroll_pane = ldtp.getobjectproperty(self.name , filler, 'children')
399
text_field = ldtp.getobjectproperty(self.name , scroll_pane, 'children')
400
text_field = text_field.split(' ')[0]
402
text = ldtp.gettextvalue(self.name, text_field)
407
def toggle_changes(self, show):
409
It shows or hides the Description of the updates
412
@param show: True, to show the description; False, to hide the description.
414
updateManager = ooldtp.context(self.name)
416
toggle_button = updateManager.getchild(role='toggle button')
417
state = toggle_button[0].verifytoggled()
420
toggle_button[0].click()