Sat, 23 Dec 2023 15:48:53 +0100
Updated copyright for 2024.
# -*- coding: utf-8 -*- # Copyright (c) 2012 - 2024 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing a dialog to select the distribution file formats. """ from PyQt6.QtCore import QProcess, Qt from PyQt6.QtWidgets import QDialog, QListWidgetItem from eric7 import Preferences from eric7.EricWidgets import EricMessageBox from .Ui_DistributionTypeSelectionDialog import Ui_DistributionTypeSelectionDialog class DistributionTypeSelectionDialog(QDialog, Ui_DistributionTypeSelectionDialog): """ Class implementing a dialog to select the distribution file formats. """ def __init__(self, project, projectPath, parent=None): """ Constructor @param project reference to the project object @type Project @param projectPath path of the Pyramid project @type str @param parent reference to the parent widget @type QWidget """ super().__init__(parent) self.setupUi(self) errMsg = "" proc = QProcess() cmd = project.getPyramidCommand( "python", virtualEnv=project.getProjectVirtualEnvironment() ) args = [] args.append("setup.py") args.append("sdist") args.append("--help-formats") proc.setWorkingDirectory(projectPath) proc.start(cmd, args) procStarted = proc.waitForStarted() if procStarted: finished = proc.waitForFinished(30000) if finished and proc.exitCode() == 0: output = str( proc.readAllStandardOutput(), Preferences.getSystem("IOEncoding"), "replace", ) else: if not finished: errMsg = self.tr( "The python setup.py command did not finish within" " 30s." ) else: errMsg = self.tr("Could not start the python executable.") if not errMsg: for line in output.splitlines(): line = line.strip() if line.startswith("--formats="): fileFormat, description = line.replace("--formats=", "").split( None, 1 ) itm = QListWidgetItem( "{0} ({1})".format(fileFormat, description), self.formatsList ) itm.setFlags(itm.flags() | Qt.ItemFlag.ItemIsUserCheckable) itm.setCheckState(Qt.CheckState.Unchecked) else: EricMessageBox.critical(None, self.tr("Process Generation Error"), errMsg) def getFormats(self): """ Public method to retrieve the checked formats. @return list of selected formats @rtype list of str """ formats = [] for row in range(self.formatsList.count()): itm = self.formatsList.item(row) if itm.checkState() == Qt.CheckState.Checked: fileFormat = itm.text().split(None, 1)[0].strip() if fileFormat: formats.append(fileFormat) return formats