Merge ~cjwatson/launchpad:sprite-positioning-sort-keys into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 575b37e3bbfb24ba535a005dde59cae79bd54852
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:sprite-positioning-sort-keys
Merge into: launchpad:master
Diff against target: 72 lines (+12/-12)
2 files modified
lib/lp/services/doc/sprites.txt (+4/-4)
lib/lp/services/spriteutils.py (+8/-8)
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+396658@code.launchpad.net

Commit message

Sort keys in sprite positioning file

To post a comment you must log in.
Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/lib/lp/services/doc/sprites.txt b/lib/lp/services/doc/sprites.txt
index c2483c4..ccdfcea 100644
--- a/lib/lp/services/doc/sprites.txt
+++ b/lib/lp/services/doc/sprites.txt
@@ -99,17 +99,17 @@ changes without requiring the combined image file to be recreated.
99 >>> print new_positioning_file.read()99 >>> print new_positioning_file.read()
100 /*...100 /*...
101 {101 {
102 "../images/edit.png": [102 "../images/add.png": [
103 0,103 0,
104 -228104 -114
105 ],105 ],
106 "../images/blue-bar.png": [106 "../images/blue-bar.png": [
107 0,107 0,
108 -342108 -342
109 ],109 ],
110 "../images/add.png": [110 "../images/edit.png": [
111 0,111 0,
112 -114112 -228
113 ]113 ]
114 }114 }
115115
diff --git a/lib/lp/services/spriteutils.py b/lib/lp/services/spriteutils.py
index b007a05..21ccddb 100644
--- a/lib/lp/services/spriteutils.py
+++ b/lib/lp/services/spriteutils.py
@@ -12,6 +12,7 @@ __all__ = [
12 'SpriteUtil',12 'SpriteUtil',
13 ]13 ]
1414
15import json
15import os16import os
16import re17import re
17import sys18import sys
@@ -19,7 +20,6 @@ from textwrap import dedent
1920
20import cssutils21import cssutils
21from PIL import Image22from PIL import Image
22import simplejson
2323
2424
25class SpriteUtil:25class SpriteUtil:
@@ -218,18 +218,18 @@ class SpriteUtil:
218 changes to the css template without recreating the combined218 changes to the css template without recreating the combined
219 image file.219 image file.
220 """220 """
221 fp = open(filename, 'w')221 with open(filename, 'w') as fp:
222 fp.write(self.EDIT_WARNING)222 fp.write(self.EDIT_WARNING)
223 simplejson.dump(self.positions, fp=fp, indent=4)223 json.dump(self.positions, fp=fp, indent=4, sort_keys=True)
224224
225 def loadPositioning(self, filename):225 def loadPositioning(self, filename):
226 """Load file with the positions of sprites in the combined image."""226 """Load file with the positions of sprites in the combined image."""
227 with open(filename) as f:227 with open(filename) as f:
228 json = f.read()228 text = f.read()
229 # Remove comments from the beginning of the file.229 # Remove comments from the beginning of the file.
230 start = json.index('{')230 start = text.index('{')
231 json = json[start:]231 text = text[start:]
232 self.positions = simplejson.loads(json)232 self.positions = json.loads(text)
233233
234 def saveConvertedCSS(self, css_file, combined_image_url_path):234 def saveConvertedCSS(self, css_file, combined_image_url_path):
235 """Generate new css from the template and the positioning info.235 """Generate new css from the template and the positioning info.

Subscribers

People subscribed via source and target branches

to status/vote changes: