eric6/CondaInterface/Conda.py

Mon, 12 Oct 2020 19:28:42 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 12 Oct 2020 19:28:42 +0200
changeset 7781
607a6098cb44
parent 7780
41420f82c0ac
child 7923
91e843545d9a
permissions
-rw-r--r--

Performed some more code cleanup.

6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7250
diff changeset
3 # Copyright (c) 2019 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Package implementing the conda GUI logic.
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import json
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import os
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
13 from PyQt5.QtCore import pyqtSignal, QObject, QProcess, QCoreApplication
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
14 from PyQt5.QtWidgets import QDialog
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from E5Gui import E5MessageBox
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 import Globals
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 import Preferences
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
21 from . import rootPrefix, condaVersion
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
22 from .CondaExecDialog import CondaExecDialog
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 class Conda(QObject):
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Class implementing the conda GUI logic.
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
28
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
29 @signal condaEnvironmentCreated() emitted to indicate the creation of
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
30 a new environment
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
31 @signal condaEnvironmentRemoved() emitted to indicate the removal of
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
32 an environment
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
34 condaEnvironmentCreated = pyqtSignal()
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
35 condaEnvironmentRemoved = pyqtSignal()
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
36
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
37 RootName = QCoreApplication.translate("Conda", "<root>")
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
38
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 def __init__(self, parent=None):
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 Constructor
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 @param parent parent
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 @type QObject
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 super(Conda, self).__init__(parent)
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.__ui = parent
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
50 #######################################################################
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
51 ## environment related methods below
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
52 #######################################################################
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
53
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 def createCondaEnvironment(self, arguments):
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 Public method to create a conda environment.
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @param arguments list of command line arguments
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 @type list of str
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 @return tuple containing a flag indicating success, the directory of
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 the created environment (aka. prefix) and the corresponding Python
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 interpreter
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 @rtype tuple of (bool, str, str)
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 args = ["create", "--json", "--yes"] + arguments
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 dlg = CondaExecDialog("create", self.__ui)
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 dlg.start(args)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
69 dlg.exec()
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 ok, resultDict = dlg.getResult()
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 if ok:
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
73 if ("actions" in resultDict and
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
74 "PREFIX" in resultDict["actions"]):
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 prefix = resultDict["actions"]["PREFIX"]
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 elif "prefix" in resultDict:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 prefix = resultDict["prefix"]
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 elif "dst_prefix" in resultDict:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 prefix = resultDict["dst_prefix"]
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 else:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 prefix = ""
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 # determine Python executable
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 if prefix:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 pathPrefixes = [
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 prefix,
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 rootPrefix()
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 ]
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 else:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 pathPrefixes = [
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 rootPrefix()
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 ]
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 for pathPrefix in pathPrefixes:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 if Globals.isWindowsPlatform():
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 python = os.path.join(pathPrefix, "python.exe")
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 else:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 python = os.path.join(pathPrefix, "bin", "python")
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 if os.path.exists(python):
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 break
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 else:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 python = ""
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
103 self.condaEnvironmentCreated.emit()
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 return True, prefix, python
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 else:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 return False, "", ""
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 def removeCondaEnvironment(self, name="", prefix=""):
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 Public method to remove a conda environment.
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 @param name name of the environment
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 @type str
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 @param prefix prefix of the environment
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 @type str
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 @return flag indicating success
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 @rtype bool
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 @exception RuntimeError raised to indicate an error in parameters
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 Note: only one of name or prefix must be given.
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 if name and prefix:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 if not name and not prefix:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 raise RuntimeError("One of 'name' or 'prefix' must be given.")
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 args = [
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 "remove",
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 "--json",
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 "--quiet",
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 "--all",
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 ]
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 if name:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 args.extend(["--name", name])
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 elif prefix:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 args.extend(["--prefix", prefix])
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 exe = Preferences.getConda("CondaExecutable")
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 if not exe:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 exe = "conda"
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 proc = QProcess()
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 proc.start(exe, args)
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 if not proc.waitForStarted(15000):
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 E5MessageBox.critical(
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 self.__ui,
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 self.tr("conda remove"),
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 self.tr("""The conda executable could not be started."""))
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 return False
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 else:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 proc.waitForFinished(15000)
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 output = str(proc.readAllStandardOutput(),
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 Preferences.getSystem("IOEncoding"),
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 'replace').strip()
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 try:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 jsonDict = json.loads(output)
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 except Exception:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 E5MessageBox.critical(
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 self.__ui,
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 self.tr("conda remove"),
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 self.tr("""The conda executable returned invalid data."""))
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 return False
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 if "error" in jsonDict:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 E5MessageBox.critical(
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 self.__ui,
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 self.tr("conda remove"),
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 self.tr("<p>The conda executable returned an error.</p>"
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 "<p>{0}</p>").format(jsonDict["message"]))
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 return False
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
173 if jsonDict["success"]:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
174 self.condaEnvironmentRemoved.emit()
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
175
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 return jsonDict["success"]
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
177
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
178 return False
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
179
6705
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
180 def getCondaEnvironmentsList(self):
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
181 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
182 Public method to get a list of all Conda environments.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
183
6705
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
184 @return list of tuples containing the environment name and prefix
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
185 @rtype list of tuples of (str, str)
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
186 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
187 exe = Preferences.getConda("CondaExecutable")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
188 if not exe:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
189 exe = "conda"
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
190
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
191 environmentsList = []
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
192
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
193 proc = QProcess()
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
194 proc.start(exe, ["info", "--json"])
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
195 if proc.waitForStarted(15000):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
196 if proc.waitForFinished(15000):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
197 output = str(proc.readAllStandardOutput(),
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
198 Preferences.getSystem("IOEncoding"),
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
199 'replace').strip()
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
200 try:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
201 jsonDict = json.loads(output)
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
202 except Exception:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
203 jsonDict = {}
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
204
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
205 if "envs" in jsonDict:
6705
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
206 for prefix in jsonDict["envs"][:]:
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
207 if prefix == jsonDict["root_prefix"]:
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
208 if not jsonDict["root_writable"]:
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
209 # root prefix is listed but not writable
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
210 continue
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
211 name = self.RootName
6705
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
212 else:
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
213 name = os.path.basename(prefix)
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
214
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
215 environmentsList.append((name, prefix))
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
216
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
217 return environmentsList
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
218
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
219 #######################################################################
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
220 ## package related methods below
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
221 #######################################################################
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
222
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
223 def getInstalledPackages(self, name="", prefix=""):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
224 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
225 Public method to get a list of installed packages of a conda
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
226 environment.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
227
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
228 @param name name of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
229 @type str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
230 @param prefix prefix of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
231 @type str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
232 @return list of installed packages. Each entry is a tuple containing
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
233 the package name, version and build.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
234 @rtype list of tuples of (str, str, str)
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
235 @exception RuntimeError raised to indicate an error in parameters
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
236
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
237 Note: only one of name or prefix must be given.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
238 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
239 if name and prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
240 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
241
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
242 if not name and not prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
243 raise RuntimeError("One of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
244
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
245 args = [
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
246 "list",
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
247 "--json",
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
248 ]
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
249 if name:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
250 args.extend(["--name", name])
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
251 elif prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
252 args.extend(["--prefix", prefix])
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
253
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
254 exe = Preferences.getConda("CondaExecutable")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
255 if not exe:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
256 exe = "conda"
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
257
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
258 packages = []
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
259
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
260 proc = QProcess()
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
261 proc.start(exe, args)
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
262 if proc.waitForStarted(15000):
6705
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
263 if proc.waitForFinished(30000):
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
264 output = str(proc.readAllStandardOutput(),
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
265 Preferences.getSystem("IOEncoding"),
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
266 'replace').strip()
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
267 try:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
268 jsonList = json.loads(output)
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
269 except Exception:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
270 jsonList = []
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
271
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
272 for package in jsonList:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
273 if isinstance(package, dict):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
274 packages.append((
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
275 package["name"],
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
276 package["version"],
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
277 package["build_string"]
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
278 ))
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
279 else:
7033
39b9e66ddbd6 Conda: fixed an issue causing package list returned by getInstalledPackages() and getUpdateablePackages() not always contain three tuple elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
280 parts = package.rsplit("-", 2)
39b9e66ddbd6 Conda: fixed an issue causing package list returned by getInstalledPackages() and getUpdateablePackages() not always contain three tuple elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
281 while len(parts) < 3:
39b9e66ddbd6 Conda: fixed an issue causing package list returned by getInstalledPackages() and getUpdateablePackages() not always contain three tuple elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
282 parts.append("")
39b9e66ddbd6 Conda: fixed an issue causing package list returned by getInstalledPackages() and getUpdateablePackages() not always contain three tuple elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
283 packages.append(tuple(parts))
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
284
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
285 return packages
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
286
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
287 def getUpdateablePackages(self, name="", prefix=""):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
288 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
289 Public method to get a list of updateable packages of a conda
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
290 environment.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
291
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
292 @param name name of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
293 @type str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
294 @param prefix prefix of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
295 @type str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
296 @return list of installed packages. Each entry is a tuple containing
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
297 the package name, version and build.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
298 @rtype list of tuples of (str, str, str)
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
299 @exception RuntimeError raised to indicate an error in parameters
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
300
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
301 Note: only one of name or prefix must be given.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
302 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
303 if name and prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
304 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
305
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
306 if not name and not prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
307 raise RuntimeError("One of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
308
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
309 args = [
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
310 "update",
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
311 "--json",
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
312 "--quiet",
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
313 "--all",
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
314 "--dry-run",
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
315 ]
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
316 if name:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
317 args.extend(["--name", name])
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
318 elif prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
319 args.extend(["--prefix", prefix])
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
320
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
321 exe = Preferences.getConda("CondaExecutable")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
322 if not exe:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
323 exe = "conda"
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
324
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
325 packages = []
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
326
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
327 proc = QProcess()
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
328 proc.start(exe, args)
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
329 if proc.waitForStarted(15000):
6705
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
330 if proc.waitForFinished(30000):
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
331 output = str(proc.readAllStandardOutput(),
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
332 Preferences.getSystem("IOEncoding"),
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
333 'replace').strip()
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
334 try:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
335 jsonDict = json.loads(output)
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
336 except Exception:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
337 jsonDict = {}
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
338
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
339 if "actions" in jsonDict and "LINK" in jsonDict["actions"]:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
340 for linkEntry in jsonDict["actions"]["LINK"]:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
341 if isinstance(linkEntry, dict):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
342 packages.append((
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
343 linkEntry["name"],
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
344 linkEntry["version"],
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
345 linkEntry["build_string"]
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
346 ))
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
347 else:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
348 package = linkEntry.split()[0]
7033
39b9e66ddbd6 Conda: fixed an issue causing package list returned by getInstalledPackages() and getUpdateablePackages() not always contain three tuple elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
349 parts = package.rsplit("-", 2)
39b9e66ddbd6 Conda: fixed an issue causing package list returned by getInstalledPackages() and getUpdateablePackages() not always contain three tuple elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
350 while len(parts) < 3:
39b9e66ddbd6 Conda: fixed an issue causing package list returned by getInstalledPackages() and getUpdateablePackages() not always contain three tuple elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
351 parts.append("")
39b9e66ddbd6 Conda: fixed an issue causing package list returned by getInstalledPackages() and getUpdateablePackages() not always contain three tuple elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
352 packages.append(tuple(parts))
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
353
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
354 return packages
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
355
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
356 def updatePackages(self, packages, name="", prefix=""):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
357 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
358 Public method to update packages of a conda environment.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
359
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
360 @param packages list of package names to be updated
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
361 @type list of str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
362 @param name name of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
363 @type str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
364 @param prefix prefix of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
365 @type str
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
366 @return flag indicating success
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
367 @rtype bool
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
368 @exception RuntimeError raised to indicate an error in parameters
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
369
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
370 Note: only one of name or prefix must be given.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
371 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
372 if name and prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
373 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
374
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
375 if not name and not prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
376 raise RuntimeError("One of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
377
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
378 if packages:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
379 args = [
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
380 "update",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
381 "--json",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
382 "--yes",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
383 ]
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
384 if name:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
385 args.extend(["--name", name])
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
386 elif prefix:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
387 args.extend(["--prefix", prefix])
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
388 args.extend(packages)
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
389
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
390 dlg = CondaExecDialog("update", self.__ui)
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
391 dlg.start(args)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
392 dlg.exec()
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
393 ok, _ = dlg.getResult()
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
394 else:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
395 ok = False
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
396
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
397 return ok
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
398
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
399 def updateAllPackages(self, name="", prefix=""):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
400 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
401 Public method to update all packages of a conda environment.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
402
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
403 @param name name of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
404 @type str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
405 @param prefix prefix of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
406 @type str
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
407 @return flag indicating success
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
408 @rtype bool
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
409 @exception RuntimeError raised to indicate an error in parameters
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
410
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
411 Note: only one of name or prefix must be given.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
412 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
413 if name and prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
414 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
415
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
416 if not name and not prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
417 raise RuntimeError("One of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
418
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
419 args = [
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
420 "update",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
421 "--json",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
422 "--yes",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
423 "--all"
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
424 ]
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
425 if name:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
426 args.extend(["--name", name])
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
427 elif prefix:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
428 args.extend(["--prefix", prefix])
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
429
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
430 dlg = CondaExecDialog("update", self.__ui)
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
431 dlg.start(args)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
432 dlg.exec()
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
433 ok, _ = dlg.getResult()
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
434
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
435 return ok
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
436
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
437 def installPackages(self, packages, name="", prefix=""):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
438 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
439 Public method to install packages into a conda environment.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
440
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
441 @param packages list of package names to be installed
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
442 @type list of str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
443 @param name name of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
444 @type str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
445 @param prefix prefix of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
446 @type str
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
447 @return flag indicating success
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
448 @rtype bool
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
449 @exception RuntimeError raised to indicate an error in parameters
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
450
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
451 Note: only one of name or prefix must be given.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
452 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
453 if name and prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
454 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
455
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
456 if not name and not prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
457 raise RuntimeError("One of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
458
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
459 if packages:
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
460 args = [
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
461 "install",
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
462 "--json",
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
463 "--yes",
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
464 ]
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
465 if name:
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
466 args.extend(["--name", name])
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
467 elif prefix:
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
468 args.extend(["--prefix", prefix])
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
469 args.extend(packages)
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
470
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
471 dlg = CondaExecDialog("install", self.__ui)
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
472 dlg.start(args)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
473 dlg.exec()
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
474 ok, _ = dlg.getResult()
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
475 else:
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
476 ok = False
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
477
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
478 return ok
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
479
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
480 def uninstallPackages(self, packages, name="", prefix=""):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
481 """
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
482 Public method to uninstall packages of a conda environment (including
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
483 all no longer needed dependencies).
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
484
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
485 @param packages list of package names to be uninstalled
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
486 @type list of str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
487 @param name name of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
488 @type str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
489 @param prefix prefix of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
490 @type str
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
491 @return flag indicating success
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
492 @rtype bool
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
493 @exception RuntimeError raised to indicate an error in parameters
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
494
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
495 Note: only one of name or prefix must be given.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
496 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
497 if name and prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
498 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
499
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
500 if not name and not prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
501 raise RuntimeError("One of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
502
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
503 if packages:
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
504 from UI.DeleteFilesConfirmationDialog import (
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
505 DeleteFilesConfirmationDialog)
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
506 dlg = DeleteFilesConfirmationDialog(
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
507 self.parent(),
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
508 self.tr("Uninstall Packages"),
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
509 self.tr(
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
510 "Do you really want to uninstall these packages and"
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
511 " their dependencies?"),
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
512 packages)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
513 if dlg.exec() == QDialog.Accepted:
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
514 args = [
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
515 "remove",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
516 "--json",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
517 "--yes",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
518 ]
6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
519 if condaVersion() >= (4, 4, 0):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
520 args.append("--prune",)
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
521 if name:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
522 args.extend(["--name", name])
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
523 elif prefix:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
524 args.extend(["--prefix", prefix])
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
525 args.extend(packages)
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
526
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
527 dlg = CondaExecDialog("remove", self.__ui)
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
528 dlg.start(args)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
529 dlg.exec()
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
530 ok, _ = dlg.getResult()
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
531 else:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
532 ok = False
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
533 else:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
534 ok = False
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
535
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
536 return ok
6712
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
537
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
538 def searchPackages(self, pattern, fullNameOnly=False, packageSpec=False,
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
539 platform="", name="", prefix=""):
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
540 """
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
541 Public method to search for a package pattern of a conda environment.
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
542
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
543 @param pattern package search pattern
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
544 @type str
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
545 @param fullNameOnly flag indicating to search for full names only
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
546 @type bool
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
547 @param packageSpec flag indicating to search a package specification
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
548 @type bool
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
549 @param platform type of platform to be searched for
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
550 @type str
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
551 @param name name of the environment
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
552 @type str
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
553 @param prefix prefix of the environment
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
554 @type str
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
555 @return flag indicating success and a dictionary with package name as
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
556 key and list of dictionaries containing detailed data for the found
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
557 packages as values
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
558 @rtype tuple of (bool, dict of list of dict)
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
559 @exception RuntimeError raised to indicate an error in parameters
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
560
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
561 Note: only one of name or prefix must be given.
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
562 """
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
563 if name and prefix:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
564 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
565
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
566 args = [
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
567 "search",
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
568 "--json",
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
569 ]
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
570 if fullNameOnly:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
571 args.append("--full-name")
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
572 if packageSpec:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
573 args.append("--spec")
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
574 if platform:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
575 args.extend(["--platform", platform])
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
576 if name:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
577 args.extend(["--name", name])
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
578 elif prefix:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
579 args.extend(["--prefix", prefix])
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
580 args.append(pattern)
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
581
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
582 exe = Preferences.getConda("CondaExecutable")
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
583 if not exe:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
584 exe = "conda"
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
585
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
586 packages = {}
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
587 ok = False
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
588
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
589 proc = QProcess()
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
590 proc.start(exe, args)
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
591 if proc.waitForStarted(15000):
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
592 if proc.waitForFinished(30000):
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
593 output = str(proc.readAllStandardOutput(),
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
594 Preferences.getSystem("IOEncoding"),
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
595 'replace').strip()
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
596 try:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
597 packages = json.loads(output)
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
598 ok = "error" not in packages
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
599 except Exception: # secok
6712
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
600 # return values for errors is already set
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
601 pass
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
602
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
603 return ok, packages
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
604
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
605 #######################################################################
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
606 ## special methods below
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
607 #######################################################################
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
608
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
609 def updateConda(self):
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
610 """
6724
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
611 Public method to update conda itself.
6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
612
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
613 @return flag indicating success
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
614 @rtype bool
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
615 """
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
616 args = [
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
617 "update",
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
618 "--json",
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
619 "--yes",
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
620 "conda"
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
621 ]
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
622
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
623 dlg = CondaExecDialog("update", self.__ui)
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
624 dlg.start(args)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
625 dlg.exec()
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
626 ok, _ = dlg.getResult()
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
627
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
628 return ok
6724
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
629
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
630 def writeDefaultConfiguration(self):
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
631 """
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
632 Public method to create a conda configuration with default values.
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
633 """
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
634 args = [
6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
635 "config",
6724
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
636 "--write-default",
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
637 "--quiet"
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
638 ]
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
639
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
640 exe = Preferences.getConda("CondaExecutable")
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
641 if not exe:
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
642 exe = "conda"
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
643
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
644 proc = QProcess()
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
645 proc.start(exe, args)
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
646 proc.waitForStarted(15000)
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
647 proc.waitForFinished(30000)
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
648
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
649 def getCondaInformation(self):
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
650 """
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
651 Public method to get a dictionary containing information about conda.
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
652
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
653 @return dictionary containing information about conda
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
654 @rtype dict
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
655 """
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
656 exe = Preferences.getConda("CondaExecutable")
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
657 if not exe:
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
658 exe = "conda"
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
659
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
660 infoDict = {}
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
661
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
662 proc = QProcess()
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
663 proc.start(exe, ["info", "--json"])
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
664 if proc.waitForStarted(15000):
6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
665 if proc.waitForFinished(30000):
6724
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
666 output = str(proc.readAllStandardOutput(),
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
667 Preferences.getSystem("IOEncoding"),
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
668 'replace').strip()
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
669 try:
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
670 infoDict = json.loads(output)
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
671 except Exception:
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
672 infoDict = {}
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
673
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
674 return infoDict
6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
675
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
676 def runProcess(self, args):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
677 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
678 Public method to execute the conda with the given arguments.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
679
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
680 The conda executable is called with the given arguments and
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
681 waited for its end.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
682
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
683 @param args list of command line arguments
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
684 @type list of str
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
685 @return tuple containing a flag indicating success and the output
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
686 of the process
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
687 @rtype tuple of (bool, str)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
688 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
689 exe = Preferences.getConda("CondaExecutable")
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
690 if not exe:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
691 exe = "conda"
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
692
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
693 process = QProcess()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
694 process.start(exe, args)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
695 procStarted = process.waitForStarted(15000)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
696 if procStarted:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
697 finished = process.waitForFinished(30000)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
698 if finished:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
699 if process.exitCode() == 0:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
700 output = str(process.readAllStandardOutput(),
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
701 Preferences.getSystem("IOEncoding"),
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
702 'replace').strip()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
703 return True, output
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
704 else:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
705 return (False,
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
706 self.tr("conda exited with an error ({0}).")
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
707 .format(process.exitCode()))
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
708 else:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
709 process.terminate()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
710 process.waitForFinished(2000)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
711 process.kill()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
712 process.waitForFinished(3000)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
713 return False, self.tr("conda did not finish within"
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
714 " 30 seconds.")
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
715
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
716 return False, self.tr("conda could not be started.")
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
717
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
718 def cleanConda(self, cleanAction):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
719 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
720 Public method to update conda itself.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
721
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
722 @param cleanAction cleaning action to be performed (must be one of
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
723 the command line parameters without '--')
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
724 @type str
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
725 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
726 args = [
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
727 "clean",
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
728 "--yes",
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
729 "--{0}".format(cleanAction),
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
730 ]
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
731
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
732 dlg = CondaExecDialog("clean", self.__ui)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
733 dlg.start(args)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
734 dlg.exec()

eric ide

mercurial