[game-data-packager] 10/25: make-template: fill in steam ID automatically

Simon McVittie smcv at debian.org
Wed Feb 11 10:41:12 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 75e79687450e77581ec576f63702f4f9d8fdbae4
Author: Alexandre Detiste <alexandre.detiste at gmail.com>
Date:   Mon Feb 9 17:57:25 2015 +0100

    make-template: fill in steam ID automatically
    
    to achieve this, I copied acf_parser() from
    my steam branch
---
 game_data_packager/make_template.py | 12 +++++++---
 game_data_packager/steam.py         | 45 +++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/game_data_packager/make_template.py b/game_data_packager/make_template.py
index ebc6051..c656d36 100644
--- a/game_data_packager/make_template.py
+++ b/game_data_packager/make_template.py
@@ -26,6 +26,7 @@ from debian.deb822 import Deb822
 import yaml
 
 from . import HashedFile
+from .steam import parse_acf
 
 logging.basicConfig()
 logger = logging.getLogger('game_data_packager.make-template')
@@ -52,7 +53,12 @@ def do_one_dir(destdir,lower):
                 destdir.find('/steamapps/common/'))
     if steam > 0:
           steam_dict = dict()
-          steam_dict['id'] = 'FIXME'
+          steam_id = 'FIXME'
+          for acf in parse_acf(destdir[:steam+11]):
+              if '/common/' + acf['installdir'] in destdir:
+                   steam_id = acf['appid']
+                   break
+          steam_dict['id'] = steam_id
           steam_dict['path'] = destdir[steam+11:]
           package['steam'] = steam_dict
 
@@ -78,10 +84,10 @@ def do_one_dir(destdir,lower):
                 package.setdefault('symlinks', {})[name] = os.path.realpath(path).lstrip('/')
             elif os.path.isfile(path):
                 if is_doc(fn):
-                     optional.add(fn)
+                     optional.add(out_name)
                      files['files'][out_name] = dict(install_to='$docdir')
                 else:
-                     install.add(fn)
+                     install.add(out_name)
 
                 hf = HashedFile.from_file(name, open(path, 'rb'))
                 sums['ck'][out_name] = os.path.getsize(path)
diff --git a/game_data_packager/steam.py b/game_data_packager/steam.py
new file mode 100644
index 0000000..780648d
--- /dev/null
+++ b/game_data_packager/steam.py
@@ -0,0 +1,45 @@
+#!/usr/bin/python3
+# encoding=utf-8
+#
+# Copyright © 2015 Alexandre Detiste <alexandre at detiste.be>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# You can find the GPL license text on a Debian system under
+# /usr/share/common-licenses/GPL-2.
+
+import glob
+
+def parse_acf(path):
+    acf = []
+    for manifest in glob.glob(path + '/*.acf'):
+        with open(manifest) as data:
+            # the .acf files are not really JSON files
+            level = 0
+            acf_struct = {}
+            for line in data.readlines():
+                if line.strip() == '{':
+                   level += 1
+                elif line.strip() == '}':
+                   level -= 1
+                elif level != 1:
+                   continue
+                elif '"\t\t"' in line:
+                   key , value = line.split('\t\t')
+                   key = key.strip().strip('"')
+                   value = value.strip().strip('"')
+                   if key in ('appid', 'name', 'installdir'):
+                       acf_struct[key] = value
+            if 'name' not in acf_struct:
+                acf_struct['name'] = acf_struct['installdir']
+            acf.append(acf_struct)
+
+    acf = sorted(acf, key=lambda k: (k['name']))
+    return acf

-- 
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