Package build :: Module io
[hide private]
[frames] | no frames]

Source Code for Module build.io

  1  #============================================================================  
  2  #Name        : io.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  """ IO classes for handling build-related objects, e.g. log files. 
 21  """ 
 22   
 23  import logging 
 24  import re 
 25  import symbian.log 
 26   
 27   
 28  _logger = logging.getLogger('build.io') 
 29   
 30   
31 -class AbldLogWhatReader(symbian.log.Parser):
32 """ Reader that parses a Symbian build log and extracts abld -what sections. 33 34 This reader will return, using the iterator protocol, tuples containing: 35 * Unit name. 36 * List of binaries for that unit. 37 38 """
39 - def __init__(self, logpath):
40 symbian.log.Parser.__init__(self, open(logpath, 'r')) 41 self.__match_what = re.compile("abld(\.bat)?(\s+.*)*\s+-w(hat)?", re.I) 42 self._releasable = {} 43 self.parse()
44
45 - def __iter__(self):
46 for key in self._releasable.keys(): 47 yield (key, self._releasable[key])
48
49 - def task(self, name, cmdline, path, output):
50 """ Scans abld what build jobs to extract the list of releasable. """ 51 _logger.debug("%s, %s, %s, %s" % (name, cmdline, path, output)) 52 if self.__match_what.match(cmdline) == None: 53 return 54 55 if name not in self._releasable: 56 self._releasable[name] = [] 57 for line in output.splitlines(): 58 line = line.strip() 59 if line.startswith("\\") or line.startswith("/"): 60 self._releasable[name].append(line)
61 62
63 -class RombuildLogBinarySizeReader(object):
64 """ Reader that parses a Symbian ROM build log and extracts binary sizes. 65 66 This reader will return, using the iterator protocol, tuples containing: 67 * Binary name. 68 * Size of binary.\t(\d+) 69 """ 70 rom_binary_size_regex = re.compile(r'(\\epoc32[\w\\\.]+)\t(\d+)') 71 rofs_binary_size_regex = re.compile(r"ile '([\w\\\.]+)' size: (\w+)") 72 image_type_regex = re.compile(r'[._]([^._]+)\.log') 73
74 - def __init__(self, logpath):
75 """ Initialisation. 76 77 :param logpath: The path to the Symbian log file. 78 """ 79 self._logpath = logpath
80
81 - def __iter__(self):
82 """ Implement the iterator protocol. """ 83 loghandle = open(self._logpath, 'r') 84 85 # Find the ROM image type 86 type_match = self.image_type_regex.search(self._logpath) 87 image_type = type_match.group(1) 88 if image_type == 'rom' or image_type.startswith('rofs'): 89 # Extract the binary and size info 90 for line in loghandle: 91 if image_type == 'rom': 92 match = self.rom_binary_size_regex.match(line) 93 if match != None: 94 # Number is in decimal 95 size = int(match.group(2)) 96 yield (match.group(1), size, image_type) 97 elif image_type.startswith('rofs'): 98 match = self.rofs_binary_size_regex.search(line) 99 if match != None: 100 # Number is in hexidecimal 101 size = int(match.group(2), 16) 102 yield (match.group(1), size, image_type) 103 else: 104 _logger.error('ROM type not matched')
105