From 973725aa1985ca4fab62bff0afe29a8fb8f96b6d Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 26 Jun 2015 00:59:48 -0400 Subject: Initial commit of utils.py --- cbc/utils.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 cbc/utils.py (limited to 'cbc') 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 -- cgit