[game-data-packager] 02/03: yaml2json: specifically work on one file at a time

Simon McVittie smcv at debian.org
Wed Sep 30 23:46:18 UTC 2015


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch master
in repository game-data-packager.

commit b35da7fb3c2b5fe55f2fa3c3d1cf024a2913edcd
Author: Simon McVittie <smcv at debian.org>
Date:   Thu Oct 1 00:31:13 2015 +0100

    yaml2json: specifically work on one file at a time
---
 Makefile           |  3 +--
 debian/changelog   |  1 +
 tools/yaml2json.py | 25 +++++++++++++------------
 3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/Makefile b/Makefile
index 6d27ac9..1c0eed7 100644
--- a/Makefile
+++ b/Makefile
@@ -29,8 +29,7 @@ out/%: data/%
 	if [ -L $< ]; then cp -a $< $@ ; else install -m644 $< $@ ; fi
 
 out/%.json: data/%.yaml
-	python3 tools/yaml2json.py $< > $@.tmp
-	mv $@.tmp $@
+	python3 tools/yaml2json.py $< $@
 
 out/bash_completion: $(in_yaml)
 	python3 tools/bash_completion.py > ./out/bash_completion
diff --git a/debian/changelog b/debian/changelog
index ec4485f..0963867 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -52,6 +52,7 @@ game-data-packager (43) UNRELEASED; urgency=medium
 
   [ Simon McVittie ]
   * Use debian.debian_support.Version to compare version numbers
+  * yaml2json: specifically work on one file at a time
 
  -- Simon McVittie <smcv at debian.org>  Thu, 16 Jul 2015 09:59:23 +0200
 
diff --git a/tools/yaml2json.py b/tools/yaml2json.py
index c881a3e..2a73199 100755
--- a/tools/yaml2json.py
+++ b/tools/yaml2json.py
@@ -16,21 +16,22 @@
 # /usr/share/common-licenses/GPL-2.
 
 import json
+import os
 import sys
 
 import yaml
 
-def main():
-    for f in sys.argv[1:]:
-        data = yaml.load(open(f, encoding='utf-8'), Loader=yaml.CLoader)
-        game = f[5:].split('.')[0]
-        with open('data/wikipedia.csv', 'r', encoding='utf8') as csv:
-            for line in csv.readlines():
-                shortname, url = line.strip().split(';', 1)
-                if shortname == game:
-                    data['wikipedia'] = url
-                    break
-        json.dump(data, sys.stdout, sort_keys=True)
+def main(f, out):
+    data = yaml.load(open(f, encoding='utf-8'), Loader=yaml.CLoader)
+    game = f[5:].split('.')[0]
+    with open('data/wikipedia.csv', 'r', encoding='utf8') as csv:
+        for line in csv.readlines():
+            shortname, url = line.strip().split(';', 1)
+            if shortname == game:
+                data['wikipedia'] = url
+                break
+    json.dump(data, open(out + '.tmp', 'w', encoding='utf-8'), sort_keys=True)
+    os.rename(out + '.tmp', out)
 
 if __name__ == '__main__':
-    main()
+    main(sys.argv[1], sys.argv[2])

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/game-data-packager.git



More information about the Pkg-games-commits mailing list