diff -r d792e054cde2 -r 91fa67e8ebbc CondaInterface/Conda.py --- a/CondaInterface/Conda.py Thu Feb 07 18:54:38 2019 +0100 +++ b/CondaInterface/Conda.py Sat Feb 09 16:43:49 2019 +0100 @@ -516,3 +516,70 @@ ok = False return ok + + def searchPackages(self, pattern, fullNameOnly=False, packageSpec=False, + platform="", name="", prefix=""): + """ + Public method to search for a package pattern of a conda environment. + + @param pattern package search pattern + @type str + @param fullNameOnly flag indicating to search for full names only + @type bool + @param packageSpec flag indicating to search a package specification + @type bool + @param platform type of platform to be searched for + @type str + @param name name of the environment + @type str + @param prefix prefix of the environment + @type str + @return flag indicating success and a dictionary with package name as + key and list of dictionaries containing detailed data for the found + packages as values + @rtype tuple of (bool, dict of list of dict) + @exception RuntimeError raised to indicate an error in parameters + + Note: only one of name or prefix must be given. + """ + if name and prefix: + raise RuntimeError("Only one of 'name' or 'prefix' must be given.") + + args = [ + "search", + "--json", + ] + if fullNameOnly: + args.append("--full-name") + if packageSpec: + args.append("--spec") + if platform: + args.extend(["--platform", platform]) + if name: + args.extend(["--name", name]) + elif prefix: + args.extend(["--prefix", prefix]) + args.append(pattern) + + exe = Preferences.getConda("CondaExecutable") + if not exe: + exe = "conda" + + packages = {} + ok = False + + proc = QProcess() + proc.start(exe, args) + if proc.waitForStarted(15000): + if proc.waitForFinished(30000): + output = str(proc.readAllStandardOutput(), + Preferences.getSystem("IOEncoding"), + 'replace').strip() + try: + packages = json.loads(output) + ok = "error" not in packages + except Exception: + # return values for errors is already set + pass + + return ok, packages