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

« back to all changes in this revision

Viewing changes to DistUpgrade/DistUpgradeViewKDE.py

  • Committer: Package Import Robot
  • Author(s): Colin Watson, Colin Watson, Adam Conrad, Barry Warsaw, Michael Vogt, Stéphane Graber, Steve Langasek
  • Date: 2012-06-14 00:57:42 UTC
  • Revision ID: package-import@ubuntu.com-20120614005742-2tnicupbt5io911y
Tags: 1:0.163
[ Colin Watson ]
* Isolate tests from local configuration in
  /etc/update-manager/release-upgrades.d/.
* Use Python attributes rather than GObject.get_data and GObject.set_data,
  which have been removed upstream (LP: #1009859).
* Switch default view class to Gtk3 and replace python-gobject dependency
  with python-gi.
* Port away from old-style apt.Package candidateFoo and installedFoo
  properties, preferring candidate.foo and installed.foo.  In a number of
  cases we have to check whether candidate/installed is non-None first.
* Use apt_pkg.version_compare rather than apt_pkg.VersionCompare.
* Use apt_pkg.uri_to_filename rather than apt_pkg.URItoFileName.
* Use apt_pkg.TagFile (and related new-style API) rather than
  apt_pkg.ParseTagFile.
* Use apt_pkg.PackageManager rather than apt_pkg.GetPackageManager.
* Use apt_pkg.Acquire rather than apt_pkg.GetAcquire.
* Use mark_foo/marked_foo rather than markFoo/markedFoo.
* Use apt_pkg.ActionGroup rather than apt_pkg.GetPkgActionGroup.
* Use apt_pkg.ProblemResolver rather than apt_pkg.GetPkgProblemResolver.
* Use apt_pkg.read_config_file rather than apt_pkg.ReadConfigFile.
* Use new spelling of apt_pkg.DepCache methods.
* Rename several local cache methods to PEP-8 style to avoid showing up in
  the output of /usr/share/python-apt/migrate-0.8.py.
* Use apt_pkg.size_to_str rather than apt_pkg.SizeToStr.
* Use apt_pkg.PackageManager.get_archives rather than
  apt_pkg.PackageManager.GetArchives.
* Use apt_pkg.Acquire.fetch_needed rather than
  apt_pkg.Acquire.FetchNeeded.
* Use new spelling of apt_pkg.Package/Version/Dependency methods.
* Use apt_pkg.pkgsystem_lock rather than apt_pkg.PkgSystemLock.
* Use new spelling of apt_pkg dependency parsing methods.
* Use new spelling of apt_pkg.SourceList methods.
* Bump python-apt (build-)dependency to >= 0.8.0.
* Add a scheme for excluding false positives from the pyflakes test, and
  enable it by default.
* Rearrange the OptionParser workaround from 1:0.154.5 to work with Python
  3, using gettext or ugettext as appropriate.
* Always pass bytes to hashlib.md5.update.
* Fix DistUpgradeAptCdrom to account for gzip files being opened in binary
  mode.
* Convert the last use of os.popen to subprocess.check_output, which makes
  it easier to read str rather than bytes.  (This requires Python 2.7.)
* Decode bytes read from urlopened file objects.
* UpdateManager/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
    (LP: #724687).
  - Open temporary synaptic selections file in text mode.
* Define __bool__ rather than __nonzero__ method in Python 3.
* sort(cmp=) and sorted(cmp=) no longer work in Python 3.  Use appropriate
  key= arguments instead.
* Fix ResourceWarning while reading /proc/mounts.
* Make update-manager-kde depend on psmisc, for killall.
* DistUpgrade/DistUpgradeView.py:
  - Use floor division in FuzzyTimeToStr.
* DistUpgrade/DistUpgradeViewText.py:
  - Flush stdout after printing confirmation message, since it doesn't
    have a trailing newline.
* Use the appropriate Unicode gettext methods in both Python 2 and 3, and
  drop lots of Python-3-unfriendly Unicode mangling as a result.
* DistUpgrade/DistUpgradeViewKDE.py:
  - Open the terminal log in binary mode.
* data/do-release-upgrade.8:
  - Provide a more useful NAME section.
* DistUpgrade/DistUpgradeCache.py:
  - Tolerate SyntaxError from attempting to import NvidiaDetector, until
    such time as a complete ubuntu-drivers-common Python 3 port is in the
    archive.
* Switch #! lines over to python3, apart from dist-upgrader which needs to
  stay as Python 2 for a while longer (and have some special arrangement
  for running with Python 3 for upgrades from >= quantal).
* Run tests under both Python 2 and 3.

[ Adam Conrad ]
* Merge branch from Michael Terry to drop auto-upgrade-tester
  from update-manager and move it into its own source package

[ Barry Warsaw ]
* Begin refactoring of Computer Janitor code by renaming and
  re-situating all of it to janitor/plugincore.  This will eventually be
  removed from here into its own separate branch.
* Merge the temporary Python 3 sprint branch back into trunk, and close
  the py3 sprint branch.
* Moved UpdateManager/backend and UpdateManager/UnitySupport.py to the
  python*-update-manager packages for apturl.

[ Michael Vogt ]
* UpdateManager/GtkProgress.py:
  - fix python-apt 0.8 API crash

[ Stéphane Graber ]
* Drop fdsend as it's not used and doesn't build with python3.
* Make update-manager-core a binary all packages (everything is python).
* Split update-manager-core into python-update-manager,
  python3-update-manager and update-manager-core.
* Build-depend and depend on python-apt >= 0.8.5~ as we need proper
  python3 support.

[ Steve Langasek ]
* tests/test_country_mirror.py: the test suite shouldn't fail if $LANG
  isn't set in the environment.
* update-manager is now using python3 as an interpreter, so fix these up
  to actually be python3 packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
 
50
50
import select
51
51
import gettext
52
 
from .DistUpgradeGettext import gettext as gett
53
 
 
54
 
def _(str):
55
 
    return unicode(gett(str), 'UTF-8')
56
 
 
57
 
def utf8(str):
58
 
  if isinstance(str, unicode):
59
 
      return str
60
 
  return unicode(str, 'UTF-8')
 
52
from .DistUpgradeGettext import gettext as _
 
53
from .DistUpgradeGettext import unicode_gettext
 
54
 
 
55
def utf8(s, errors="strict"):
 
56
    if isinstance(s, bytes):
 
57
        return s.decode("UTF-8", errors)
 
58
    else:
 
59
        return s
61
60
 
62
61
def loadUi(file, parent):
63
62
    if os.path.exists(file):
167
166
      #self.progressbar.set_pulse_step(0.01)
168
167
      #self.progressbar.pulse()
169
168
 
170
 
  def update(self, percent):
171
 
      #if percent > 99:
 
169
  def update(self, percent=None):
 
170
      super(KDEOpProgress, self).update(percent)
 
171
      #if self.percent > 99:
172
172
      #    self.progressbar.set_fraction(1)
173
173
      #else:
174
174
      #    self.progressbar.pulse()
175
 
      #self.progressbar.set_fraction(percent/100.0)
176
 
      self.progressbar.setValue(percent)
 
175
      #self.progressbar.set_fraction(self.percent/100.0)
 
176
      self.progressbar.setValue(self.percent)
177
177
      QApplication.processEvents()
178
178
 
179
179
  def done(self):
220
220
 
221
221
        if self.current_cps > 0:
222
222
            self.status.setText(_("Fetching file %li of %li at %sB/s") % (current_item, self.total_items, apt_pkg.size_to_str(self.current_cps)))
223
 
            self.parent.window_main.progress_text.setText("<i>" + _("About %s remaining") % unicode(FuzzyTimeToStr(self.eta), 'utf-8') + "</i>")
 
223
            self.parent.window_main.progress_text.setText("<i>" + _("About %s remaining") % FuzzyTimeToStr(self.eta) + "</i>")
224
224
        else:
225
225
            self.status.setText(_("Fetching file %li of %li") % (current_item, self.total_items))
226
226
            self.parent.window_main.progress_text.setText("  ")
242
242
        self.progress_text = parent.window_main.progress_text
243
243
        self.parent = parent
244
244
        try:
245
 
            self._terminal_log = open("/var/log/dist-upgrade/term.log","w")
 
245
            self._terminal_log = open("/var/log/dist-upgrade/term.log","wb")
246
246
        except Exception as e:
247
247
            # if something goes wrong (permission denied etc), use stdout
248
248
            logging.error("Can not open terminal log: '%s'" % e)
249
 
            self._terminal_log = sys.stdout
 
249
            if sys.version >= '3':
 
250
                self._terminal_log = sys.stdout.buffer
 
251
            else:
 
252
                self._terminal_log = sys.stdout
250
253
        # some options for dpkg to make it die less easily
251
254
        apt_pkg.config.set("DPkg::StopOnError","False")
252
255
 
280
283
        dialogue = QDialog(self.parent.window_main)
281
284
        loadUi("dialog_error.ui", dialogue)
282
285
        self.parent.translate_widget_children(dialogue)
283
 
        dialogue.label_error.setText(utf8(msg))
 
286
        dialogue.label_error.setText(msg)
284
287
        if errormsg != None:
285
 
            dialogue.textview_error.setText(utf8(errormsg))
 
288
            dialogue.textview_error.setText(errormsg)
286
289
            dialogue.textview_error.show()
287
290
        else:
288
291
            dialogue.textview_error.hide()
313
316
        # now get the diff
314
317
        if os.path.exists("/usr/bin/diff"):
315
318
          cmd = ["/usr/bin/diff", "-u", current, new]
316
 
          diff = utf8(subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0])
 
319
          diff = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
 
320
          diff = diff.decode("UTF-8", "replace")
317
321
          self.confDialogue.textview_conffile.setText(diff)
318
322
        else:
319
323
          self.confDialogue.textview_conffile.setText(_("The 'diff' command was not found"))
352
356
          #print("setting start time to %s" % self.start_time)
353
357
          self.start_time = time.time()
354
358
        self.progress.setValue(self.percent)
355
 
        self.label_status.setText(unicode(status.strip(), 'UTF-8'))
 
359
        self.label_status.setText(utf8(status.strip()))
356
360
        # start showing when we gathered some data
357
361
        if percent > 1.0:
358
362
          self.last_activity = time.time()
383
387
                if len(rlist) > 0:
384
388
                    line = os.read(self.master_fd, 255)
385
389
                    self._terminal_log.write(line)
386
 
                    self.parent.terminal_text.insertWithTermCodes(utf8(line))
 
390
                    self.parent.terminal_text.insertWithTermCodes(
 
391
                        utf8(line, errors="replace"))
387
392
                else:
388
393
                    break
389
394
            except Exception as e:
558
563
    def translate_widget(self, widget):
559
564
        if isinstance(widget, QLabel) or isinstance(widget, QPushButton):
560
565
            if str(widget.text()) == "&Cancel":
561
 
                widget.setText(unicode(gettext.dgettext("kdelibs", "&Cancel"), 'UTF-8'))
 
566
                kdelibs = gettext.translation(
 
567
                    "kdelibs", gettext.textdomain("kdelibs"), fallback=True)
 
568
                widget.setText(unicode_gettext(kdelibs, "&Cancel"))
562
569
            elif str(widget.text()) == "&Close":
563
 
                widget.setText(unicode(gettext.dgettext("kdelibs", "&Close"), 'UTF-8'))
 
570
                kdelibs = gettext.translation(
 
571
                    "kdelibs", gettext.textdomain("kdelibs"), fallback=True)
 
572
                widget.setText(unicode_gettext(kdelibs, "&Close"))
564
573
            elif str(widget.text()) != "":
565
574
                widget.setText( _(str(widget.text())).replace("_", "&") )
566
575
 
626
635
        return self._cdromProgress
627
636
 
628
637
    def update_status(self, msg):
629
 
        self.window_main.label_status.setText(utf8(msg))
 
638
        self.window_main.label_status.setText(msg)
630
639
 
631
640
    def hideStep(self, step):
632
641
        image = getattr(self.window_main,"image_step%i" % step)
682
691
        dialogue = QDialog(self.window_main)
683
692
        loadUi("dialog_error.ui", dialogue)
684
693
        self.translate_widget_children(dialogue)
685
 
        dialogue.label_error.setText(utf8(msg))
 
694
        dialogue.label_error.setText(msg)
686
695
        if extended_msg != None:
687
 
            dialogue.textview_error.setText(utf8(extended_msg))
 
696
            dialogue.textview_error.setText(extended_msg)
688
697
            dialogue.textview_error.show()
689
698
        else:
690
699
            dialogue.textview_error.hide()
706
715
        dialogue = QDialog(self.window_main)
707
716
        loadUi("dialog_error.ui", dialogue)
708
717
        self.translate_widget_children(dialogue)
709
 
        dialogue.label_error.setText(utf8(msg))
 
718
        dialogue.label_error.setText(msg)
710
719
        if extended_msg != None:
711
 
            dialogue.textview_error.setText(utf8(extended_msg))
 
720
            dialogue.textview_error.setText(extended_msg)
712
721
            dialogue.textview_error.show()
713
722
        else:
714
723
            dialogue.textview_error.hide()
733
742
        # removed (how to calc this automatically?)
734
743
        DistUpgradeView.confirmChanges(self, summary, changes, demotions, 
735
744
                                       downloadSize)
736
 
        msg = unicode(self.confirmChangesMessage, 'UTF-8')
737
745
        self.changesDialogue = QDialog(self.window_main)
738
746
        loadUi("dialog_changes.ui", self.changesDialogue)
739
747
 
758
766
            confirm = actions[1].replace("_", "")
759
767
            self.changesDialogue.button_confirm_changes.setText(confirm)
760
768
 
761
 
        summaryText = unicode("<big><b>%s</b></big>" % summary, 'UTF-8')
 
769
        summaryText = "<big><b>%s</b></big>" % summary
762
770
        self.changesDialogue.label_summary.setText(summaryText)
763
 
        self.changesDialogue.label_changes.setText(msg)
 
771
        self.changesDialogue.label_changes.setText(self.confirmChangesMessage)
764
772
        # fill in the details
765
773
        self.changesDialogue.treeview_details.clear()
766
774
        self.changesDialogue.treeview_details.setHeaderLabels(["Packages"])
792
800
        self.changesDialogue.resize(self.changesDialogue.sizeHint())
793
801
 
794
802
    def askYesNoQuestion(self, summary, msg, default='No'):
795
 
        answer = QMessageBox.question(self.window_main, unicode(summary, 'UTF-8'), unicode("<font>") + unicode(msg, 'UTF-8'), QMessageBox.Yes|QMessageBox.No, QMessageBox.No)
 
803
        answer = QMessageBox.question(self.window_main, summary, "<font>" + msg, QMessageBox.Yes|QMessageBox.No, QMessageBox.No)
796
804
        if answer == QMessageBox.Yes:
797
805
            return True
798
806
        return False
854
862
 
855
863
  cache = apt.Cache()
856
864
  for pkg in sys.argv[1:]:
857
 
    if cache[pkg].is_installed and not cache[pkg].isUpgradable: 
 
865
    if cache[pkg].is_installed and not cache[pkg].is_upgradable:
858
866
      cache[pkg].mark_delete(purge=True)
859
867
    else:
860
868
      cache[pkg].mark_install()