在我们部门,我们将文档格式改为Asciidoc(tor)。 出于自动化目的,我们希望使用从.yml文件读取的属性/变量。你知道吗
尝试子处理此属性时出现问题。使用外壳,效果完美。你知道吗
asciidoctor-pdf -a ui_host=10.10.10.10 -a ui_port=10 -a ext_host=10.11.11.11 -a ext_port=11 userman_asciidoc.adoc
解析变量.yml对python3脚本进行格式化,并将它们作为解包列表附加到subprocess.run()
调用将返回有效的asciidocpdf。但是不包括属性。你知道吗
我认为这是一个子流程问题,我做错了什么。 那么,你是怎么做到的子流程运行()是否生成与写入命令行时完全相同的输出?你知道吗
变量.yml:
ui_host: 10.10.10.10
ui_port: 10
ext_host: 10.11.11.11
ext_port: 11
海鞘_生成.py:
import yaml
import subprocess
import argparse
parser = argparse.ArgumentParser(description="This Script builds the Asciidoc usermanual for TASTE-OS as a pdf. It can take variables as input, which yould be stored in a .yml file")
parser.add_argument("adoc_file", help="Path to the usermanual as Asciidoc (.adoc) file")
parser.add_argument("yaml_file", help="The path to the yaml file, which contains all needed variables for the TASTE-OS usermanual")
args = parser.parse_args()
with open(args.yaml_file, "r") as f:
try:
yaml_content = yaml.load(f)
except yaml.YAMLError as exc:
print(exc)
yaml_variables = []
for key, value in yaml_content.items():
print(key, value)
yaml_variables.append("-a " + key + "=" + str(value))
subprocess.run(["asciidoctor-pdf", *yaml_variables, args.adoc_file])
-a
参数和实际值需要在给子进程的列表中分开。你知道吗之前:
[-a ui_host=10.10.10.10, -a ui_port=10, ...]
之后:
[-a, ui_host=10.10.10.10, -a, ui_port=10, ...]
相关问题 更多 >
编程相关推荐