http://www.documentroot.net - Tipps, Tricks, Tutorials, Wissenswertes
20. Mai 2010

Python-Plasmoide nach KDE-Update reparieren

Quelle: http://www.documentroot.net/linux/python-plasmoide-reparieren

Nachdem ich heute ein KDE-Update auf meinem Debian (Testing) hinter mich gebracht habe, funktionieren Python-basierte Plasmoide nicht mehr. Der plasmoidviewer beschwert sich: AttributeError: ‘module’ object has no attribute ‘relpath’. Nach 2 Stunden totgeschlagener Zeit hab ich endlich ein Workaround gefunden…

Der Fehler kommt daher, dass mein KDE nicht davon abzubringen ist, Python 2.5 statt 2.6 zu verwenden (ja, ich habe die Symlinks geändert – sogar die python2.5 executable komplett entfernt). Die fehlende Funktion relpath gibts aber erst seit Python 2.6.

Das Skript, in dem der Fehler passiert, ist /usr/share/kde4/apps/plasma_scriptengine_python/pyappletscript.py. Dort kann man die fehlende Funktion direkt nachrüsten, damit das Problem (bis zum nächsten Update) vorerst aus dem Weg geschafft ist.

Nach den import-Befehlen fügt man dazu einfach folgenden Code-Schnipsel ein:

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from os.path import *
 
def relpath(path, start):
    """Workaround until python 2.6 is called by plasmoidviewer"""
 
    if not path:
        raise ValueError("no path specified")
    start_list = abspath(start).split(sep)
    path_list = abspath(path).split(sep)
    if start_list[0].lower() != path_list[0].lower():
        unc_path, rest = splitunc(path)
        unc_start, rest = splitunc(start)
        if bool(unc_path) ^ bool(unc_start):
            raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)"
                                                                % (path, start))
        else:
            raise ValueError("path is on drive %s, start on drive %s"
                                                % (path_list[0], start_list[0]))
    # Work out how much of the filepath is shared by start and path.
    for i in range(min(len(start_list), len(path_list))):
        if start_list[i].lower() != path_list[i].lower():
            break
    else:
        i += 1
 
    rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
    if not rel_list:
        return curdir
    return join(*rel_list)
 
os.path.relpath = relpath

(Der Code ist aus dem Python 2.6 Modul geklaut und leicht modifiziert, um die Namespaces kompatibel zu halten)

Nach dem Ändern der Datei war bei mir ein Neustart nötig, damit KDE die Änderung bemerkt hat.

Ich weiß, es ist nicht schön, aber Hauptsache, es tut wieder.
Falls jemand eine saubere Lösung für dieses Problem kennt, ich wäre sehr dankbar dafür.

Linux , , , , , , ,