From 24be03241fc4de70dc99bb251f52b169d23b8fc0 Mon Sep 17 00:00:00 2001 From: Chandrasekhar Ramakrishnan <chandrasekhar.ramakrishnan@id.ethz.ch> Date: Thu, 2 Feb 2017 14:02:56 +0100 Subject: [PATCH] SSDM-4670: Implemented locate_command. --- src/python/OBis/obis/dm/data_mgmt.py | 11 +++++++---- src/python/OBis/obis/dm/data_mgmt_test.py | 6 ++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/python/OBis/obis/dm/data_mgmt.py b/src/python/OBis/obis/dm/data_mgmt.py index 41972d66bbf..f5a93879957 100644 --- a/src/python/OBis/obis/dm/data_mgmt.py +++ b/src/python/OBis/obis/dm/data_mgmt.py @@ -9,6 +9,7 @@ Module implementing data management operations. Created by Chandrasekhar Ramakrishnan on 2017-02-01. Copyright (c) 2017 Chandrasekhar Ramakrishnan. All rights reserved. """ +import subprocess import pybis import abc @@ -45,8 +46,8 @@ def complete_git_config(config): find_git = config['find_git'] if config.get('find_git') else False if find_git: - config['git_path'] = locate_path('git') - config['git_annex_path'] = locate_path('git-annex') + config['git_path'] = locate_command('git') + config['git_annex_path'] = locate_command('git-annex') def default_echo(details): @@ -54,8 +55,10 @@ def default_echo(details): print(details['message']) -def locate_path(command): - return None +def locate_command(command): + """Return a tuple of (returncode, stdout).""" + result = subprocess.run(['type', '-p', command], stdout=subprocess.PIPE) + return result.returncode, result.stdout.decode('utf-8').strip() class AbstractDataMgmt(metaclass=abc.ABCMeta): diff --git a/src/python/OBis/obis/dm/data_mgmt_test.py b/src/python/OBis/obis/dm/data_mgmt_test.py index 140278d13d1..14fa399e1ab 100644 --- a/src/python/OBis/obis/dm/data_mgmt_test.py +++ b/src/python/OBis/obis/dm/data_mgmt_test.py @@ -19,3 +19,9 @@ def test_no_git(tmpdir): assert False, "Command should have failed -- no git defined." except ValueError: pass + + +def test_locate_command(): + result = data_mgmt.locate_command("bash") + assert result[0] == 0 + assert result[1] == "/bin/bash" -- GitLab