mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
Merge pull request #904 from pimutils/improve-error-msg
Fix double-use of a generator
This commit is contained in:
commit
722dace828
2 changed files with 11 additions and 9 deletions
|
|
@ -74,20 +74,21 @@ def _fetch_value(opts, key):
|
|||
return rv
|
||||
|
||||
|
||||
def _strategy_command(*command):
|
||||
def _strategy_command(*command: str):
|
||||
"""Execute a user-specified command and return its output."""
|
||||
import subprocess
|
||||
|
||||
# normalize path of every path member
|
||||
# if there is no path specified then nothing will happen
|
||||
command = map(expand_path, command)
|
||||
# Normalize path of every path member.
|
||||
# If there is no path specified then nothing will happen.
|
||||
# Makes this a list to avoid it being exhausted on the first iteration.
|
||||
expanded_command = list(map(expand_path, command))
|
||||
|
||||
try:
|
||||
stdout = subprocess.check_output(command, universal_newlines=True)
|
||||
stdout = subprocess.check_output(expanded_command, universal_newlines=True)
|
||||
return stdout.strip("\n")
|
||||
except OSError as e:
|
||||
raise exceptions.UserError(
|
||||
"Failed to execute command: {}\n{}".format(" ".join(command), str(e))
|
||||
)
|
||||
cmd = " ".join(expanded_command)
|
||||
raise exceptions.UserError(f"Failed to execute command: {cmd}\n{str(e)}")
|
||||
|
||||
|
||||
def _strategy_prompt(text):
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ SAFE_UID_CHARS = (
|
|||
_missing = object()
|
||||
|
||||
|
||||
def expand_path(p):
|
||||
def expand_path(p: str) -> str:
|
||||
"""Expand $HOME in a path and normalise slashes."""
|
||||
p = os.path.expanduser(p)
|
||||
p = os.path.normpath(p)
|
||||
return p
|
||||
|
|
|
|||
Loading…
Reference in a new issue