【发布时间】:2016-01-21 16:21:30
【问题描述】:
关注这个:Find out git branch creator
我制作了一个 python 脚本,它根据
的结果为我提供了一组排序好的电子邮件git for-each-ref --format='%(authoremail)%09%(refname)' | sort -k5n -k2M -k3n -k4n | grep remotes | awk -F "\t" '{ printf "%-32s %-27s %s\n", $1, $2, $3 }'
以便我可以通过电子邮件向他们发送这些是您远程分支的信息,请删除它们。
但是当我尝试将它放在 python 中时,我得到了错误
intitial = "git for-each-ref --format='%(authoremail)%09%(refname)' | sort -k5n -k2M -k3n -k4n | grep remotes | awk -F "
addTab = "\t"
printf = '{ printf "%-32s %-27s %s\n", $1, $2, $3 }'
gitCommnad = "%s%s %s " % (intitial, addTab, printf)
def _exec_git_command(command, verbose=False):
""" Function used to get data out of git commads
and errors in case of failure.
Args:
command(string): string of a git command
verbose(bool): whether to display every command
and its resulting data.
Returns:
(tuple): string of Data and error if present
"""
# converts multiple spaces to single space
command = re.sub(' +',' ',command)
pr = subprocess.Popen(command, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
msg = pr.stdout.read()
err = pr.stderr.read()
if err:
print err
if 'Could not resolve host' in err:
return
if verbose and msg:
print "Executing '%s' %s" % (command, msg)
return msg, err
print _exec_git_command(gitCommnad)
【问题讨论】:
-
你得到什么错误?
-
@AnandSKumar
SyntaxErrorawk: printf ^ grep: write error ('', 'awk: printf\nawk: ^ syntax error\ngrep: write error\n') -
来自 awk 的语法错误对吗?