Thu, 01 Jan 2015 13:25:35 +0100
Updated copyright for 2015.
# -*- coding: utf-8 -*- # Copyright (c) 2012 - 2015 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing a dialog to select the distribution file formats. """ from __future__ import unicode_literals try: str = unicode except NameError: pass from PyQt5.QtCore import Qt, QProcess from PyQt5.QtWidgets import QDialog, QListWidgetItem from E5Gui import E5MessageBox from .Ui_DistributionTypeSelectionDialog import \ Ui_DistributionTypeSelectionDialog import Preferences 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 (ProjectPyramid.Project.Project) @param projectPath path of the Pyramid project (string) @param parent reference to the parent widget (QWidget) """ super(DistributionTypeSelectionDialog, self).__init__(parent) self.setupUi(self) errMsg = "" proc = QProcess() cmd = project.getPythonCommand() 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 pcreate executable.") if not errMsg: for line in output.splitlines(): line = line.strip() if line.startswith("--formats="): format, description = line.replace("--formats=", "")\ .split(None, 1) itm = QListWidgetItem( "{0} ({1})".format(format, description), self.formatsList) itm.setFlags(itm.flags() | Qt.ItemIsUserCheckable) itm.setCheckState(Qt.Unchecked) else: E5MessageBox.critical( None, self.tr('Process Generation Error'), errMsg) def getFormats(self): """ Public method to retrieve the checked formats. @return list of selected formats (list of string) """ formats = [] for row in range(self.formatsList.count()): itm = self.formatsList.item(row) if itm.checkState() == Qt.Checked: format = itm.text().split(None, 1)[0].strip() if format: formats.append(format) return formats