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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | grit/node/io.py » ('j') | grit/node/io.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: grit/gather/chrome_scaled_image.py
diff --git a/grit/gather/chrome_scaled_image.py b/grit/gather/chrome_scaled_image.py
index 19777d08e959bb72e438490ff87a6e3a444a6d7d..9e590f15d57cf7eb5f962fd788da5c908bee3f17 100644
--- a/grit/gather/chrome_scaled_image.py
+++ b/grit/gather/chrome_scaled_image.py
@@ -100,20 +100,39 @@ class ChromeScaledImage(interface.GathererBase):
req_layout, req_scale = match.group(1), int(match.group(2))
layouts = [req_layout]
+ try_default_layout = True
+ 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.
+ if self.grd_node.GetRoot().fallback_to_default_layout == 'false': # awkward
+ try_default_layout = False
+
if 'default' not in layouts:
- layouts.append('default')
+ 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.
+ layouts.append('default')
+ else:
+ allow_empty_path = True
+ # Terry - raise exception for 'elif not try_default_layout' ?
+
+ # TODO(tdanderson): Search in descending order of all image scales
+ # instead of immediately falling back to 100. crbug.com/x
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.
+
+ # If we get here then the file is missing.
+ if allow_empty_path:
+ return None, 100, req_scale
+
+ # Raise an exception if the file is missing and we do not permit returning
+ # an empty path.
dir = "%s_%s_percent" % (_MakeBraceGlob(layouts),
_MakeBraceGlob(map(str, scales)))
raise exception.FileNotFound(
@@ -131,6 +150,9 @@ class ChromeScaledImage(interface.GathererBase):
def GetData(self, *args):
path, scale, req_scale = self._FindInputFile()
+ if path is None:
+ return None
+
data = util.ReadFile(self.grd_node.ToRealPath(path), util.BINARY)
data = _RescaleImage(data, scale, req_scale)
data = _MoveSpecialChunksToFront(data)
« 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