Skip to content
Snippets Groups Projects
Commit a031b4f9 authored by Daniel Schulte's avatar Daniel Schulte
Browse files

Begin porting linuxparty.py away from subprocess.*

parent 3e040b3a
No related branches found
No related tags found
No related merge requests found
...@@ -3,9 +3,34 @@ ...@@ -3,9 +3,34 @@
import sys, os, io, subprocess import sys, os, io, subprocess
import json import json
from PyQt5 import QtWidgets, QtGui, QtCore import apt
from PyQt5 import QtWidgets, QtGui, QtCore, QtDBus
from collections import OrderedDict from collections import OrderedDict
cache = apt.cache.Cache()
def subprocess_wrap(what):
proc = subprocess.Popen(what, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True:
status = proc.poll()
if status is not None:
break
output = proc.stdout.readline()
if output == '' and status:
break
if output:
print(output.strip().decode('utf-8'))
rc = proc.poll()
print("Subprocess exited with status", rc)
return rc
def get_mountpoint(dev):
iface = QtDBus.QDBusInterface("org.freedesktop.UDisks2", "/org/freedesktop/UDisks2/block_devices/%s"%(dev,), "org.freedesktop.DBus.Properties", QtDBus.QDBusConnection.systemBus())
msg = iface.call("Get", "org.freedesktop.UDisks2.Filesystem", "MountPoints")
mpoint = msg.arguments()[0][0].data().decode('utf-8')[:-1]
print(mpoint)
return mpoint
class Ui_MainWindow(object): class Ui_MainWindow(object):
def setupUi(self, MainWindow): def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow") MainWindow.setObjectName("MainWindow")
...@@ -83,6 +108,8 @@ class Main(QtWidgets.QMainWindow): ...@@ -83,6 +108,8 @@ class Main(QtWidgets.QMainWindow):
pass pass
def installProcess(): def installProcess():
global pkglist
window.ui.btnl.hide() window.ui.btnl.hide()
window.ui.btnr.setText("&Finish") window.ui.btnr.setText("&Finish")
window.ui.progressBar.show() window.ui.progressBar.show()
...@@ -128,22 +155,30 @@ def checkIfRoot(): ...@@ -128,22 +155,30 @@ def checkIfRoot():
pass pass
def installPackages(strlist): def installPackages(strlist):
command=["echo", "apt-get", "install","--quiet", "-y", "--force-yes"," ".join(strlist)] global pkglist
#command=["apt-get", "install","--quiet", "-y", "--force-yes"]
#subprocess.call(command, shell=False) cache.update(sources_list='')
stdout_installPackages = subprocess.check_output(command, shell=False) cache.open(None)
print(stdout_installPackages)
for pkg in pkglist:
candidate = cache[pkg]
if not candidate.is_installed:
candidate.mark_install()
try:
cache.commit(apt.progress.text.AcquireProgress(), apt.progress.base.InstallProgress())
except Exception as ex:
print("Error during install",ex)
def mountStick(): def mountStick():
command=[basepath+"infuse_offline_repo.sh"] command=[basedir+"/infuse_offline_repo.sh"]
stdout_mountStick = subprocess.check_output(command, shell=False) subprocess_wrap(command)
print(stdout_mountStick)
def makeDoku(stringlist): def makeDoku(stringlist):
command=["echo", "./makeDoku.sh", os.path.dirname(basepath), " ".join(stringlist)] global pkglist
#command=["./makeDoku.sh", os.path.dirname(basepath), " ".join(pkglist)]
stdout_makeDoku = subprocess.check_output(command, shell=False) #command=["echo", "./makeDoku.sh", basedir, " ".join(stringlist)]
print(stdout_makeDoku) command=["./makeDoku.sh", basedir+"/", " ".join(pkglist)]
subprocess_wrap(command)
def getPackagelist(): def getPackagelist():
installList = [] installList = []
...@@ -151,6 +186,7 @@ def getPackagelist(): ...@@ -151,6 +186,7 @@ def getPackagelist():
i = 0 i = 0
while i < model.rowCount(): while i < model.rowCount():
item = model.item(i) item = model.item(i)
item.readOnly(true)
if item.isEnabled: if item.isEnabled:
if item.checkState(): if item.checkState():
installList.append(item.text()) installList.append(item.text())
...@@ -210,12 +246,12 @@ def fillTreeView(inputDataJson, treeView): ...@@ -210,12 +246,12 @@ def fillTreeView(inputDataJson, treeView):
if __name__ == '__main__': if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv) app = QtWidgets.QApplication(sys.argv)
basepath=os.path.realpath(__file__) basepath=os.path.realpath(__file__)
basedir=os.path.dirname(basepath)
checkIfRoot() checkIfRoot()
#mountStick() #mountStick()
window = Main() window = Main()
window.setWindowTitle("Linux Install Party Software Installer") window.setWindowTitle("Linux Install Party Software Installer")
with open('../offline_repo.json', 'r') as inputfile: with open(basedir+'/../offline_repo.json', 'r') as inputfile:
#with open('./test.json', 'r') as inputfile:
data=json.loads(inputfile.read(), object_pairs_hook=OrderedDict) data=json.loads(inputfile.read(), object_pairs_hook=OrderedDict)
fillTreeView(data, window.ui.treeView) fillTreeView(data, window.ui.treeView)
window.ui.btnl.clicked.connect(installProcess) window.ui.btnl.clicked.connect(installProcess)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment