514 ok = False |
514 ok = False |
515 else: |
515 else: |
516 ok = False |
516 ok = False |
517 |
517 |
518 return ok |
518 return ok |
|
519 |
|
520 def searchPackages(self, pattern, fullNameOnly=False, packageSpec=False, |
|
521 platform="", name="", prefix=""): |
|
522 """ |
|
523 Public method to search for a package pattern of a conda environment. |
|
524 |
|
525 @param pattern package search pattern |
|
526 @type str |
|
527 @param fullNameOnly flag indicating to search for full names only |
|
528 @type bool |
|
529 @param packageSpec flag indicating to search a package specification |
|
530 @type bool |
|
531 @param platform type of platform to be searched for |
|
532 @type str |
|
533 @param name name of the environment |
|
534 @type str |
|
535 @param prefix prefix of the environment |
|
536 @type str |
|
537 @return flag indicating success and a dictionary with package name as |
|
538 key and list of dictionaries containing detailed data for the found |
|
539 packages as values |
|
540 @rtype tuple of (bool, dict of list of dict) |
|
541 @exception RuntimeError raised to indicate an error in parameters |
|
542 |
|
543 Note: only one of name or prefix must be given. |
|
544 """ |
|
545 if name and prefix: |
|
546 raise RuntimeError("Only one of 'name' or 'prefix' must be given.") |
|
547 |
|
548 args = [ |
|
549 "search", |
|
550 "--json", |
|
551 ] |
|
552 if fullNameOnly: |
|
553 args.append("--full-name") |
|
554 if packageSpec: |
|
555 args.append("--spec") |
|
556 if platform: |
|
557 args.extend(["--platform", platform]) |
|
558 if name: |
|
559 args.extend(["--name", name]) |
|
560 elif prefix: |
|
561 args.extend(["--prefix", prefix]) |
|
562 args.append(pattern) |
|
563 |
|
564 exe = Preferences.getConda("CondaExecutable") |
|
565 if not exe: |
|
566 exe = "conda" |
|
567 |
|
568 packages = {} |
|
569 ok = False |
|
570 |
|
571 proc = QProcess() |
|
572 proc.start(exe, args) |
|
573 if proc.waitForStarted(15000): |
|
574 if proc.waitForFinished(30000): |
|
575 output = str(proc.readAllStandardOutput(), |
|
576 Preferences.getSystem("IOEncoding"), |
|
577 'replace').strip() |
|
578 try: |
|
579 packages = json.loads(output) |
|
580 ok = "error" not in packages |
|
581 except Exception: |
|
582 # return values for errors is already set |
|
583 pass |
|
584 |
|
585 return ok, packages |