0

我只需要一些关于如何完成以下操作的输入

我有以下输入,我需要获取最新的“Depends-on”标签,然后打印它的值,下面的示例输入和输出......

输入:-

[{u'timestamp': 1361325046, u'message': u"Patch Set 1: I would prefer that you didn't submit this\n\n1) Now that this project is mapped to noship, should x-ship be set to none?\n\n2) Make sure that noship_common_HY11/22 are updated to not ship this folder. I see release/crm/noship_common_HY22:LINUX\\android\\vendor\\company\\proprietary\\wlan. This needs to be removed and wlan-noship has to be included in both HY11/22 files. \n\n3) Make a customer variant build and post results. \n\n4) Follow these guidelines for commit text. http://qwiki.company.com/quic/Git#Formatting_Commit_Messages", u'reviewer': {u'username': u'nname', u'name': u'Nagender name', u'email': u'nname@company.com'}}, {u'timestamp': 1361341193, u'message': u'Patch Set 1:\n\nThis change is being verified in lookahead for the following manifests along with other changes as detailed below:\n\n\n\n=====================================================================================\n\ngit-android.company.com/platform/manifest:jb_mr1:default.xml\n\n=====================================================================================\n\nhttps://commander.company.com/commander/pages/SimplifiedJobView/LoadComponent_run?jobId=723644\n\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n\n  o https://review-android.company.com/#change,252804\n\n\n\nPlease note that verification of all changes in this batch need to be successful before this change can be merged.\n\nPLEASE DO NOT UPLOAD A NEW PATCH SET, OR REMOVE APPROVALS UNTIL THE VERIFICATION IS COMPLETE.\n', u'reviewer': {u'username': u'lnxbuild', u'name': u'Linux Build Service Account', u'email': u'lnxbuild@localhost'}}, {u'timestamp': 1361344352, u'message': u'Patch Set 1: Fails\n\nFailed lookahead verification. You may find the results of the verification by following the link(s) below:                 If you feel this is an automation error and want it to be re-verified\nplease use https://commander.company.com/commander/runProcedure.php?procedureName=reset_failed_bit&projectName=Android_Main to reset the failed verify bit.\n\nYou may find the results of the verification by following the link(s) below:\n\nhttps://commander.company.com/commander/pages/SimplifiedJobView/LoadComponent_run?jobId=723644\n\n', u'reviewer': {u'username': u'lnxbuild', u'name': u'Linux Build Service Account', u'email': u'lnxbuild@localhost'}}, {u'timestamp': 1361477871, u'message': u'Uploaded patch set 2.', u'reviewer': {u'username': u'name', u'name': u'name', u'email': u'name@qca.company.com'}}, {u'timestamp': 1361477872, u'message': u'Patch Set 2:\n\nNew patchset patch-id matches previous patchset, but commit message has changed.', u'reviewer': {u'username': u'gituser', u'name': u'Git User Service Account', u'email': u'gituser@localhost'}}, {u'timestamp': 1361477891, u'message': u'Patch Set 2: Looks good to me, but someone else must approve\n\nYour change has passed all of the checks enforced by the android patch\nchecker.', u'reviewer': {u'username': u'checkpatch', u'name': u'Checkpatch Service Account', u'email': u'checkpatch@localhost'}}, {u'timestamp': 1361491295, u'message': u'Patch Set 2:\n\nDepends-on:254994', u'reviewer': {u'username': u'nname', u'name': u'Nagender name', u'email': u'nname@company.com'}}, {u'timestamp': 1361494370, u'message': u'Uploaded patch set 3.', u'reviewer': {u'username': u'name', u'name': u'name', u'email': u'name@qca.company.com'}}, {u'timestamp': 1361494386, u'message': u'Patch Set 3: Looks good to me, but someone else must approve\n\nYour change has passed all of the checks enforced by the android patch\nchecker.', u'reviewer': {u'username': u'checkpatch', u'name': u'Checkpatch Service Account', u'email': u'checkpatch@localhost'}}, {u'timestamp': 1361535719, u'message': u'Patch Set 3:\n\nThis change is being verified in lookahead for the following manifests along with other changes as detailed below:\n\n\n\n=====================================================================================\n\ngit-android.company.com/platform/manifest:jb_mr1:default.xml\n\n=====================================================================================\n\nhttps://commander.company.com/commander/pages/SimplifiedJobView/LoadComponent_run?jobId=733150\n\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n\n  o https://review-android.company.com/#change,252804\n\n  o https://review-android.company.com/#change,254994\n\n\n\nPlease note that verification of all changes in this batch need to be successful before this change can be merged.\n\nPLEASE DO NOT UPLOAD A NEW PATCH SET, OR REMOVE APPROVALS UNTIL THE VERIFICATION IS COMPLETE.\n', u'reviewer': {u'username': u'lnxbuild', u'name': u'Linux Build Service Account', u'email': u'lnxbuild@localhost'}}, {u'timestamp': 1361536209, u'message': u'Patch Set 3: Fails\n\nFailed lookahead verification. You may find the results of the verification by following the link(s) below:                 If you feel this is an automation error and want it to be re-verified\nplease use https://commander.company.com/commander/runProcedure.php?procedureName=reset_failed_bit&projectName=Android_Main to reset the failed verify bit.\n\nYou may find the results of the verification by following the link(s) below:\n\nhttps://commander.company.com/commander/pages/SimplifiedJobView/LoadComponent_run?jobId=733150\n\n', u'reviewer': {u'username': u'lnxbuild', u'name': u'Linux Build Service Account', u'email': u'lnxbuild@localhost'}}, {u'timestamp': 1361544517, u'message': u"Patch Set 3: I would prefer that you didn't submit this\n\n(1 inline comment)\n\n", u'reviewer': {u'username': u'name', u'name': u'Satya Durga Srinivasu Prabhala', u'email': u'a_name@company.com'}}, {u'timestamp': 1361560535, u'message': u'Uploaded patch set 4.', u'reviewer': {u'username': u'name', u'name': u'name', u'email': u'name@qca.company.com'}}, {u'timestamp': 1361560553, u'message': u'Patch Set 4: Looks good to me, but someone else must approve\n\nYour change has passed all of the checks enforced by the android patch\nchecker.', u'reviewer': {u'username': u'checkpatch', u'name': u'Checkpatch Service Account', u'email': u'checkpatch@localhost'}}, {u'timestamp': 1361565513, u'message': u'Patch Set 4: Looks good to me, but someone else must approve; Developer Build and Test Successful\n\nFixed all the comments and made a customer-variant build @\n\\\\wbit-linux1\\workspace\\name\\wbit\\LA_builds\\AU_LINUX_ANDROID_JB_MR1.04.02.00.49.041 ,please let me know if anything else is needed', u'reviewer': {u'username': u'name', u'name': u'name', u'email': u'name@qca.company.com'}}, {u'timestamp': 1361594838, u'message': u'Patch Set 4: Looks good to me, approved\n\n', u'reviewer': {u'username': u'nname', u'name': u'Nagender name', u'email': u'nname@company.com'}}, {u'timestamp': 1361833588, u'message': u'Patch Set 4:\n\nDepends-on:254994 258334', u'reviewer': {u'username': u'name', u'name': u'name', u'email': u'name@qca.company.com'}}, {u'timestamp': 1361846437, u'message': u'Patch Set 4: No code review score\n\n', u'reviewer': {u'username': u'name', u'name': u'Satya Durga Srinivasu Prabhala', u'email': u'a_name@company.com'}}, {u'timestamp': 1361922741, u'message': u'Patch Set 4:\n\nThis change is being verified in lookahead for the following manifests along with other changes as detailed below:\n\n\n\n=====================================================================================\n\ngit-android.company.com/platform/manifest:jb_2.5:default.xml\n\n=====================================================================================\n\nhttps://commander.company.com/commander/pages/SimplifiedJobView/LoadComponent_run?jobId=746359\n\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n\n  o https://review-android.company.com/#change,258334\n\n\n\n=====================================================================================\n\ngit-android.company.com/platform/manifest:jb_mr1:default.xml\n\n=====================================================================================\n\nhttps://commander.company.com/commander/pages/SimplifiedJobView/LoadComponent_run?jobId=746360\n\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n\n  o https://review-android.company.com/#change,258334\n\n  o https://review-android.company.com/#change,252804\n\n  o https://review-android.company.com/#change,254994\n\n\n\nPlease note that verification of all changes in this batch need to be successful before this change can be merged.\n\nPLEASE DO NOT UPLOAD A NEW PATCH SET, OR REMOVE APPROVALS UNTIL THE VERIFICATION IS COMPLETE.\n', u'reviewer': {u'username': u'lnxbuild', u'name': u'Linux Build Service Account', u'email': u'lnxbuild@localhost'}}, {u'timestamp': 1361923330, u'message': u'Patch Set 4: Fails\n\nFailed lookahead verification. You may find the results of the verification by following the link(s) below:                 If you feel this is an automation error and want it to be re-verified\nplease use https://commander.company.com/commander/runProcedure.php?procedureName=reset_failed_bit&projectName=Android_Main to reset the failed verify bit.\n\nYou may find the results of the verification by following the link(s) below:\n\nhttps://commander.company.com/commander/pages/SimplifiedJobView/LoadComponent_run?jobId=746360\n\n', u'reviewer': {u'username': u'lnxbuild', u'name': u'Linux Build Service Account', u'email': u'lnxbuild@localhost'}}]

输出:-

[254994 258334]

4

2 回答 2

3

不应该有那个输入;有人只是打印出 Python reprs,这是不行的。考虑使用内置json模块在进程之间进行通信。

同时,ast.literal_eval这是将其转回 Python 结构的唯一安全方法。

于 2013-02-28T01:58:30.587 回答
0

如果标签总是在消息的末尾,那么str.rpartition()可以提取它:

tag = "Depends-on:"
latest = max((d for d in data if tag in d["message"]),
             key=lambda d: d["timestamp"])
print(latest["message"].rpartition(tag)[2])

输出

254994 258334
于 2013-02-28T03:35:54.110 回答