2017-09-25 99 views
0

我正在創建一個工具,該工具提供百分之一的測試結果的概述。該工具訪問日誌文件,檢查通過和失敗判決。當它失敗時,我需要回到日誌的前幾行來捕捉失敗的原因。 linecache.getline在我的工作區中工作(Python通過eclipse運行)。但是,在我創建了一個Windows安裝程序(.exe文件)並在我的計算機中安裝了該應用程序後,linecache.getline不會返回任何內容。有什麼我需要添加到我的setup.py文件來解決這個問題還是我的代碼問題?安裝我的應用程序後,Linecache getline不起作用

工具代碼

PRECON: 從wx.FileDialog,訪問日誌文件

self.result_path = dlg.GetPath() 
    try: 
     with open(self.result_path, 'r') as file: 
     self.checkLog(self.result_path, file) 

def checkLog(self, path, f): 

     line_no = 1 
     index = 0 
     for line in f: 
      n = re.search("FAIL", line, re.IGNORECASE) or re.search("PASS", line, re.IGNORECASE) 
      if n: 
       currentline = re.sub('\s+', ' ', line.rstrip()) 
       finalresult = currentline 


       self.list_ctrl.InsertStringItem(index, finaltestname) 
       self.list_ctrl.SetStringItem(index, 1, finalresult) 

       if currentline == "FAIL": 

        fail_line1 = linecache.getline(path, int(line_no - 3)) #Get reason of failure 
        fail_line2 = linecache.getline(path, int(line_no - 2)) #Get reason of failure      
        cause = fail_line1.strip() + " " + fail_line2.strip() 
        self.list_ctrl.SetStringItem(index, 2, cause) 

        index += 1 
      line_no += 1 

回答

相關問題