def EndParsing(self): '''Called at the end of parsing.''' # TODO(joi) Rewrite this, it's extremely ugly! if len(self.mixed_content): if isinstance(self.mixed_content[0], types.StringTypes): # Remove leading and trailing chunks of pure whitespace. while (len(self.mixed_content) and isinstance(self.mixed_content[0], types.StringTypes) and self.mixed_content[0].strip() == ''): self.mixed_content = self.mixed_content[1:] # Strip leading and trailing whitespace from mixed content chunks # at front and back. if (len(self.mixed_content) and isinstance(self.mixed_content[0], types.StringTypes)): self.mixed_content[0] = self.mixed_content[0].lstrip() # Remove leading and trailing ''' (used to demarcate whitespace) if (len(self.mixed_content) and isinstance(self.mixed_content[0], types.StringTypes)): if self.mixed_content[0].startswith("'''"): self.mixed_content[0] = self.mixed_content[0][3:] if len(self.mixed_content): if isinstance(self.mixed_content[-1], types.StringTypes): # Same stuff all over again for the tail end. while (len(self.mixed_content) and isinstance(self.mixed_content[-1], types.StringTypes) and self.mixed_content[-1].strip() == ''): self.mixed_content = self.mixed_content[:-1] if (len(self.mixed_content) and isinstance(self.mixed_content[-1], types.StringTypes)): self.mixed_content[-1] = self.mixed_content[-1].rstrip() if (len(self.mixed_content) and isinstance(self.mixed_content[-1], types.StringTypes)): if self.mixed_content[-1].endswith("'''"): self.mixed_content[-1] = self.mixed_content[-1][:-3] # Check that all mandatory attributes are there. for node_mandatt in self.MandatoryAttributes(): mandatt_list = [] if node_mandatt.find('|') >= 0: mandatt_list = node_mandatt.split('|') else: mandatt_list.append(node_mandatt) mandatt_option_found = False for mandatt in mandatt_list: assert mandatt not in self.DefaultAttributes().keys() if mandatt in self.attrs: if not mandatt_option_found: mandatt_option_found = True else: raise exception.MutuallyExclusiveMandatoryAttribute(mandatt) if not mandatt_option_found: raise exception.MissingMandatoryAttribute(mandatt) # Add default attributes if not specified in input file. for defattr in self.DefaultAttributes(): if not defattr in self.attrs: self.attrs[defattr] = self.DefaultAttributes()[defattr]
def _FindInputFile(self): output_context = self.grd_node.GetRoot().output_context match = self.split_context_re_.match(output_context) if not match: raise exception.MissingMandatoryAttribute( 'All <output> nodes must have an appropriate context attribute' ' (e.g. context="touch_200_percent")') req_layout, req_scale = match.group(1), int(match.group(2)) layouts = [req_layout] if 'default' not in layouts: layouts.append('default') scales = [req_scale] try_low_res = self.grd_node.FindBooleanAttribute( 'fallback_to_low_resolution', default=False, skip_self=False) if try_low_res and 100 not in scales: scales.append(100) for layout in layouts: for scale in scales: dir = '%s_%s_percent' % (layout, scale) path = os.path.join(dir, self.rc_file) if os.path.exists(self.grd_node.ToRealPath(path)): return path, scale, req_scale # If we get here then the file is missing, so fail. dir = "%s_%s_percent" % (_MakeBraceGlob(layouts), _MakeBraceGlob(map(str, scales))) raise exception.FileNotFound( 'Tried ' + self.grd_node.ToRealPath(os.path.join(dir, self.rc_file)))
def _FindInputFile(self): output_context = self.grd_node.GetRoot().output_context match = self.split_context_re_.match(output_context) if not match: raise exception.MissingMandatoryAttribute( 'All <output> nodes must have an appropriate context attribute' ' (e.g. context="touch_200_percent")') req_layout, req_scale = match.group(1), int(match.group(2)) layouts = [req_layout] try_default_layout = self.grd_node.GetRoot().fallback_to_default_layout if try_default_layout and 'default' not in layouts: layouts.append('default') # TODO(tdanderson): Search in descending order of all image scales # instead of immediately falling back to 100. # See crbug.com/503643. scales = [req_scale] try_low_res = self.grd_node.FindBooleanAttribute( 'fallback_to_low_resolution', default=False, skip_self=False) if try_low_res and 100 not in scales: scales.append(100) for layout in layouts: for scale in scales: dir = '%s_%s_percent' % (layout, scale) path = os.path.join(dir, self.rc_file) if os.path.exists(self.grd_node.ToRealPath(path)): return path, scale, req_scale if not try_default_layout: # The file was not found in the specified output context and it was # explicitly indicated that the default context should not be searched # as a fallback, so return an empty path. return None, 100, req_scale # The file was found in neither the specified context nor the default # context, so raise an exception. dir = "%s_%s_percent" % (_MakeBraceGlob(layouts), _MakeBraceGlob(map(str, scales))) raise exception.FileNotFound( 'Tried ' + self.grd_node.ToRealPath(os.path.join(dir, self.rc_file)))