~straemer/ubuntu/quantal/update-manager/fix-for-1058070

« back to all changes in this revision

Viewing changes to UpdateManager/UpdateProgress.py

  • Committer: Package Import Robot
  • Author(s): Michael Terry
  • Date: 2012-06-29 10:59:30 UTC
  • mfrom: (389.1.2 precise-security)
  • Revision ID: package-import@ubuntu.com-20120629105930-0oaj9vdvykmvkjum
Tags: 1:0.165
* Implementation of "update on start" feature from spec
  https://wiki.ubuntu.com/SoftwareUpdates
* Use a single main window that changes instead of having modal dialogs
* Implement several special-purpose dialogs like "No updates" or
  "Dist upgrade needed" accordingn to the above spec
* Split out release upgrader code and DistUpgrade module into a separate
  source package
* Drop python-update-manager, as it is unused
* debian/tests:
  - Add dep8 tests

Show diffs side-by-side

added added

removed removed

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