Permalink
Browse files

scripts: Refactored my json<->plist scripts

  • Loading branch information...
1 parent 72bfa51 commit 1306f966159e7ea9ab470b6fdc6797e9c66fb826 @csand committed Jan 12, 2013
Showing with 16 additions and 16 deletions.
  1. +8 −8 scripts/json2plist
  2. +8 −8 scripts/plist2json
View
@@ -3,11 +3,11 @@
import sys
import json
from plistlib import writePlist
-import StringIO
-
-json_file = open(sys.argv[1], "r").read()
-
-in_file = StringIO.StringIO(json_file)
-json_dict = json.load(in_file)
-
-writePlist(json_dict, open(sys.argv[1] + ".plist", "w"))
+from StringIO import StringIO
+
+if __name__ == '__main__':
+ filename = sys.argv[1]
+ with open(filename, 'r') as f:
+ data = json.load(StringIO(f.read()))
+ with open(filename + '.plist', 'w') as plist_file:
+ writePlist(data, plist_file)
View
@@ -3,11 +3,11 @@
import sys
import json
from plistlib import readPlist
-import StringIO
-
-plist = open(sys.argv[1], "r").read()
-
-in_file = StringIO.StringIO(plist)
-plist_dict = readPlist(in_file)
-
-open(sys.argv[1] + ".json", "w").write(json.dumps(plist_dict))
+from StringIO import StringIO
+
+if __name__ == '__main__':
+ filename = sys.argv[1]
+ with open(filename, 'r') as f:
+ data = readPlist(StringIO(f.read()))
+ with open(filename + '.json', 'w') as json_file:
+ json_file.write(json.dumps(data))

0 comments on commit 1306f96

Please sign in to comment.