~packagekit/packagekit/ubuntu-packagekit-gnome-0.2.x

« back to all changes in this revision

Viewing changes to debian/patches/03_improve_installprogress.patch

  • Committer: Michael Vogt
  • Date: 2008-08-08 13:04:58 UTC
  • Revision ID: michael.vogt@ubuntu.com-20080808130458-rhmpi6lzb8v8y0xc
* debian/patches/03_improve_installprogress.patch:
  - kill maintainer scripts that hang
  - send backend.Message() after the install if conffile prompts are
    detected during the install (default to keep old conffile)
  - implement doUpdatePackages() 
  (patch sent to upstream git repo)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
diff --git a/backends/apt/aptDBUSBackend.py b/backends/apt/aptDBUSBackend.py
 
2
index da1fad2..4d6a623 100755
 
3
--- a/backends/apt/aptDBUSBackend.py
 
4
+++ b/backends/apt/aptDBUSBackend.py
 
5
@@ -121,19 +121,23 @@ class PackageKitFetchProgress(apt.progress.FetchProgress):
 
6
         #FIXME: use the Message method to notify the user
 
7
         self._backend.error(ERROR_UNKNOWN,
 
8
                             "Medium change needed")
 
9
-
 
10
 class PackageKitInstallProgress(apt.progress.InstallProgress):
 
11
     '''
 
12
     Handle the installation and removal process. Bits taken from
 
13
     DistUpgradeViewNonInteractive.
 
14
     '''
 
15
+
 
16
+    # a insanly long timeout to be able to kill hanging maintainer
 
17
+    # scripts
 
18
+    TIMEOUT = 10*60
 
19
+
 
20
     def __init__(self, backend, prange=(0,100)):
 
21
         apt.progress.InstallProgress.__init__(self)
 
22
         self._backend = backend
 
23
-        self.timeout = 900
 
24
         self.pstart = prange[0]
 
25
         self.pend = prange[1]
 
26
         self.pprev = None
 
27
+        self.conffile_prompts = set()
 
28
 
 
29
     def statusChange(self, pkg, percent, status):
 
30
         progress = self.pstart + percent/100 * (self.pend - self.pstart)
 
31
@@ -146,12 +150,33 @@ class PackageKitInstallProgress(apt.progress.InstallProgress):
 
32
         self._backend.StatusChanged(STATUS_INSTALL)
 
33
         self.last_activity = time.time()
 
34
 
 
35
+    def fork(self):
 
36
+        pklog.debug("fork()")
 
37
+        (pid, self.master_fd) = pty.fork()
 
38
+        return pid
 
39
+
 
40
     def updateInterface(self):
 
41
-        pklog.debug("Updating interface")
 
42
+        #pklog.debug("Updating interface")
 
43
         apt.progress.InstallProgress.updateInterface(self)
 
44
+        try:
 
45
+            pklog.debug("%s" % os.read(self.master_fd, 512))
 
46
+        except Exception, e:
 
47
+            pklog.debug("ioerror: %s" % e)
 
48
+        # we timed out, send ctrl-c
 
49
+        if self.last_activity + self.TIMEOUT < time.time():
 
50
+            pklog.critical("no activity for %s time sending ctrl-c" % self.TIMEOUT)
 
51
+            os.write(self.master_fd, 3)
 
52
 
 
53
     def conffile(self, current, new):
 
54
-        pklog.critical("Config file prompt: '%s'" % current)
 
55
+        pklog.warning("Config file prompt: '%s' (sending no)" % current)
 
56
+        i = os.write(self.master_fd, "n\n")
 
57
+        pklog.debug("wrote n, send %i bytes" % i)
 
58
+        self.conffile_prompts.add(new)
 
59
+    
 
60
+    def finishUpdate(self):
 
61
+        pklog.debug("finishUpdate()")
 
62
+        if self.conffile_prompts:
 
