eric6/PipInterface/PipFileSelectionDialog.py

Wed, 17 Jun 2020 20:18:54 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 17 Jun 2020 20:18:54 +0200
changeset 7628
f904d0eef264
parent 7360
9190402e4505
child 7780
41420f82c0ac
permissions
-rw-r--r--

Checked the reported security related issue reports generated by the new security checker.

6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
3 # Copyright (c) 2015 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 Module implementing a dialog to enter a file to be processed.
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import os
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from PyQt5.QtCore import pyqtSlot
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from E5Gui.E5PathPicker import E5PathPickerModes
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from .Ui_PipFileSelectionDialog import Ui_PipFileSelectionDialog
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 import Utilities
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 class PipFileSelectionDialog(QDialog, Ui_PipFileSelectionDialog):
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Class implementing a dialog to enter a file to be processed.
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
28 def __init__(self, pip, mode, install=True, parent=None):
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 Constructor
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
32 @param pip reference to the pip object
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
33 @type Pip
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @param mode mode of the dialog
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @type str
6327
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
36 @param install flag indicating an install action
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
37 @type bool
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @param parent reference to the parent widget
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @type QWidget
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 super(PipFileSelectionDialog, self).__init__(parent)
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.setupUi(self)
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 if mode == "requirements":
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.fileLabel.setText(self.tr("Enter requirements file:"))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.filePicker.setMode(E5PathPickerModes.OpenFileMode)
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 self.filePicker.setToolTip(self.tr(
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 "Press to select the requirements file through a file"
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 " selection dialog."))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.filePicker.setFilters(
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 self.tr("Text Files (*.txt);;All Files (*)"))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 elif mode == "package":
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.fileLabel.setText(self.tr("Enter package file:"))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.filePicker.setMode(E5PathPickerModes.OpenFileMode)
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.filePicker.setToolTip(self.tr(
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 "Press to select the package file through a file"
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 " selection dialog."))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.filePicker.setFilters(
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.tr("Python Wheel (*.whl);;"
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 "Archive Files (*.tar.gz *.zip);;"
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 "All Files (*)"))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 else:
6295
79bfd24e2fee Updated translations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6294
diff changeset
63 self.fileLabel.setText(self.tr("Enter file name:"))
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 self.filePicker.setMode(E5PathPickerModes.OpenFileMode)
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.filePicker.setToolTip(self.tr(
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 "Press to select a file through a file selection dialog."))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.filePicker.setFilters(self.tr("All Files (*)"))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 self.filePicker.setDefaultDirectory(os.path.expanduser("~"))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
6327
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
72 self.userCheckBox.setVisible(install)
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
73
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 msh = self.minimumSizeHint()
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.resize(max(self.width(), msh.width()), msh.height())
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 @pyqtSlot(str)
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 def on_filePicker_textChanged(self, txt):
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 Private slot to handle entering the name of a file.
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 @param txt name of the file
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 @type str
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 bool(txt) and
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 os.path.exists(Utilities.toNativeSeparators(txt))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 )
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 def getData(self):
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 Public method to get the entered data.
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
6795
6e2ed2aac325 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6782
diff changeset
94 @return tuple with the name of the selected file and a flag indicating
6e2ed2aac325 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6782
diff changeset
95 to install to the user install directory
6e2ed2aac325 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6782
diff changeset
96 @rtype tuple of (str, bool)
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 """
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
98 return (
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
99 self.filePicker.text(),
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
100 self.userCheckBox.isChecked()
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
101 )

eric ide

mercurial