gpt4 book ai didi

python - 这个 python 函数在寻找什么?

转载 作者:太空狗 更新时间:2023-10-29 12:16:00 25 4
gpt4 key购买 nike

我有一段 python,我正在用头撞墙。我不是 python 开发人员/程序员。但是,我的任务是重做此应用程序中的某些功能,但我无法弄清楚它在寻找什么。我有一个名为 support.sh 的 bash 程序。它与旧版本的功能相同,但我删除了 500 行无用代码。它收集了一堆日志和其他信息,然后我将一些目录 rsync 并通过它们进入/tmp/"$bundleName",然后创建一个 zip。

要启动该过程,需要调用一个 python 脚本,它会调用我的 bash 脚本。这是检查我的 bash 的部分,但我不知道它在寻找什么来表示我的 bash 程序已完成。一旦我知道它在寻找什么来表示我的 bash 已完成,我会将其添加到我的程序末尾以表示它已完成。

这是查找我的 bash 状态的 python:

def checkSupportBundleGenerationStatus(bundle):
try:
f=open(SUPPORT_BUNDLE_DIR + bundle + '/' + SUPPORT_BUNDLE_LOG,'r')
blog=f.read()
f.close()
except:
sendError("Invalid bundle")
log.message(cgiutil.LOG_INFO, "Log bundle generation output so far %r bytes." % len(blog))
filename=None
lines = blog.splitlines()
for l in lines:
pair = l.split(':', 1)
if len(pair) == 2 and pair[0] == 'File':
filename=pair[1].strip()
break
blog=re.sub(r'\rPreparing Files: [-\\|/]','',blog)
if filename:
dlPath=filename.replace(SUPPORT_BUNDLE_DIR,'',1)
try:
fileSize=os.stat(filename).st_size
except:
sendError('Error accesing bundle zip')
lastSlash=filename.rfind("/")
if lastSlash != -1 :
filename=filename[lastSlash+1:]
dlMessage='''<form action="%s" method="post">
<input type="hidden" name="HTTP_AUTHORIZATION" value="%s"/>
%s (%s) is ready for download. <input type="submit" value="Download">
</form>''' % (
buildGetQuery(downloadbundle=dlPath),
os.environ['HTTP_AUTHORIZATION'],
filename,
convertBytes(fileSize)
)
sendBundlePage(dlMessage,blog)
else:
sendBundlePage(WAIT_MSG,blog,buildGetQuery(checkbundle=bundle), os.environ['HTTP_AUTHORIZATION'])

谢谢!

最佳答案

循环:

for l in lines:
pair = l.split(':', 1)
if len(pair) == 2 and pair[0] == 'File':
filename=pair[1].strip()
break

查找以 File: 开头的第一行。它将 filename 设置为该前缀之后的文件名。如果找到这一行,它将执行以下代码块:

if filename:

如果找不到,它将转到:

else:
sendBundlePage(WAIT_MSG,blog,buildGetQuery(checkbundle=bundle), os.environ['HTTP_AUTHORIZATION'])

关于python - 这个 python 函数在寻找什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24563790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com