2019-06-10 17:00:28 +00:00
|
|
|
import os
|
|
|
|
from subprocess import check_output
|
|
|
|
|
2020-06-20 19:15:08 +00:00
|
|
|
from furl import furl
|
|
|
|
|
2019-06-10 17:00:28 +00:00
|
|
|
|
2020-10-12 07:52:49 +00:00
|
|
|
def get_command_output(command, path=None, strip=True):
|
2019-06-10 17:00:28 +00:00
|
|
|
"""
|
|
|
|
Run a command and return its output
|
|
|
|
:raises CalledProcessError: when command execution fails
|
|
|
|
:raises UnicodeDecodeError: when output decoding fails
|
|
|
|
"""
|
|
|
|
with open(os.devnull, "wb") as devnull:
|
2020-10-12 07:52:49 +00:00
|
|
|
result = check_output(command, cwd=path, stderr=devnull).decode()
|
|
|
|
return result.strip() if strip else result
|
2020-06-20 19:15:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
def remove_user_pass_from_url(url):
|
|
|
|
# remove user / password, if we have it embedded in the git repo
|
|
|
|
url = str(url)
|
|
|
|
# noinspection PyBroadException
|
|
|
|
try:
|
|
|
|
url = furl(url).remove(username=True, password=True).tostr()
|
|
|
|
except ValueError:
|
|
|
|
# check if for any reason we have two @
|
|
|
|
# (e.g. ssh://user@abc.com@domain.com/path or ssh://user@abc.com:pass@domain.com/path)
|
|
|
|
if len(url.split('@')) >= 3:
|
|
|
|
# noinspection PyBroadException
|
|
|
|
try:
|
|
|
|
url = furl(url.replace('@', '_', 1)).remove(username=True, password=True).tostr()
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
return url
|