我有一个冗长的shell脚本,我试图将其转换为python脚本,但我被排成一行。
cat $projects_list | while read line
do
list=`find . -name "*.json" -exec grep -l "project_name.*\"$line\"" {} \; | grep -vw project`
实际上我需要的是
Project_list包含一个值列表,这些值将与键'项目名称匹配'
以下是json格式
{
"artifactory_space_MiB": 1,
"enovia": {
"name": "",
"product": "",
"release": "",
"release_notes_url": "http://example.com/ld+Release"
},
"goldmine": {
"build_type_list": [
"product",
"prodspec"
]
},
"goldmine_monitor_flag": false,
"image_list": [
{
"image": "framework-image",
"machine": "qemux86-64",
"name": "qemu"
}
],
"item_status": "inactive",
"jira": {
"key": "cdtest",
"version": "1.0"
},
"product_name": "cdtest",
"product_release": "1.0",
"project_name": "cdtest-1.0",
"testlink": {
"proj_name": "__TESTLINK_PROJ_NAME__"
},
"warios_repo_list": [],
"zone_tracking": {
"inactivation": {
"deletion_time": "2018-02-16_1516",
"inactivation_time": "2018-02-16_1516"
},
"previous_values": {
"artifactory_space_MiB": 1
}
}
}
我在下面尝试使用python ..
with open(projects_list, 'r') as f:
for line in f:
# Ignore "project" files... only interested in downstream product files.
json_list = subprocess.check_output(["find . -name '*.json' " , "-exec grep -l 'project_name.*\"" + line + "\"' {} \; " , "| grep -vw project"], shell=True)
答案 0 :(得分:0)
如果您只是尝试执行从shell脚本执行的Python脚本中的所有Unix命令,那就没有任何意义。你甚至不能在Windows中使用相同的python脚本,因为它只是执行Unix命令。当您计划将shell脚本转换为Python脚本时,首先从shell脚本执行的算法生成算法,然后在Python中实现该算法。