desktop-base-openmamba/mambabase/mambabase.py

256 lines
9.2 KiB
Python
Raw Normal View History

2019-10-19 16:32:47 +02:00
#!/usr/bin/env python3
# Copyright (c) 2019 by Silvan Calarco <silvan.calarco@mambasoft.it>
# Release under the terms of the GPL version 3 license
from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5.QtCore import pyqtProperty
from PyQt5 import QtCore, QtWidgets
from PyQt5 import QtWidgets, uic
from pathlib import Path
import gettext
import subprocess
import os
import gi
gi.require_version('PackageKitGlib', '1.0')
from gi.repository import PackageKitGlib as packagekit
class InstallThread(QtCore.QThread):
parent = None
doneSignal = QtCore.pyqtSignal()
updateProgressSignal = QtCore.pyqtSignal(dict)
pkggroups = {}
def __init__(self, parent=None):
super(InstallThread, self).__init__(parent)
self.parent = parent
self.doneSignal.connect(parent.installationPage.completeChanged)
self.updateProgressSignal.connect(
parent.installationPage.updateProgressSlot)
# Load packages group db into a dict
result = subprocess.run(['/usr/libexec/mambabase-pkggroups-parser.sh'],
stdout=subprocess.PIPE)
lines = result.stdout.decode('UTF-8').splitlines()
for line in lines:
if line:
(key, val) = line.split("=")
self.pkggroups[key] = val
def run(self):
install = {}
parent = self.parent
# Disable back and next buttons
parent.installationPage.done = False
self.doneSignal.emit()
self.updateProgressSignal.emit(
{ 'value': 1, 'label': _("Starting installation...")})
# Groups
install['base'] = \
parent.selectGroupsPage.inst_base.isChecked()
install['office'] = \
parent.selectGroupsPage.inst_office.isChecked()
install['players'] = \
parent.selectGroupsPage.inst_players.isChecked()
install['multimedia_editing'] = \
parent.selectGroupsPage.inst_multimedia_editing.isChecked()
install['internet'] = \
parent.selectGroupsPage.inst_internet.isChecked()
install['graphics'] = \
parent.selectGroupsPage.inst_graphics.isChecked()
install['games'] = \
parent.selectGroupsPage.inst_games.isChecked()
install['virtualization'] = \
parent.selectGroupsPage.inst_virtualization.isChecked()
install['server'] = \
parent.selectGroupsPage.inst_server.isChecked()
install['devel'] = \
parent.selectGroupsPage.inst_devel.isChecked()
# Extra proprietary
install['nvidia'] = \
parent.selectExtraPage.inst_nvidia.isChecked()
install['fglrx'] = \
parent.selectExtraPage.inst_fglrx.isChecked()
install['fglrx_legacy'] = \
parent.selectExtraPage.inst_fglrx_legacy.isChecked()
install['broadcom_sta'] = \
parent.selectExtraPage.inst_broadcom_sta.isChecked()
install['b43'] = \
parent.selectExtraPage.inst_b43.isChecked()
install['flash'] = \
parent.selectExtraPage.inst_flash.isChecked()
install['pepperflash'] = \
parent.selectExtraPage.inst_pepperflash.isChecked()
install['msttcf'] = \
parent.selectExtraPage.inst_msttcf.isChecked()
install['codecs'] = \
parent.selectExtraPage.inst_codecs.isChecked()
install['java'] = \
parent.selectExtraPage.inst_java.isChecked()
install['skype'] = \
parent.selectExtraPage.inst_skype.isChecked()
install['spotify'] = \
parent.selectExtraPage.inst_spotify.isChecked()
install['virtualbox'] = \
parent.selectExtraPage.inst_virtualbox.isChecked()
install['widevine'] = \
parent.selectExtraPage.inst_widevine.isChecked()
# Update packages list
self.updateProgressSignal.emit({ 'value': 5,
'label': _("Updating packages list...")})
result = subprocess.run(['pkcon', 'refresh', 'force'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
if result.stdout:
self.updateProgressSignal.emit({
'details': result.stdout.decode('UTF-8')})
else:
if result.stderr:
self.updateProgressSignal.emit({
'details': result.stderr.decode('UTF-8')})
# Perform system update
self.updateProgressSignal.emit({ 'value': 10,
'label': _("Updating installed packages...")})
result = subprocess.run(['pkcon', 'update'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
if result.stdout:
self.updateProgressSignal.emit({
'details': result.stdout.decode('UTF-8')})
else:
if result.stderr:
self.updateProgressSignal.emit({
'details': result.stderr.decode('UTF-8')})
self.updateProgressSignal.emit({ 'value': 20 })
# Install requested packages
arch = os.uname()[4]
if arch == 'i686':
arch = 'i586'
elif arch[:3] == 'arm':
arch = 'arm'
client = packagekit.Client()
for inst in install:
if install[inst]:
parent.installationPage.progressLabel.setText(
_("Installing %s packages..." % inst))
for p in self.pkggroups[inst].split():
result =client.resolve(0, (p,), None,
self.packagekit_progress_cb, None)
pkgs = result.get_package_array()
for p in pkgs:
if 'installed' in p.get_data().split(':'):
break
if p.get_arch() != arch:
continue
packageid = p.get_name() + ';' + p.get_version() + ';' \
+ p.get_arch() + ';' + p.get_data()
client.install_packages(False, (packageid, ), None,
self.packagekit_progress_cb, p.get_name())
self.updateProgressSignal.emit({ 'value': 100,
'label': _("Installation finished!")})
# Enable back and next buttons
parent.installationPage.done = True
self.doneSignal.emit()
def packagekit_progress_cb(self, status, typ, data=None):
if status.get_property('package'):
self.updateProgressSignal.emit({
'label': _("Installing %s package (%s)..." %
(status.get_property('package').get_name(),
str(status.get_percentage())))})
class MambabaseWizard(QtWidgets.QWizard):
def __init__(self, parent=None):
super(MambabaseWizard, self).__init__(parent)
self.addPage(WelcomePage(self))
self.selectGroupsPage = SelectGroupsPage(self)
self.addPage(self.selectGroupsPage)
self.selectExtraPage = SelectExtraPage(self)
self.addPage(self.selectExtraPage)
self.installationPage = InstallationPage(self)
self.addPage(self.installationPage)
self.finishPage = FinishPage(self)
self.addPage(self.finishPage)
self.setWindowTitle("openmamba base network installations - openmamba.org")
self.setFixedSize(571,465)
self.currentIdChanged.connect(self.currentIdChangedSlot)
self.installThread = InstallThread(self)
def currentIdChangedSlot(self, currentId):
if currentId == 3:
self.installThread.start()
class WelcomePage(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super(WelcomePage, self).__init__(parent)
uic.loadUi('WelcomePage.ui', self)
self.show()
class SelectGroupsPage(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super(SelectGroupsPage, self).__init__(parent)
uic.loadUi('SelectGroupsPage.ui', self)
self.show()
class SelectExtraPage(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super(SelectExtraPage, self).__init__(parent)
uic.loadUi('SelectExtraPage.ui', self)
self.setCommitPage(True)
self.show()
class InstallationPage(QtWidgets.QWizardPage):
done = False
parent = None
def __init__(self, parent=None):
super(InstallationPage, self).__init__(parent)
uic.loadUi('InstallationPage.ui', self)
self.parent = parent
self.show()
def isComplete(self):
return self.done
@QtCore.pyqtSlot(dict)
def updateProgressSlot(self, dict):
if 'value' in dict:
self.progressBar.setValue(dict['value'])
if 'label' in dict:
self.progressLabel.setText(dict['label'])
if 'details' in dict:
self.progressDetails.setText(dict['details'])
class FinishPage(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super(FinishPage, self).__init__(parent)
uic.loadUi('FinishPage.ui', self)
self.show()
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
app.setWindowIcon(QtGui.QIcon("mamba-128x128.png"))
wizard = MambabaseWizard()
gettext.install('mambabase', '/usr/share/locale')
wizard.show()
sys.exit(app.exec_())