234
242
self.transaction.paused = True
235
243
self.transaction.status = enums.STATUS_WAITING_MEDIUM
236
244
while self.transaction.paused:
237
gobject.main_context_default().iteration()
245
GObject.main_context_default().iteration()
238
246
self.transaction.status = enums.STATUS_DOWNLOADING
239
247
if self.transaction.cancelled:
252
class DaemonAcquireRepoProgress(DaemonAcquireProgress):
254
"""Handle the repository information download"""
256
def __init__(self, transaction, begin=0, end=100):
257
DaemonAcquireProgress.__init__(self, transaction, begin, end)
258
self.languages = IsoCodes("iso_639", "iso_639_1_code")
259
self.countries = IsoCodes("iso_3166", "alpha_2_code")
263
"""Callback at the beginning of the operation"""
264
self.transaction.status = enums.STATUS_DOWNLOADING_REPO
265
self.transaction.cancellable = True
267
def _emit_status_details(self, items):
268
"""Emit the transaction status details."""
271
# We are only interested in the hostname currently
273
repos.add(item.description.split()[0].split("://")[-1])
275
#TRANSLATORS: the string is used as a fallback if we cannot
276
# get the URI of a local repository
277
repos.add(self.transaction.gettext("local repository"))
279
#TRANSLATORS: %s is a list of repository names
280
msg = self.transaction.ngettext("Downloading from %s",
281
"Downloading from %s",
282
len(repos)) % " ".join(repos)
283
self.transaction.status_details = msg
285
def _emit_acquire_item(self, item, total_size=0, current_size=0):
286
if item.owner.status == apt_pkg.AcquireItem.STAT_DONE:
287
status = enums.DOWNLOAD_DONE
288
# Workaround for a bug in python-apt, see lp: #581886
289
current_size = item.owner.filesize
290
elif item.owner.status == apt_pkg.AcquireItem.STAT_AUTH_ERROR:
291
status = enums.DOWNLOAD_AUTH_ERROR
292
elif item.owner.status == apt_pkg.AcquireItem.STAT_FETCHING:
293
status = enums.DOWNLOAD_FETCHING
294
elif item.owner.status == apt_pkg.AcquireItem.STAT_ERROR:
295
status = enums.DOWNLOAD_ERROR
296
elif item.owner.status == apt_pkg.AcquireItem.STAT_IDLE:
297
status = enums.DOWNLOAD_IDLE
299
# Workaround: The StatTransientNetworkError status isn't mapped
300
# by python-apt, see LP #602578
301
status = enums.DOWNLOAD_NETWORK_ERROR
302
if item.owner.status != apt_pkg.AcquireItem.STAT_DONE and \
303
item.owner.error_text:
304
msg = item.owner.error_text
305
elif item.owner.mode:
306
msg = item.owner.mode
309
# Get a better description than e.g. Packages or Sources
310
host, dist = item.description.split()[0:2]
312
host = host.split("://")[1]
314
#TRANSLATORS: the string is used as a fallback if we cannot
315
# get the URI of a local repository
316
desc = self.transaction.gettext("local repository")
317
repo = "%s %s" % (host, dist)
318
if item.shortdesc == "InRelease":
319
#TRANSLATORS: repo is the name of a repository
320
desc = self.transaction.gettext("Structure of %s") % repo
321
elif item.shortdesc == "Release":
322
#TRANSLATORS: repo is the name of a repository
323
desc = self.transaction.gettext("Description of %s") % repo
324
elif item.shortdesc == "Release.gpg":
325
#TRANSLATORS: repo is the name of a repository
326
desc = self.transaction.gettext("Description signature "
328
elif item.shortdesc.startswith("Packages"):
329
#TRANSLATORS: repo is the name of a repository
330
desc = self.transaction.gettext("Available packages from %s") % repo
331
elif item.shortdesc.startswith("Sources"):
332
#TRANSLATORS: repo is the name of a repository
333
desc = self.transaction.gettext("Available sources from %s") % repo
334
elif item.shortdesc == "TranslationIndex":
335
#TRANSLATORS: repo is the name of a repository
336
desc = self.transaction.gettext("Available translations from "
338
elif item.shortdesc.startswith("Translation-"):
339
lang = item.shortdesc.split("-", 1)[-1]
341
lang, country = lang.split("_")
345
#TRANSLATORS: The first %s is the name of a language. The second
346
# one the name of the country. The third %s is the
347
# name of a repository
348
desc = self.transaction.gettext("Translations for %s (%s) from "
350
(self.languages.get_localised_name(lang,
351
self.transaction.locale),
352
self.countries.get_localised_name(country,
353
self.transaction.locale),
356
#TRANSLATORS: %s is the name of a language. The second one is
357
# the name of the repository
358
desc = self.transaction.gettext("Translations for %s from "
360
(self.languages.get_localised_name(lang,
361
self.transaction.locale),
364
desc = item.shortdesc
365
self.transaction.progress_download = item.uri, status, desc, \
366
total_size | item.owner.filesize, \
367
current_size | item.owner.partialsize, \
244
371
class DaemonInstallProgress(object):
246
373
def __init__(self, transaction, begin=50, end=100):
314
438
os.close(self.status_child_fd)
315
439
log.debug("Child pid: %s", pid)
317
flags = gobject.IO_IN | gobject.IO_ERR | gobject.IO_HUP
441
flags = GObject.IO_IN | GObject.IO_ERR | GObject.IO_HUP
318
442
if self.transaction.terminal:
319
443
# Setup copying of i/o between the controlling terminals
320
watchers.append(gobject.io_add_watch(terminal_fd, flags,
444
watchers.append(GObject.io_add_watch(terminal_fd, flags,
322
watchers.append(gobject.io_add_watch(self.master_fd, flags,
446
watchers.append(GObject.io_add_watch(self.master_fd, flags,
323
447
self._copy_io_master, terminal_fd))
324
448
# Monitor the child process
325
watchers.append(gobject.child_watch_add(pid, self._on_child_exit))
449
watchers.append(GObject.child_watch_add(pid, self._on_child_exit))
326
450
# Watch for status updates
327
watchers.append(gobject.io_add_watch(self.status_parent_fd,
451
watchers.append(GObject.io_add_watch(self.status_parent_fd,
329
453
self._on_status_update))
330
454
while self._child_exit == -1:
331
gobject.main_context_default().iteration()
455
GObject.main_context_default().iteration()
332
456
for id in watchers:
333
gobject.source_remove(id)
457
GObject.source_remove(id)
334
458
# Restore the settings of the transaction terminal