63
+            self._backend.Message(MESSAGE_NOTICE, "The following conffile prompts were found and need investiagtion: %s" % "\n".join(self.conffile_prompts))
 
64
 
 
65
 def sigquit(signum, frame):
 
66
     pklog.error("Was killed")
 
67
@@ -413,6 +438,59 @@ class PackageKitAptBackend(PackageKitBaseBackend):
 
68
 
 
69
     @threaded
 
70
     @async
 
71
+    def doUpdatePackages(self, ids):
 
72
+        '''
 
73
+        Implement the {backend}-update functionality
 
74
+        '''
 
75
+        pklog.info("Updating package with id %s" % ids)
 
76
+        self.StatusChanged(STATUS_INSTALL)
 
77
+        self.AllowCancel(False)
 
78
+        self.PercentageChanged(0)
 
79
+        self.StatusChanged(STATUS_RUNNING)
 
80
+        pkgs=[]
 
81
+        for id in ids:
 
82
+            pkg = self._find_package_by_id(id)
 
83
+            if pkg == None:
 
84
+                self.ErrorCode(ERROR_PACKAGE_NOT_FOUND,
 
85
+                               "Package %s isn't available" % id)
 
86
+                self.Finished(EXIT_FAILED)
 
87
+                return
 
88
+            if not pkg.isUpgradable:
 
89
+                self.ErrorCode(ERROR_PACKAGE_ALREADY_INSTALLED,
 
90
+                               "Package %s is already installed" % pkg.name)
 
91
+                self.Finished(EXIT_FAILED)
 
92
+                return
 
93
+            pkgs.append(pkg.name[:])
 
94
+            try:
 
95
+                pkg.markUpgrade()
 
96
+            except:
 
97
+                self._open_cache(prange=(90,100))
 
98
+                self.ErrorCode(ERROR_UNKNOWN, "%s could not be queued for "
 
99
+                                              "installation" % pkg.name)
 
100
+                self.Finished(EXIT_FAILED)
 
101
+                return
 
102
+        try:
 
103
+            self._cache.commit(PackageKitFetchProgress(self, prange=(10,50)),
 
104
+                               PackageKitInstallProgress(self, prange=(50,90)))
 
105
+        except Exception, e:
 
106
+            pklog.warning("exception %s during commit()" % e)
 
107
+            self._open_cache(prange=(90,100))
 
108
+            self.ErrorCode(ERROR_UNKNOWN, "Installation failed")
 
109
+            self.Finished(EXIT_FAILED)
 
110
+            return
 
111
+        self._open_cache(prange=(90,100))
 
112
+        self.PercentageChanged(100)
 
113
+        pklog.debug("Checking success of operation")
 
114
+        for p in pkgs:
 
115
+            if not self._cache.has_key(p) or not self._cache[p].isInstalled:
 
116
+                self.ErrorCode(ERROR_UNKNOWN, "%s was not installed" % p)
 
117
+                self.Finished(EXIT_FAILED)
 
118
+                return
 
119
+        pklog.debug("Sending success signal")
 
120
+        self.Finished(EXIT_SUCCESS)
 
121
+
 
122
+    @threaded
 
123
+    @async
 
124
     def doInstallPackages(self, ids):
 
125
         '''
 
126
         Implement the {backend}-install functionality
 
127
@@ -447,7 +525,8 @@ class PackageKitAptBackend(PackageKitBaseBackend):
 
128
         try:
 
129
             self._cache.commit(PackageKitFetchProgress(self, prange=(10,50)),
 
130
                                PackageKitInstallProgress(self, prange=(50,90)))
 
131
-        except:
 
132
+        except Exception, e:
 
133
+            pklog.warning("exception %s during commit()" % e)
 
134
             self._open_cache(prange=(90,100))
 
135
             self.ErrorCode(ERROR_UNKNOWN, "Installation failed")
 
136
             self.Finished(EXIT_FAILED)