~ubuntu-core-dev/update-manager/main

« back to all changes in this revision

Viewing changes to UpdateManager/UpdateProgress.py

  • Committer: Michael Terry
  • Date: 2012-05-31 22:22:44 UTC
  • mto: (2503.1.1 mterry)
  • mto: This revision was merged to the branch mainline in revision 2504.
  • Revision ID: michael.terry@canonical.com-20120531222244-efhxv4cajy9okvvh
add new class to do an update before main window comes up

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# UpdateManager.py
 
2
#  
 
3
#  Copyright (c) 2004-2010 Canonical
 
4
#                2004 Michiel Sikkes
 
5
#                2005 Martin Willemoes Hansen
 
6
#                2010 Mohamed Amine IL Idrissi
 
7
#  
 
8
#  Author: Michiel Sikkes <michiel@eyesopened.nl>
 
9
#          Michael Vogt <mvo@debian.org>
 
10
#          Martin Willemoes Hansen <mwh@sysrq.dk>
 
11
#          Mohamed Amine IL Idrissi <ilidrissiamine@gmail.com>
 
12
#          Alex Launi <alex.launi@canonical.com>
 
13
 
14
#  This program is free software; you can redistribute it and/or 
 
15
#  modify it under the terms of the GNU General Public License as 
 
16
#  published by the Free Software Foundation; either version 2 of the
 
17
#  License, or (at your option) any later version.
 
18
 
19
#  This program is distributed in the hope that it will be useful,
 
20
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
#  GNU General Public License for more details.
 
23
 
24
#  You should have received a copy of the GNU General Public License
 
25
#  along with this program; if not, write to the Free Software
 
26
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
27
#  USA
 
28
 
 
29
from __future__ import absolute_import, print_function
 
30
 
 
31
from gi.repository import Gtk
 
32
 
 
33
import warnings
 
34
warnings.filterwarnings("ignore", "Accessed deprecated property", DeprecationWarning)
 
35
 
 
36
import os
 
37
import sys
 
38
 
 
39
from .backend import get_backend
 
40
 
 
41
from gettext import gettext as _
 
42
from gettext import ngettext
 
43
 
 
44
from .Core.utils import (inhibit_sleep,
 
45
                         allow_sleep)
 
46
 
 
47
class UpdateProgress(object):
 
48
 
 
49
  def __init__(self):
 
50
    # Used for inhibiting power management
 
51
    self.sleep_cookie = None
 
52
    self.sleep_dev = None
 
53
 
 
54
    # get the install backend
 
55
    self.install_backend = get_backend(None)
 
56
    self.install_backend.connect("action-done", self._on_backend_done)
 
57
 
 
58
  def invoke_manager(self):
 
59
    # don't display apt-listchanges
 
60
    os.environ["APT_LISTCHANGES_FRONTEND"]="none"
 
61
 
 
62
    # Do not suspend during the update process
 
63
    (self.sleep_dev, self.sleep_cookie) = inhibit_sleep()
 
64
 
 
65
    self.install_backend.update()
 
66
 
 
67
  def _on_backend_done(self, backend, action, authorized, success):
 
68
    # Allow suspend after synaptic is finished
 
69
    if self.sleep_cookie:
 
70
      allow_sleep(self.sleep_dev, self.sleep_cookie)
 
71
      self.sleep_cookie = self.sleep_dev = None
 
72
 
 
73
    # Either quit the current blocking loop and continue or quit altogether
 
74
    if success:
 
75
      Gtk.main_quit()
 
76
    else:
 
77
      sys.exit(0)
 
78
 
 
79
  def main(self):
 
80
    self.invoke_manager()
 
81
    Gtk.main()