Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(726)

Side by Side Diff: grit/gather/chrome_scaled_image.py

Issue 1194063002: grit: Add fallback_to_default_layout attribute to <output> (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | grit/node/io.py » ('j') | grit/node/io.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 '''Gatherer for <structure type="chrome_scaled_image">. 6 '''Gatherer for <structure type="chrome_scaled_image">.
7 ''' 7 '''
8 8
9 import os 9 import os
10 import struct 10 import struct
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 def _FindInputFile(self): 93 def _FindInputFile(self):
94 output_context = self.grd_node.GetRoot().output_context 94 output_context = self.grd_node.GetRoot().output_context
95 match = self.split_context_re_.match(output_context) 95 match = self.split_context_re_.match(output_context)
96 if not match: 96 if not match:
97 raise exception.MissingMandatoryAttribute( 97 raise exception.MissingMandatoryAttribute(
98 'All <output> nodes must have an appropriate context attribute' 98 'All <output> nodes must have an appropriate context attribute'
99 ' (e.g. context="touch_200_percent")') 99 ' (e.g. context="touch_200_percent")')
100 req_layout, req_scale = match.group(1), int(match.group(2)) 100 req_layout, req_scale = match.group(1), int(match.group(2))
101 101
102 layouts = [req_layout] 102 layouts = [req_layout]
103 try_default_layout = True
104 allow_empty_path = False
flackr 2015/06/19 19:42:13 I think the evaluation of this could be condensed
tdanderson 2015/06/22 23:33:20 Done.
105 if self.grd_node.GetRoot().fallback_to_default_layout == 'false': # awkward
106 try_default_layout = False
107
103 if 'default' not in layouts: 108 if 'default' not in layouts:
104 layouts.append('default') 109 if try_default_layout:
flackr 2015/06/19 19:42:13 No need for else, so merge with above, i.e.: if 'd
tdanderson 2015/06/22 23:33:20 Done.
110 layouts.append('default')
111 else:
112 allow_empty_path = True
113 # Terry - raise exception for 'elif not try_default_layout' ?
114
115 # TODO(tdanderson): Search in descending order of all image scales
116 # instead of immediately falling back to 100. crbug.com/x
105 scales = [req_scale] 117 scales = [req_scale]
106 try_low_res = self.grd_node.FindBooleanAttribute( 118 try_low_res = self.grd_node.FindBooleanAttribute(
107 'fallback_to_low_resolution', default=False, skip_self=False) 119 'fallback_to_low_resolution', default=False, skip_self=False)
108 if try_low_res and 100 not in scales: 120 if try_low_res and 100 not in scales:
109 scales.append(100) 121 scales.append(100)
122
110 for layout in layouts: 123 for layout in layouts:
111 for scale in scales: 124 for scale in scales:
112 dir = '%s_%s_percent' % (layout, scale) 125 dir = '%s_%s_percent' % (layout, scale)
113 path = os.path.join(dir, self.rc_file) 126 path = os.path.join(dir, self.rc_file)
114 if os.path.exists(self.grd_node.ToRealPath(path)): 127 if os.path.exists(self.grd_node.ToRealPath(path)):
115 return path, scale, req_scale 128 return path, scale, req_scale
116 # If we get here then the file is missing, so fail. 129
130 # If we get here then the file is missing.
131 if allow_empty_path:
132 return None, 100, req_scale
133
134 # Raise an exception if the file is missing and we do not permit returning
135 # an empty path.
117 dir = "%s_%s_percent" % (_MakeBraceGlob(layouts), 136 dir = "%s_%s_percent" % (_MakeBraceGlob(layouts),
118 _MakeBraceGlob(map(str, scales))) 137 _MakeBraceGlob(map(str, scales)))
119 raise exception.FileNotFound( 138 raise exception.FileNotFound(
120 'Tried ' + self.grd_node.ToRealPath(os.path.join(dir, self.rc_file))) 139 'Tried ' + self.grd_node.ToRealPath(os.path.join(dir, self.rc_file)))
121 140
122 def GetInputPath(self): 141 def GetInputPath(self):
123 path, scale, req_scale = self._FindInputFile() 142 path, scale, req_scale = self._FindInputFile()
124 return path 143 return path
125 144
126 def Parse(self): 145 def Parse(self):
127 pass 146 pass
128 147
129 def GetTextualIds(self): 148 def GetTextualIds(self):
130 return [self.extkey] 149 return [self.extkey]
131 150
132 def GetData(self, *args): 151 def GetData(self, *args):
133 path, scale, req_scale = self._FindInputFile() 152 path, scale, req_scale = self._FindInputFile()
153 if path is None:
154 return None
155
134 data = util.ReadFile(self.grd_node.ToRealPath(path), util.BINARY) 156 data = util.ReadFile(self.grd_node.ToRealPath(path), util.BINARY)
135 data = _RescaleImage(data, scale, req_scale) 157 data = _RescaleImage(data, scale, req_scale)
136 data = _MoveSpecialChunksToFront(data) 158 data = _MoveSpecialChunksToFront(data)
137 return data 159 return data
138 160
139 def Translate(self, *args, **kwargs): 161 def Translate(self, *args, **kwargs):
140 return self.GetData() 162 return self.GetData()
OLDNEW
« no previous file with comments | « no previous file | grit/node/io.py » ('j') | grit/node/io.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698