eric6/PipInterface/Pip.py

changeset 7626
7f643d41464e
parent 7360
9190402e4505
child 7628
f904d0eef264
--- a/eric6/PipInterface/Pip.py	Tue Jun 16 20:03:23 2020 +0200
+++ b/eric6/PipInterface/Pip.py	Wed Jun 17 17:12:21 2020 +0200
@@ -13,7 +13,7 @@
 import json
 
 from PyQt5.QtCore import pyqtSlot, QObject, QProcess, QUrl, QCoreApplication
-from PyQt5.QtWidgets import QDialog
+from PyQt5.QtWidgets import QDialog, QInputDialog, QLineEdit
 from PyQt5.QtNetwork import (
     QNetworkAccessManager, QNetworkRequest, QNetworkReply
 )
@@ -660,3 +660,96 @@
                     pass
         
         return result
+    
+    #######################################################################
+    ## Cache handling methods below
+    #######################################################################
+    
+    def showCacheInfo(self, venvName):
+        """
+        Public method to show some information about the pip cache.
+        
+        @param venvName name of the virtual environment to be used
+        @type str
+        """
+        if venvName:
+            interpreter = self.getVirtualenvInterpreter(venvName)
+            if interpreter:
+                args = ["-m", "pip", "cache", "info"]
+                dia = PipDialog(self.tr("Cache Info"))
+                res = dia.startProcess(interpreter, args, showArgs=False)
+                if res:
+                    dia.exec_()
+    
+    def cacheList(self, venvName):
+        """
+        Public method to list files contained in the pip cache.
+        
+        @param venvName name of the virtual environment to be used
+        @type str
+        """
+        if venvName:
+            interpreter = self.getVirtualenvInterpreter(venvName)
+            if interpreter:
+                pattern, ok = QInputDialog.getText(
+                    None,
+                    self.tr("List Cached Files"),
+                    self.tr("Enter a file pattern (empty for all):"),
+                    QLineEdit.Normal)
+                
+                if ok:
+                    args = ["-m", "pip", "cache", "list"]
+                    if pattern.strip():
+                        args.append(pattern.strip())
+                    dia = PipDialog(self.tr("List Cached Files"))
+                    res = dia.startProcess(interpreter, args,
+                                           showArgs=False)
+                    if res:
+                        dia.exec_()
+    
+    def cacheRemove(self, venvName):
+        """
+        Public method to remove files from the pip cache.
+        
+        @param venvName name of the virtual environment to be used
+        @type str
+        """
+        if venvName:
+            interpreter = self.getVirtualenvInterpreter(venvName)
+            if interpreter:
+                pattern, ok = QInputDialog.getText(
+                    None,
+                    self.tr("Remove Cached Files"),
+                    self.tr("Enter a file pattern:"),
+                    QLineEdit.Normal)
+                
+                if ok and pattern.strip():
+                    args = ["-m", "pip", "cache", "remove", pattern.strip()]
+                    dia = PipDialog(self.tr("Remove Cached Files"))
+                    res = dia.startProcess(interpreter, args,
+                                           showArgs=False)
+                    if res:
+                        dia.exec_()
+    
+    def cachePurge(self, venvName):
+        """
+        Public method to remove all files from the pip cache.
+        
+        @param venvName name of the virtual environment to be used
+        @type str
+        """
+        if venvName:
+            interpreter = self.getVirtualenvInterpreter(venvName)
+            if interpreter:
+                ok = E5MessageBox.yesNo(
+                    None,
+                    self.tr("Purge Cache"),
+                    self.tr("Do you really want to purge the pip cache? All"
+                            " files need to be downloaded again."))
+                if ok:
+                    args = ["-m", "pip", "cache", "purge"]
+                    dia = PipDialog(self.tr("Purge Cache"))
+                    res = dia.startProcess(interpreter, args,
+                                           showArgs=False)
+                    if res:
+                        dia.exec_()

eric ide

mercurial