14 import os |
14 import os |
15 import zipfile |
15 import zipfile |
16 import glob |
16 import glob |
17 |
17 |
18 from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QFile, QIODevice, QUrl, \ |
18 from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QFile, QIODevice, QUrl, \ |
19 QProcess, QPoint |
19 QProcess, QPoint, QCoreApplication |
20 from PyQt5.QtWidgets import QWidget, QDialogButtonBox, QAbstractButton, \ |
20 from PyQt5.QtWidgets import QWidget, QDialogButtonBox, QAbstractButton, \ |
21 QTreeWidgetItem, QDialog, QVBoxLayout, QMenu |
21 QTreeWidgetItem, QDialog, QVBoxLayout, QMenu |
22 from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest, \ |
22 from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest, \ |
23 QNetworkReply, QNetworkConfigurationManager |
23 QNetworkReply, QNetworkConfigurationManager |
24 |
24 |
747 |
747 |
748 def __cleanupDownloads(self): |
748 def __cleanupDownloads(self): |
749 """ |
749 """ |
750 Private slot to cleanup the plug-in downloads area. |
750 Private slot to cleanup the plug-in downloads area. |
751 """ |
751 """ |
752 downloadPath = Preferences.getPluginManager("DownloadPath") |
752 PluginRepositoryDownloadCleanup() |
753 downloads = {} # plug-in name as key, file name as value |
|
754 |
|
755 # step 1: extract plug-ins and downloaded files |
|
756 for pluginFile in os.listdir(downloadPath): |
|
757 if not os.path.isfile(os.path.join(downloadPath, pluginFile)): |
|
758 continue |
|
759 |
|
760 pluginName = pluginFile.rsplit("-", 1)[0] |
|
761 if pluginName not in downloads: |
|
762 downloads[pluginName] = [] |
|
763 downloads[pluginName].append(pluginFile) |
|
764 |
|
765 # step 2: delete old entries |
|
766 for pluginName in downloads: |
|
767 downloads[pluginName].sort() |
|
768 |
|
769 if pluginName in self.__hiddenPlugins and \ |
|
770 not Preferences.getPluginManager("KeepHidden"): |
|
771 removeFiles = downloads[pluginName] |
|
772 else: |
|
773 removeFiles = downloads[pluginName][ |
|
774 :-Preferences.getPluginManager("KeepGenerations")] |
|
775 for removeFile in removeFiles: |
|
776 try: |
|
777 os.remove(os.path.join(downloadPath, removeFile)) |
|
778 except (IOError, OSError) as err: |
|
779 E5MessageBox.critical( |
|
780 self, |
|
781 self.tr("Cleanup of Plugin Downloads"), |
|
782 self.tr("""<p>The plugin download <b>{0}</b> could""" |
|
783 """ not be deleted.</p><p>Reason: {1}</p>""") |
|
784 .format(removeFile, str(err))) |
|
785 |
753 |
786 |
754 |
787 class PluginRepositoryDialog(QDialog): |
755 class PluginRepositoryDialog(QDialog): |
788 """ |
756 """ |
789 Class for the dialog variant. |
757 Class for the dialog variant. |
871 'Ensure that it is available as <b>{0}</b>.</p>' |
839 'Ensure that it is available as <b>{0}</b>.</p>' |
872 ).format(applPath), |
840 ).format(applPath), |
873 self.tr('OK')) |
841 self.tr('OK')) |
874 |
842 |
875 self.close() |
843 self.close() |
|
844 |
|
845 |
|
846 def PluginRepositoryDownloadCleanup(quiet=False): |
|
847 """ |
|
848 Module function to clean up the plug-in downloads area. |
|
849 |
|
850 @param quiet flag indicating quiet operations |
|
851 @type bool |
|
852 """ |
|
853 downloadPath = Preferences.getPluginManager("DownloadPath") |
|
854 downloads = {} # plug-in name as key, file name as value |
|
855 |
|
856 # step 1: extract plug-ins and downloaded files |
|
857 for pluginFile in os.listdir(downloadPath): |
|
858 if not os.path.isfile(os.path.join(downloadPath, pluginFile)): |
|
859 continue |
|
860 |
|
861 pluginName = pluginFile.rsplit("-", 1)[0] |
|
862 if pluginName not in downloads: |
|
863 downloads[pluginName] = [] |
|
864 downloads[pluginName].append(pluginFile) |
|
865 |
|
866 # step 2: delete old entries |
|
867 hiddenPlugins = Preferences.getPluginManager("HiddenPlugins") |
|
868 for pluginName in downloads: |
|
869 downloads[pluginName].sort() |
|
870 |
|
871 if pluginName in hiddenPlugins and \ |
|
872 not Preferences.getPluginManager("KeepHidden"): |
|
873 removeFiles = downloads[pluginName] |
|
874 else: |
|
875 removeFiles = downloads[pluginName][ |
|
876 :-Preferences.getPluginManager("KeepGenerations")] |
|
877 for removeFile in removeFiles: |
|
878 try: |
|
879 os.remove(os.path.join(downloadPath, removeFile)) |
|
880 except (IOError, OSError) as err: |
|
881 if not quiet: |
|
882 E5MessageBox.critical( |
|
883 None, |
|
884 QCoreApplication.translate( |
|
885 "PluginRepositoryWidget", |
|
886 "Cleanup of Plugin Downloads"), |
|
887 QCoreApplication.translate( |
|
888 "PluginRepositoryWidget", |
|
889 """<p>The plugin download <b>{0}</b> could""" |
|
890 """ not be deleted.</p><p>Reason: {1}</p>""") |
|
891 .format(removeFile, str(err))) |