ProjectPyramid/DistributionTypeSelectionDialog.py

changeset 2
e691c51ab655
child 34
d20f7218d53c
equal deleted inserted replaced
1:012c492a9bd6 2:e691c51ab655
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to select the distribution file formats.
8 """
9
10 from PyQt4.QtCore import Qt, QProcess
11 from PyQt4.QtGui import QDialog, QListWidgetItem
12
13 from E5Gui import E5MessageBox
14
15 from .Ui_DistributionTypeSelectionDialog import Ui_DistributionTypeSelectionDialog
16
17 import Preferences
18
19
20 class DistributionTypeSelectionDialog(QDialog, Ui_DistributionTypeSelectionDialog):
21 """
22 Class implementing a dialog to select the distribution file formats.
23 """
24 def __init__(self, project, projectPath, parent=None):
25 """
26 Constructor
27
28 @param project reference to the project object (ProjectPyramid.Project.Project)
29 @param projectPath path of the Pyramid project (string)
30 @param parent reference to the parent widget (QWidget)
31 """
32 super().__init__(parent)
33 self.setupUi(self)
34
35 errMsg = ""
36 proc = QProcess()
37 cmd = project.getPythonCommand()
38 args = []
39 args.append("setup.py")
40 args.append("sdist")
41 args.append("--help-formats")
42 proc.setWorkingDirectory(projectPath)
43 proc.start(cmd, args)
44 procStarted = proc.waitForStarted()
45 if procStarted:
46 finished = proc.waitForFinished(30000)
47 if finished and proc.exitCode() == 0:
48 output = \
49 str(proc.readAllStandardOutput(),
50 Preferences.getSystem("IOEncoding"),
51 'replace')
52 else:
53 if not finished:
54 errMsg = self.trUtf8(
55 "The python setup.py command did not finish within 30s.")
56 else:
57 errMsg = self.trUtf8("Could not start the pcreate executable.")
58 if not errMsg:
59 for line in output.splitlines():
60 line = line.strip()
61 if line.startswith("--formats="):
62 format, description = line.replace("--formats=", "").split(None, 1)
63 itm = QListWidgetItem("{0} ({1})".format(format, description),
64 self.formatsList)
65 itm.setFlags(itm.flags() | Qt.ItemIsUserCheckable)
66 itm.setCheckState(Qt.Unchecked)
67 else:
68 E5MessageBox.critical(None,
69 self.trUtf8('Process Generation Error'),
70 errMsg)
71
72 def getFormats(self):
73 """
74 Public method to retrieve the checked formats.
75
76 @return list of selected formats (list of string)
77 """
78 formats = []
79 for row in range(self.formatsList.count()):
80 itm = self.formatsList.item(row)
81 if itm.checkState() == Qt.Checked:
82 format = itm.text().split(None, 1)[0].strip()
83 if format:
84 formats.append(format)
85
86 return formats

eric ide

mercurial