Package build :: Package ec :: Module history
[hide private]
[frames] | no frames]

Source Code for Module build.ec.history

  1  #============================================================================  
  2  #Name        : history.py  
  3  #Part of     : Helium  
  4   
  5  #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
  6  #All rights reserved. 
  7  #This component and the accompanying materials are made available 
  8  #under the terms of the License "Eclipse Public License v1.0" 
  9  #which accompanies this distribution, and is available 
 10  #at the URL "http://www.eclipse.org/legal/epl-v10.html". 
 11  # 
 12  #Initial Contributors: 
 13  #Nokia Corporation - initial contribution. 
 14  # 
 15  #Contributors: 
 16  # 
 17  #Description: 
 18  #=============================================================================== 
 19   
 20  """ History file management related functionalities. """ 
 21   
 22   
 23  import sys 
 24  import os 
 25  from os.path import join 
 26   
 27   
28 -class HistoryFileManager:
29 """ To manage EC history files. """ 30 31 weak_num = "" 32 branch_name = "" 33 file_dict = {} 34
35 - def __init__(self, arg1, arg2, arg3):
36 """ Constructor. """ 37 self.path = str(arg1) 38 self.weak_num = str(arg2) 39 self.branch_name = str(arg3)
40
41 - def findActualFilePath(self):
42 """Find the new path where the history file will be updated based on the week number and branch. 43 44 This will normally the same path as used to copy from net drive to local drive. 45 But for new branch / week number, the path will be different. """ 46 branch_dir_list = self.branch_name.split(".") 47 for dir_ in branch_dir_list: 48 self.path = os.path.join(self.path, dir_) 49 if(self.path.endswith("\\0")): 50 self.path = self.path[0:-2] 51 return str(self.path)
52
53 - def findHistoryFilePath(self):
54 """ Finds the path of the history file based on input 55 branch and week number. """ 56 branch_dir_list = self.branch_name.split(".") 57 for dir_ in branch_dir_list: 58 if(not os.path.exists(os.path.join(self.path, dir_))): 59 break 60 else: 61 self.path = os.path.join(self.path, dir_) 62 if(self.path.endswith("\\0")): 63 self.path = self.path[0:-2]
64
65 - def findFile(self):
66 """ Finds the closest history file match to week number. """ 67 ret_file_name = None 68 file_names = os.listdir(self.path) 69 file_names_alone = file_names[:] 70 71 # Find the history files without sub directory 72 for name in file_names: 73 if(os.path.isdir(os.path.join(self.path, name))): 74 file_names_alone.remove(name) 75 76 if(len(file_names_alone) > 0): 77 file_names_alone.sort() 78 low_index = 0 79 high_index = len(file_names_alone) - 1 80 81 if(high_index == 0): 82 temp_name = file_names_alone[low_index] 83 if(self.weak_num >= temp_name[0:4]): 84 return temp_name 85 else: 86 return ret_file_name 87 88 # Find the matching history file using binary search 89 while(low_index < high_index): 90 mid_index = (low_index + high_index) / 2 91 temp_name = file_names_alone[mid_index] 92 if(temp_name[0:4] < self.weak_num): 93 low_index = mid_index + 1 94 else: 95 high_index = mid_index 96 97 temp_name = file_names_alone[high_index] 98 if( self.weak_num >= temp_name[0:4]): 99 ret_file_name = file_names_alone[high_index] 100 else: 101 if(high_index != 0): 102 ret_file_name = file_names_alone[high_index - 1] 103 104 return str(ret_file_name)
105