165 "<p>{0}</p>").format(jsonDict["message"])) |
165 "<p>{0}</p>").format(jsonDict["message"])) |
166 return False |
166 return False |
167 |
167 |
168 return jsonDict["success"] |
168 return jsonDict["success"] |
169 |
169 |
170 def getCondaEnvironmentsList(self, listPrefixes=False): |
170 def getCondaEnvironmentsList(self): |
171 """ |
171 """ |
172 Public method to get a list of all Conda environments. |
172 Public method to get a list of all Conda environments. |
173 |
173 |
174 @param listPrefixes flag indicating to return prefixes instead of names |
174 @return list of tuples containing the environment name and prefix |
175 @type bool |
175 @rtype list of tuples of (str, str) |
176 @return list of environment names or prefixes |
176 """ |
177 @rtype list of str |
|
178 """ |
|
179 # TODO: return environment name and prefix |
|
180 # TODO: return root environment only, if writable ('root_prefix', 'root_writable') |
|
181 exe = Preferences.getConda("CondaExecutable") |
177 exe = Preferences.getConda("CondaExecutable") |
182 if not exe: |
178 if not exe: |
183 exe = "conda" |
179 exe = "conda" |
184 |
180 |
185 environmentsList = [] |
181 environmentsList = [] |
195 jsonDict = json.loads(output) |
191 jsonDict = json.loads(output) |
196 except Exception: |
192 except Exception: |
197 jsonDict = {} |
193 jsonDict = {} |
198 |
194 |
199 if "envs" in jsonDict: |
195 if "envs" in jsonDict: |
200 if listPrefixes: |
196 for prefix in jsonDict["envs"][:]: |
201 environmentsList = jsonDict["envs"][:] |
197 if prefix == jsonDict["root_prefix"]: |
202 else: |
198 if not jsonDict["root_writable"]: |
203 environmentsList = [ |
199 # root prefix is listed but not writable |
204 os.path.basename(e) for e in jsonDict["envs"]] |
200 continue |
|
201 name = self.tr("<root>") |
|
202 else: |
|
203 name = os.path.basename(prefix) |
|
204 |
|
205 environmentsList.append((name, prefix)) |
205 |
206 |
206 return environmentsList |
207 return environmentsList |
207 |
208 |
208 ####################################################################### |
209 ####################################################################### |
209 ## package related methods below |
210 ## package related methods below |
248 packages = [] |
249 packages = [] |
249 |
250 |
250 proc = QProcess() |
251 proc = QProcess() |
251 proc.start(exe, args) |
252 proc.start(exe, args) |
252 if proc.waitForStarted(15000): |
253 if proc.waitForStarted(15000): |
253 if proc.waitForFinished(15000): |
254 if proc.waitForFinished(30000): |
254 output = str(proc.readAllStandardOutput(), |
255 output = str(proc.readAllStandardOutput(), |
255 Preferences.getSystem("IOEncoding"), |
256 Preferences.getSystem("IOEncoding"), |
256 'replace').strip() |
257 'replace').strip() |
257 try: |
258 try: |
258 jsonList = json.loads(output) |
259 jsonList = json.loads(output) |
313 packages = [] |
314 packages = [] |
314 |
315 |
315 proc = QProcess() |
316 proc = QProcess() |
316 proc.start(exe, args) |
317 proc.start(exe, args) |
317 if proc.waitForStarted(15000): |
318 if proc.waitForStarted(15000): |
318 if proc.waitForFinished(15000): |
319 if proc.waitForFinished(30000): |
319 output = str(proc.readAllStandardOutput(), |
320 output = str(proc.readAllStandardOutput(), |
320 Preferences.getSystem("IOEncoding"), |
321 Preferences.getSystem("IOEncoding"), |
321 'replace').strip() |
322 'replace').strip() |
322 try: |
323 try: |
323 jsonDict = json.loads(output) |
324 jsonDict = json.loads(output) |