Python parse File Sample _python

Source: Internet
Author: User
Tags readline

Python's most recent work is the component compatibility test, the original framework has a lot of features are not perfect, need to add! For example, you need to write the results of the AutoIt script to Excel, and the final solution is to use the local log to parse the result!

The following class is added to complete the above functions:

Copy Code code as follows:

Class Autoitresultparser ():
def parseresult (self, Vm_result, log_file):
For Case_result in Vm_result.cases_results:
Self.__modifyautoitresult (Case_result, Log_file)

def __modifyautoitresult (self, result, log_file):
Items = []
MyFile = open (Log_file, ' RB ')
line = Myfile.readline ()
Count = 0
while ("!= line"):
Items.append (Line.split (': ') [0])
Count + 1
if (count% 2 = 0):
Items.append (Line.split (': ') [1])
line = Myfile.readline ()

Myfile.close ()
Fail_scripts = []
length = len (items)
arr = List (range (2, length, 3))
For I in Arr:
Test = Items[i].lower ()
If Test.rfind (' success ') = = 1:
Fail_scripts.append ((items[i-2), items[i-1])

For script in fail_scripts:
If script[0] = = Result.case_name:
If script[1] = = ' Installation ':
Result.install_script_success = False
Elif script[1] = = ' Launch ':
Result.launch_script_success = False
Elif script[1] = = ' Function ':
Result.function_script_success = False
Else
Result.uninstall_script_success = False

The contents of the Log_file file here are similar to the following:

Copy Code code as follows:

Visualstudio2010_standaloneprofiler:
Installation:success
Visualstudio2010_standaloneprofiler:
Launch:success
Visualstudio2010_standaloneprofiler:
Function:fail
taobaobrowser_2.0.0:
citrixofflineplugin_6.5:
Installation:success
citrixofflineplugin_6.5:
Function:success
Trusteerrapport:
Tntshippingtools:
Installation:success
Tntshippingtools:
Launch:success
wget_1.11.4:
Installation:success
Visualstudio2010_standaloneprofiler:
Uninstallation:success
Tntshippingtools:
Uninstallation:fail

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.