~ubuntu-branches/ubuntu/saucy/apturl/saucy

« back to all changes in this revision

Viewing changes to AptUrl/kde/KdeUI.py

  • Committer: Package Import Robot
  • Author(s): Brian Murray, Brian Murray, Colin Watson, Barry Warsaw
  • Date: 2012-06-11 10:32:52 UTC
  • Revision ID: package-import@ubuntu.com-20120611103252-sls6xzdyuxfzt3v0
Tags: 0.5.1ubuntu4
[ Brian Murray ]
* Port to Python 3:
  - Use Python 3 style print functions
* AptUrl/Parser.py:
  - ensure MAX_URL_LEN/10 returns an int

[ Colin Watson ]
* AptUrl/gtk/backend/InstallBackendSynaptic.py:
  - Keep a reference to the data tuple passed to GObject.child_watch_add
    to avoid attempts to destroy it without a thread context.
  - Open temporary synaptic selections file in text mode.

[ Barry Warsaw ]
* Additional Python 3 fixes:
  + Port setup.py to Python 3.
  + Use the new python-apt API since the legacy API is not available in
    Python 3.
  + ki18n() takes bytes.
  + Fix relative imports so the code can be run from source.
  + Fixed some additional packaging paths.
  + Change #! lines to use python3.
  + Changed debian/control and debian/rules to use python3.
  + Change debian/compat == 9
  + apturl now must require python3-aptdaemon.gtk3widgets (i.e. not |
    synaptic) due to the Python 3 port of update-manager.
* Other changes:
  + Remove the need for threads in the KDE front-end.
  + Enable running the test suite via `python3 -m unittest discover`
  + i18n updates.
  + Various and sundry pyflakes, whitespace, style, line length, and
    spelling fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
from PyKDE4.kdeui import *
8
8
from PyKDE4.kdecore import *
9
9
 
10
 
import subprocess
11
 
from tempfile import NamedTemporaryFile
12
 
 
13
10
import os
14
 
import os.path
15
 
 
16
 
import time
17
 
import thread
18
11
import apt_pkg
 
12
import subprocess
19
13
 
20
14
from AptUrl.UI import AbstractUI
21
 
from AptUrl import Helpers
22
 
from AptUrl.Helpers import utf8, _, _n
 
15
from AptUrl.Helpers import _
 
16
 
 
17
APTURL_UI_FILE = os.environ.get(
 
18
    # Set this envar to use a test .ui file.
 
19
    'APTURL_UI_FILE',
 
20
    # System file to use if the envar is not set.
 
21
    '/usr/share/apturl/apturl-qt.ui'
 
22
    )
 
23
 
23
24
 
24
25
class AptUrlDialog(KDialog):
25
26
    def __init__(self,parent=None):
32
33
        else:
33
34
            KDialog.reject(self)
34
35
 
 
36
 
35
37
class KdeUI(AbstractUI):
36
38
    def __init__(self):
37
39
        self.dialog = AptUrlDialog()
39
41
        self.d = QWidget(self.dialog)
40
42
        self.dialog.setMainWidget(self.d)
41
43
 
42
 
        uic.loadUi('/usr/share/apturl/apturl-qt.ui', self.d)
 
44
        uic.loadUi(APTURL_UI_FILE, self.d)
43
45
        self.d.image_label.setPixmap(KIcon("application-x-deb").pixmap(64,64))
44
46
 
45
47
    # generic dialogs
95
97
               "software-properties-kde",
96
98
               "--enable-component", "%s" % ' '.join(sections)]
97
99
        try:
98
 
            output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
99
 
        except OSError, e:
100
 
            print >>sys.stderr, "Execution failed:", e
 
100
            output = subprocess.check_output(
 
101
                cmd,
 
102
                stdout=subprocess.PIPE,
 
103
                universal_newlines=True)
 
104
        except (OSError, subprocess.CalledProcessError) as e:
 
105
            print("Execution failed: %s" % e, file=sys.stderr)
101
106
            return True
102
107
        # FIXME: Very ugly, but kdesudo doesn't return the correct exit states
103
 
        print output
 
108
        print(output)
104
109
        if not output.startswith("Enabled the "):
105
110
            return False
106
111
        return True
111
116
               "--",
112
117
               "install", "--mode=644","--owner=0",channelpath,
113
118
               apt_pkg.Config.FindDir("Dir::Etc::sourceparts")]
114
 
        res=subprocess.call(cmd)
115
 
        if not res == 0:
 
119
        res = subprocess.call(cmd, universal_newlines=True)
 
120
        if res != 0:
116
121
            return False
117
122
        # install the key as well
118
123
        if os.path.exists(channelkey):
119
124
            cmd = ["kdesudo",
120
125
                   "--",
121
126
                   "apt-key", "add",channelkey]
122
 
            res=subprocess.call(cmd)
123
 
            if not res == 0:
 
127
            res = subprocess.call(cmd, universal_newlines=True)
 
128
            if res != 0:
124
129
                return False
125
130
        return True
126
131
 
127
132
    def askInstallPackage(self, package, summary, description, homepage):
128
133
        header = "<h2>" + _("Install additional software?") + "</h2>"
129
134
        body = _("Do you want to install package '%s'?") % package
130
 
        desc = "%s\n\n%s" % (summary, Helpers.format_description(description))
131
 
 
132
135
        self.d.header_label.setText(header)
133
136
        self.d.body_label.setText(body)
134
 
        #self.description_edit.show()
135
 
        #self.description_edit.setText(desc)
136
137
 
137
138
        self.dialog.setButtons(KDialog.ButtonCode(KDialog.Yes | KDialog.No))
138
139
 
143
144
 
144
145
    # progress etc
145
146
    def doUpdate(self):
146
 
        p = subprocess.Popen(['qapt-batch',
147
 
                              '--attach', str(self.dialog.winId()),
148
 
                              '--update'
149
 
                              ])
150
 
        self._wait_for_install_package(p)
 
147
        subprocess.check_call([
 
148
            'qapt-batch',
 
149
            '--attach', str(self.dialog.winId()),
 
150
            '--update'
 
151
            ],
 
152
            universal_newlines=True)
151
153
 
152
154
    def doInstall(self, apturl):
153
 
        p = subprocess.Popen(['qapt-batch',
154
 
                              '--attach', str(self.dialog.winId()),
155
 
                              '--install',
156
 
                              apturl.package
157
 
                              ])
158
 
        self._wait_for_install_package(p)
159
 
        return True
160
 
 
161
 
    # helpers
162
 
    def _wait_for_p(self, p, lock):
163
 
        " helper for the thread to wait for process p to finish "
164
 
        p.wait()
165
 
        lock.release()
166
 
 
167
 
    def _wait_for_install_package(self, p):
168
 
        # wait for qapt-batch
169
 
        lock = thread.allocate_lock()
170
 
        lock.acquire()
171
 
        thread.start_new_thread(self._wait_for_p, (p, lock))
172
 
 
173
 
        while lock.locked():
174
 
            time.sleep(0.01)
175
 
        return True
 
155
        subprocess.check_call([
 
156
            'qapt-batch',
 
157
            '--attach', str(self.dialog.winId()),
 
158
            '--install',
 
159
            apturl.package
 
160
            ],
 
161
            universal_newlines=True)
176
162
 
177
163
 
178
164
if __name__ == "__main__":