Skip to content

Python3 - Umzug nach Fedora 34

Python3
  • Mal kurz ein paar Notizen, fürs nächste Mal.

    VSCodium

    VSCodium installiert, lt. Anleitung Hersteller

    sudo rpm --import https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/-/raw/master/pub.gpg
    printf "[gitlab.com_paulcarroty_vscodium_repo]\nname=gitlab.com_paulcarroty_vscodium_repo\nbaseurl=https://paulcarroty.gitlab.io/vscodium-deb-rpm-repo/rpms/\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=1\ngpgkey=https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/-/raw/master/pub.gpg" |sudo tee -a /etc/yum.repos.d/vscodium.repo 
    sudo dnf install codium 
    

    Die Einstellungen habe ich übernommen. /home/frank/.vscode-oss

    PyQt5

    [frank@fedora ~]$ pip3 install PyQt5
    
    Defaulting to user installation because normal site-packages is not writeable
    
    Collecting PyQt5
    
      Downloading PyQt5-5.15.4-cp36.cp37.cp38.cp39-abi3-manylinux2014_x86_64.whl (8.3 MB)
    
         |████████████████████████████████| 8.3 MB 1.6 MB/s 
    
    Collecting PyQt5-sip<13,>=12.8
    
      Downloading PyQt5_sip-12.9.0-cp39-cp39-manylinux1_x86_64.whl (328 kB)
    
         |████████████████████████████████| 328 kB 59.0 MB/s 
    
    Collecting PyQt5-Qt5>=5.15
    
      Downloading PyQt5_Qt5-5.15.2-py3-none-manylinux2014_x86_64.whl (59.9 MB)
    
         |████████████████████████████████| 59.9 MB 65.8 MB/s 
    
    Installing collected packages: PyQt5-sip, PyQt5-Qt5, PyQt5
    
    Successfully installed PyQt5-5.15.4 PyQt5-Qt5-5.15.2 PyQt5-sip-12.9.0
    

    Noch eine andere Möglichkeit

    [frank@fedora ~]$ python -m pip install PyQt5
    
    Defaulting to user installation because normal site-packages is not writeable
    
    Requirement already satisfied: PyQt5 in ./.local/lib/python3.9/site-packages (5.15.4)
    
    Requirement already satisfied: PyQt5-Qt5>=5.15 in ./.local/lib/python3.9/site-packages (from PyQt5) (5.15.2)
    
    Requirement already satisfied: PyQt5-sip<13,>=12.8 in ./.local/lib/python3.9/site-packages (from PyQt5) (12.9.0)
    

    Danach konnte ich über die Konsole meine Tools wieder starten, aber nicht in VSCodium.

    pylint

    pip3 install pylint
    

    Danach startete das Tool auch wieder aus VSCodium.

  • Python - Frameworks

    Python3
    2
    0 Stimmen
    2 Beiträge
    76 Aufrufe
    FrankMF

    Und mal hier parken

  • Python - Match-Case Statement

    Python3
    1
    0 Stimmen
    1 Beiträge
    83 Aufrufe
    Niemand hat geantwortet
  • PyQt6 - QRegularExpressionValidator

    Python3
    1
    0 Stimmen
    1 Beiträge
    390 Aufrufe
    Niemand hat geantwortet
  • Python3 - HTML Text ausgeben

    Python3
    1
    0 Stimmen
    1 Beiträge
    120 Aufrufe
    Niemand hat geantwortet
  • Python3 - QT_QPA_PLATFORM

    Python3
    2
    0 Stimmen
    2 Beiträge
    284 Aufrufe
    FrankMF

    Nachdem ich ja mittlerweile schon lange weder auf Cinnamon bin, hatte ich nach einem Update von VSCodium wieder ein anderes Design. Ok, schauen wir rein.

    (venv) frank@frank-MS-7C37:~/restic-ui-public$ env | grep "QT" QT_ACCESSIBILITY=1 QT_QPA_PLATFORMTHEME=qt5ct

    Wenn ich das auf

    QT_QPA_PLATFORMTHEME=gnome3

    ändere, sieht es wie auf meinem Linux Mint Cinnamon Desktop aus.

  • Python3 - subprocess.run

    Python3
    2
    0 Stimmen
    2 Beiträge
    177 Aufrufe
    FrankMF

    Ich möchte das Thema noch mal ausgraben. Bin beim Recherchieren über diese Links gestolpert, die mein Interesse geweckt haben.

    Link Preview Image Python Pipes to Avoid Shells — OpenStack Security Advisories 0.0.1.dev268 documentation

    favicon

    (security.openstack.org)

    B603: subprocess_without_shell_equals_true — Bandit documentation

    favicon

    (bandit.readthedocs.io)

    Da ich aktuell nur eine Desktop Anwendung entwickle, ist das Thema Sicherheit nicht ganz so wichtig, weil wer hackt sich schon selber!? Aber, da man ja nie weiß, wie so ein Tool evt. mal benutzt wird, sollte man von Anfang an auf ein paar Dinge achten.

    Ok, schauen wir uns das mal genauer an.

    Link 1 - shell=True

    Ich kopiere mal das Beispiel aus dem Link.

    def count_lines(website): return subprocess.check_output('curl %s | wc -l' % website, shell=True)

    Ok, das Problem ist

    shell=True

    Ein Beispiel aus meinem Projekt

    result = subprocess.run(['restic', '-r', backup_data[row].repository, 'stats'], input=pass_word.pw[0], capture_output=True, text=True)

    Gesetzt wird der in meinem Beispiel nicht. Besuchen wir mal die Webseite vom subprocess.run

    https://docs.python.org/3/library/subprocess.html?highlight=subprocess run#subprocess.run

    Wenn ich das jetzt richtig verstehe,

    subprocess.run(args, *, stdin=None, input=None, stdout=None, stderr=None, capture_output=False, shell=False, cwd=None, timeout=None, check=False, encoding=None, errors=None, text=None, env=None, universal_newlines=None, **other_popen_kwargs)

    dann ist standardmäßig

    shell=False

    gesetzt. Damit ist das in meinem Projekt kein Problem.

    Link 2 - B603: subprocess_without_shell_equals_true

    Ein Tool auf gitlab.com wirft Security Warnings aus, dabei war diese. Schauen wir mal, was uns das sagen möchte.

    Python possesses many mechanisms to invoke an external executable. However, doing so may present a security issue if appropriate care is not taken to sanitize any user provided or variable input.

    Ok, es geht also um die Prüfung von Eingaben bzw. Variablen. Der Merksatz "Keine Benutzereingabe wird ungeprüft übernommen!" ist doch mit das Wichtigste, wenn man irgendwas programmiert. Nochmal mein Beispiel von oben.

    result = subprocess.run(['restic', '-r', backup_data[row].repository, 'stats'], input=pass_word.pw[0], capture_output=True, text=True)

    Ich übergebe dem Prozess einige Eingaben / Variablen.

    backup_data[row].repository pass_word.pw[0]

    Lesen wir wieder ein wenig in der Dokumentation von subprocess.run

    args is required for all calls and should be a string, or a sequence of program arguments. Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names). If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments.

    Das Wichtigste in Kürze Providing a sequence of arguments is generally preferred

    Der Aufruf von subprocess.run erwartet als erste Übergabe args

    subprocess.run(args, *, ....

    Mein Beispiel

    result = subprocess.run(['restic', '-r', backup_data[row].repository, 'stats'], ....

    Das zwischen den eckigen Klammern ist args. Laut der Anleitung ist es empfohlen, das als ein Argument zu übergeben, also so. Somit ist dafür gesorgt, das das Modul die Argumente selbst ein wenig "überwacht".

    as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names).

    Somit hätten man schon mal was für sie "Sicherheit" getan.

    args = ['restic', '-r', backup_data[row].repository, 'stats'] result = subprocess.run(args, ....

    Man sollte trotzdem auf diese beiden Variablen

    * backup_data[row].repository * pass_word.pw[0]

    ein Auge behalten. Ich denke, das habe ich in meinem Projekt eingehalten, indem ich Pfadangabe mit den Systemwerkzeugen auswählbar mache, keine Texteingaben! Passwörter und andere Bezeichnung werden mit regex auf korrekte Eingaben geprüft usw.

    Fazit

    Wieder viel gelernt und ich denke, es passt so weit alles. Bei der ganzen Spielerei, dann noch entdeckt, das ich im Code dieses Argument drin hatte.

    check=False

    Das ist aber Standard, somit kann das weg. Habe das im kompletten Projekt dann entfernt und mir fällt gerade auf, da der Code immer gleich ist, muss das jetzt eigentlich alles in eine Funktion 😉 Mal auf die ToDo-Liste drauf schreiben.

  • Python3 - QSettings

    Python3
    1
    0 Stimmen
    1 Beiträge
    141 Aufrufe
    Niemand hat geantwortet
  • Python und GUI

    Verschoben Python3
    1
    0 Stimmen
    1 Beiträge
    155 Aufrufe
    Niemand hat geantwortet