← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging ~cjwatson/launchpad:sprite-positioning-sort-keys into launchpad:master.

Commit message:
Sort keys in sprite positioning file

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/396658
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:sprite-positioning-sort-keys into launchpad:master.
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.
     >>> print new_positioning_file.read()
     /*...
     {
-        "../images/edit.png": [
+        "../images/add.png": [
             0,
-            -228
+            -114
         ],
         "../images/blue-bar.png": [
             0,
             -342
         ],
-        "../images/add.png": [
+        "../images/edit.png": [
             0,
-            -114
+            -228
         ]
     }
 
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__ = [
     'SpriteUtil',
     ]
 
+import json
 import os
 import re
 import sys
@@ -19,7 +20,6 @@ from textwrap import dedent
 
 import cssutils
 from PIL import Image
-import simplejson
 
 
 class SpriteUtil:
@@ -218,18 +218,18 @@ class SpriteUtil:
         changes to the css template without recreating the combined
         image file.
         """
-        fp = open(filename, 'w')
-        fp.write(self.EDIT_WARNING)
-        simplejson.dump(self.positions, fp=fp, indent=4)
+        with open(filename, 'w') as fp:
+            fp.write(self.EDIT_WARNING)
+            json.dump(self.positions, fp=fp, indent=4, sort_keys=True)
 
     def loadPositioning(self, filename):
         """Load file with the positions of sprites in the combined image."""
         with open(filename) as f:
-            json = f.read()
+            text = f.read()
         # Remove comments from the beginning of the file.
-        start = json.index('{')
-        json = json[start:]
-        self.positions = simplejson.loads(json)
+        start = text.index('{')
+        text = text[start:]
+        self.positions = json.loads(text)
 
     def saveConvertedCSS(self, css_file, combined_image_url_path):
         """Generate new css from the template and the positioning info.