diff options
Diffstat (limited to 'cbc/utils.py')
-rw-r--r-- | cbc/utils.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/cbc/utils.py b/cbc/utils.py new file mode 100644 index 0000000..096e156 --- /dev/null +++ b/cbc/utils.py @@ -0,0 +1,30 @@ +from subprocess import Popen, PIPE, check_output, CalledProcessError + + +def conda_search(pkgname): + command = ['conda', 'list', pkgname] + proc = Popen(command, stdout=PIPE) + out, _ = proc.communicate() + + for line in out.decode('utf-8').splitlines(): + if line.startswith('#'): + continue + line = line.split(); + break + + if not line: + return '' + + return '-'.join(line) + + +def conda_install(pkgname): + # Until I can figure out a good way to build with the conda API + # we'll use the CLI interface: + command = 'conda install --use-local --yes {0}'.format(pkgname).split() + try: + for line in (check_output(command).decode('utf-8').splitlines()): + print(line) + except CalledProcessError as cpe: + print('{0}\nexit={1}'.format(' '.join(cpe.cmd), cpe.returncode)) +
\ No newline at end of file |