Sat, 26 Apr 2014 17:11:59 +0200
Added the Python2 compatibility flag.
# -*- coding: utf-8 -*- # Copyright (c) 2012 - 2014 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 PyQt4.QtCore import Qt, QProcess from PyQt4.QtGui 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.trUtf8( "The python setup.py command did not finish within" " 30s.") else: errMsg = self.trUtf8("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.trUtf8('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