Commit e3479cd4 authored by Daniel Schulte's avatar Daniel Schulte Committed by osak buildhauer user

linuxparty.py now finds and mounts the LIPStick via DBus and UDisks2

parent 28f9989b
......@@ -4,11 +4,79 @@
import sys, os, io, subprocess
import json
import apt
from PyQt5 import QtWidgets, QtGui, QtCore, QtDBus
import dbus
import traceback
import tempfile
from PyQt5 import QtWidgets, QtGui, QtCore
from collections import OrderedDict
cache = apt.cache.Cache()
def get_devices():
devices = []
bus = dbus.SystemBus()
udisks_manager = bus.get_object("org.freedesktop.UDisks2", "/org/freedesktop/UDisks2")
manager_iface = dbus.Interface(udisks_manager, "org.freedesktop.DBus.ObjectManager")
try:
for k,v in manager_iface.GetManagedObjects().items():
drive_info = v.get("org.freedesktop.UDisks2.Block", {})
if drive_info.get("IdUsage") == "filesystem":
label = str(drive_info.get("IdLabel"))
device = bytearray(drive_info.get("Device")).replace(b"\x00",b"").decode("utf-8")
fs_info = v.get("org.freedesktop.UDisks2.Filesystem")
dbus_mpoints = fs_info.get("MountPoints")
mpoints = [bytearray(mpoint).replace(b"\x00",b"").decode("utf-8") for mpoint in dbus_mpoints]
devices.append((label, device, mpoints))
except Exception as ex:
traceback.print_exc(ex)
print("No devices found")
return devices
def mount_stick(dev):
bus = dbus.SystemBus()
udisks = bus.get_object("org.freedesktop.UDisks2", "/org/freedesktop/UDisks2/block_devices/%s"%(dev,))
iface = dbus.Interface(udisks, "org.freedesktop.UDisks2.Filesystem")
res = None
try:
res = bytearray(iface.Mount()).replace(b"\x00",b"").decode("utf-8")
except Exception as ex:
traceback.print_exc(ex)
print("Could not mount %s"%(dev,))
return res
def find_lipstick():
devices = get_devices()
stick = None
for device in devices:
if device[0].lower()=="lipstick":
stick = device
return stick
def enable_offline_repo(gui):
try_again = True
stick = None
while True:
stick = find_lipstick()
print(stick)
if stick is None or (type(stick) is tuple and len(stick[2])<=0):
choice = QtWidgets.QMessageBox.question(gui, 'LIPStick nicht gefunden!', "Möchtest du noch einmal versuchen den LIPStick zu finden?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
if choice == QtWidgets.QMessageBox.No:
try_again = False
else:
try_again = False
if not try_again:
break
if stick is None:
QtWidgets.QMessageBox.error(gui, "Kein LIPSTick gefunden", "Es wird ohne LIPStick weiter gemacht")
return
subprocess_wrap([basedir+"/liprepoctl.sh", "on", stick[2][0]])
def disable_offline_repo():
subprocess_wrap([basedir+"/liprepoctl.sh", "off"])
def subprocess_wrap(what):
proc = subprocess.Popen(what, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True:
......@@ -115,11 +183,13 @@ def installProcess():
window.ui.progressBar.show()
window.ui.progressBar.setRange(0,0)
pkglist = getPackagelistTree()
enable_offline_repo(window)
installPackages(pkglist)
#window.ui.progressBar.setRange(0,1)
#window.ui.progressBar.setValue(1)
makeDoku(pkglist)
showSuccBox()
disable_offline_repo()
def showSuccBox():
succBox = QtWidgets.QMessageBox()
......@@ -163,8 +233,7 @@ def checkIfRoot():
def installPackages(strlist):
global pkglist
cache.update(sources_list='')
cache.update()
cache.open(None)
for pkg in pkglist:
......@@ -175,7 +244,6 @@ def installPackages(strlist):
cache.commit(apt.progress.text.AcquireProgress(), apt.progress.base.InstallProgress())
except Exception as ex:
print("Error during install",ex)
def enableFirewall():
command=['ufw', 'enable']
subprocess_wrap(command)
......@@ -186,11 +254,12 @@ def mountStick():
def makeDoku(stringlist):
global pkglist
#command=["echo", "./makeDoku.sh", basedir, " ".join(stringlist)]
command=["./makeDoku.sh", basedir+"/", " ".join(pkglist)]
subprocess_wrap(command)
command=[basedir+"/makeDoku.sh", basedir+"/", " ".join(pkglist)]
subprocess_wrap(command)
def getPackagelist():
installList = []
model = window.ui.tableView.model()
......@@ -256,8 +325,7 @@ def fillTreeView(inputDataJson, treeView):
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
basepath=os.path.realpath(__file__)
basedir=os.path.dirname(basepath)
basedir=os.path.dirname(os.path.realpath(__file__))
checkIfRoot()
chooseFirewall()
mountStick()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment