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
1diff --git a/lib/lp/services/doc/sprites.txt b/lib/lp/services/doc/sprites.txt
2index c2483c4..ccdfcea 100644
3--- a/lib/lp/services/doc/sprites.txt
4+++ b/lib/lp/services/doc/sprites.txt
5@@ -99,17 +99,17 @@ changes without requiring the combined image file to be recreated.
6 >>> print new_positioning_file.read()
7 /*...
8 {
9- "../images/edit.png": [
10+ "../images/add.png": [
11 0,
12- -228
13+ -114
14 ],
15 "../images/blue-bar.png": [
16 0,
17 -342
18 ],
19- "../images/add.png": [
20+ "../images/edit.png": [
21 0,
22- -114
23+ -228
24 ]
25 }
26
27diff --git a/lib/lp/services/spriteutils.py b/lib/lp/services/spriteutils.py
28index b007a05..21ccddb 100644
29--- a/lib/lp/services/spriteutils.py
30+++ b/lib/lp/services/spriteutils.py
31@@ -12,6 +12,7 @@ __all__ = [
32 'SpriteUtil',
33 ]
34
35+import json
36 import os
37 import re
38 import sys
39@@ -19,7 +20,6 @@ from textwrap import dedent
40
41 import cssutils
42 from PIL import Image
43-import simplejson
44
45
46 class SpriteUtil:
47@@ -218,18 +218,18 @@ class SpriteUtil:
48 changes to the css template without recreating the combined
49 image file.
50 """
51- fp = open(filename, 'w')
52- fp.write(self.EDIT_WARNING)
53- simplejson.dump(self.positions, fp=fp, indent=4)
54+ with open(filename, 'w') as fp:
55+ fp.write(self.EDIT_WARNING)
56+ json.dump(self.positions, fp=fp, indent=4, sort_keys=True)
57
58 def loadPositioning(self, filename):
59 """Load file with the positions of sprites in the combined image."""
60 with open(filename) as f:
61- json = f.read()
62+ text = f.read()
63 # Remove comments from the beginning of the file.
64- start = json.index('{')
65- json = json[start:]
66- self.positions = simplejson.loads(json)
67+ start = text.index('{')
68+ text = text[start:]
69+ self.positions = json.loads(text)
70
71 def saveConvertedCSS(self, css_file, combined_image_url_path):
72 """Generate new css from the template and the positioning info.

Subscribers

People subscribed via source and target branches

to status/vote changes: