[game-data-packager] 03/09: Move steam and gog modes to their own modules

Simon McVittie smcv at debian.org
Thu Oct 1 10:16:50 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 9cfa8caf318bcb750e48016219f8f7bbe843c070
Author: Simon McVittie <smcv at debian.org>
Date:   Thu Oct 1 08:20:51 2015 +0100

    Move steam and gog modes to their own modules
---
 debian/changelog               |   1 +
 game_data_packager/__init__.py | 192 +----------------------------------------
 game_data_packager/gog.py      |  67 +++++++++++++-
 game_data_packager/steam.py    | 143 +++++++++++++++++++++++++++++-
 4 files changed, 211 insertions(+), 192 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 0963867..573a875 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -53,6 +53,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
+  * Move steam and gog modes to their own modules
 
  -- Simon McVittie <smcv at debian.org>  Thu, 16 Jul 2015 09:59:23 +0200
 
diff --git a/game_data_packager/__init__.py b/game_data_packager/__init__.py
index 7b20f5d..c2d5f84 100644
--- a/game_data_packager/__init__.py
+++ b/game_data_packager/__init__.py
@@ -47,7 +47,7 @@ from .build import (CDRipFailed,
         FillResult,
         NoPackagesPossible)
 from .config import read_config
-from .gog import GOG
+from .gog import (GOG, run_gog_meta_mode)
 from .paths import DATADIR, ETCDIR
 from .util import (MEBIBYTE,
         AGENT,
@@ -61,7 +61,7 @@ from .util import (MEBIBYTE,
         lang_score,
         ascii_safe,
         which)
-from .steam import get_steam_id, owned_steam_games
+from .steam import run_steam_meta_mode
 from .version import GAME_PACKAGE_VERSION
 
 logging.basicConfig()
@@ -3138,194 +3138,6 @@ def load_games(workdir=None,game='*'):
     print('\r%s\r' % (' ' * len(games)), end='', flush=True, file=sys.stderr)
     return games
 
-def run_steam_meta_mode(parsed, games):
-    logger.info('Visit our community page: https://steamcommunity.com/groups/debian_gdp#curation')
-    owned = set()
-    if parsed.download:
-        steam_id = get_steam_id()
-        if steam_id is None:
-            logger.error("Couldn't read SteamID from ~/.steam/config/loginusers.vdf")
-        else:
-            logger.info('Getting list of owned games from '
-                        'http://steamcommunity.com/profiles/' + steam_id)
-            owned = set(g[0] for g in owned_steam_games(steam_id))
-
-    logging.info('Searching for locally installed Steam games...')
-    found_games = []
-    found_packages = []
-    for game, gamedata in games.items():
-        for package in gamedata.packages.values():
-            id = package.steam.get('id') or gamedata.steam.get('id')
-            if not id:
-                continue
-
-            if package.type == 'demo':
-                continue
-            # ignore other translations for "I Have No Mouth"
-            if lang_score(package.lang) == 0:
-                continue
-
-            installed = PACKAGE_CACHE.is_installed(package.name)
-            if parsed.new and installed:
-                continue
-
-            paths = []
-            for path in gamedata.iter_steam_paths((package,)):
-                if path not in paths:
-                    paths.append(path)
-            if not paths and id not in owned:
-                continue
-
-            if game not in found_games:
-                found_games.append(game)
-            found_packages.append({
-                'game' : game,
-                'type' : 1 if package.type == 'full' else 2,
-                'package': package.name,
-                'installed': installed,
-                'longname': package.longname or gamedata.longname,
-                'paths': paths,
-               })
-    if not found_games:
-        logger.error('No Steam games found')
-        return
-
-    print('[x] = package is already installed')
-    print('----------------------------------------------------------------------\n')
-    found_packages = sorted(found_packages, key=lambda k: (k['game'], k['type'], k['longname']))
-    for g in sorted(found_games):
-        print(g)
-        for p in found_packages:
-            if p['game'] != g:
-                continue
-            print('[%s] %-42s    %s' % ('x' if p['installed'] else ' ',
-                                        p['package'], ascii_safe(p['longname'])))
-            for path in p['paths']:
-                print(path)
-            if not p['paths']:
-                print('<game owned but not installed/found>')
-        print()
-
-    if not parsed.new and not parsed.all:
-       logger.info('Please specify --all or --new to create desired packages.')
-       return
-
-    preserve_debs = (getattr(parsed, 'destination', None) is not None)
-    install_debs = getattr(parsed, 'install', True)
-    if getattr(parsed, 'compress', None) is None:
-        # default to not compressing if we aren't going to install it
-        # anyway
-        parsed.compress = preserve_debs
-
-    all_debs = set()
-
-    for shortname in sorted(found_games):
-        game = games[shortname]
-        game.verbose = getattr(parsed, 'verbose', False)
-        game.save_downloads = parsed.save_downloads
-        game.look_for_files()
-
-        todo = list()
-        for packages in found_packages:
-            if packages['game'] == shortname:
-                todo.append(game.packages[packages['package']])
-        try:
-            ready = game.prepare_packages(log_immediately=False,
-                                          packages=todo)
-        except NoPackagesPossible:
-            logger.error('No package possible for %s.' % game.shortname)
-            continue
-        except DownloadsFailed:
-            logger.error('Unable to complete any packages of %s'
-                         ' because downloads failed.' % game.shortname)
-            continue
-
-        if parsed.destination is None:
-            destination = workdir = tempfile.mkdtemp(prefix='gdptmp.')
-        else:
-            workdir = None
-            destination = parsed.destination
-
-        debs = game.build_packages(ready,
-                compress=getattr(parsed, 'compress', True),
-                destination=destination)
-        rm_rf(os.path.join(game.get_workdir(), 'tmp'))
-
-        if preserve_debs:
-            for deb in debs:
-                print('generated "%s"' % os.path.abspath(deb))
-        all_debs = all_debs.union(debs)
-
-    if not all_debs:
-        logger.error('Unable to package any game.')
-        if workdir:
-           rm_rf(workdir)
-        raise SystemExit(1)
-
-    if install_debs:
-        install_packages(all_debs)
-    if workdir:
-        rm_rf(workdir)
-
-def run_gog_meta_mode(parsed, games):
-    logger.info('Visit game-data-packager @ GOG.com: https://www.gog.com/mix/games_supported_by_debians_gamedatapackager')
-    if not which('lgogdownloader') or not which('innoextract'):
-        logger.error("You need to install lgogdownloader & innoextract first")
-        logger.error("$ su -c 'apt-get install lgogdownloader innoextract'")
-        return
-
-    owned = GOG.owned_games()
-    if not owned:
-        logger.error("Couldn't locate any game, running 'lgogdownloader --login'")
-        subprocess.call(['lgogdownloader', '--login'])
-        logger.info("... and now 'lgogdownloader --update-cache'")
-        subprocess.call(['lgogdownloader', '--update-cache'])
-        GOG.available = None
-        owned = GOG.owned_games()
-    logger.info("Found %d game(s) !" % len(owned))
-
-    found_games = set()
-    found_packages = []
-    for game, data in games.items():
-        for package in data.packages.values():
-            id = data.gog_download_name(package)
-            if id is None or id not in owned:
-                continue
-            if lang_score(package.lang) == 0:
-                continue
-            if package.better_version:
-                if data.gog_download_name(data.packages[package.better_version]):
-                    continue
-            installed = PACKAGE_CACHE.is_installed(package.name)
-            if parsed.new and installed:
-                continue
-            found_games.add(game)
-            found_packages.append({
-                'game' : game,
-                'type' : 1 if package.type == 'full' else 2,
-                'package': package.name,
-                'installed': installed,
-                'longname': package.longname or data.longname,
-                'id': id,
-               })
-    if not found_games:
-        logger.error('No supported GOG.com games found')
-        return
-
-    print('[x] = package is already installed')
-    found_packages = sorted(found_packages, key=lambda k: (k['game'], k['type'], k['longname']))
-    for g in sorted(found_games):
-        ids = set()
-        for p in found_packages:
-            if p['game'] == g:
-                ids.add('"%s"' % p['id'])
-        print('%s - provided by %s' % (g, ','.join(ids)))
-        for p in found_packages:
-            if p['game'] == g:
-                print('[%s] %-42s    %s' % ('x' if p['installed'] else ' ',
-                                        p['package'], ascii_safe(p['longname'])))
-        print()
-
 def run_command_line():
     logger.debug('Arguments: %r', sys.argv)
 
diff --git a/game_data_packager/gog.py b/game_data_packager/gog.py
index 6f04597..fc2c961 100644
--- a/game_data_packager/gog.py
+++ b/game_data_packager/gog.py
@@ -16,10 +16,16 @@
 # /usr/share/common-licenses/GPL-2.
 
 import json
+import logging
 import os
 import subprocess
 
-from .util import which
+from .util import (PACKAGE_CACHE,
+        ascii_safe,
+        lang_score,
+        which)
+
+logger = logging.getLogger('game-data-packager.gog')
 
 class Gog:
     available = None
@@ -76,3 +82,62 @@ class Gog:
                     return game['gamename']
 
 GOG = Gog()
+
+def run_gog_meta_mode(parsed, games):
+    logger.info('Visit game-data-packager @ GOG.com: https://www.gog.com/mix/games_supported_by_debians_gamedatapackager')
+    if not which('lgogdownloader') or not which('innoextract'):
+        logger.error("You need to install lgogdownloader & innoextract first")
+        logger.error("$ su -c 'apt-get install lgogdownloader innoextract'")
+        return
+
+    owned = GOG.owned_games()
+    if not owned:
+        logger.error("Couldn't locate any game, running 'lgogdownloader --login'")
+        subprocess.call(['lgogdownloader', '--login'])
+        logger.info("... and now 'lgogdownloader --update-cache'")
+        subprocess.call(['lgogdownloader', '--update-cache'])
+        GOG.available = None
+        owned = GOG.owned_games()
+    logger.info("Found %d game(s) !" % len(owned))
+
+    found_games = set()
+    found_packages = []
+    for game, data in games.items():
+        for package in data.packages.values():
+            id = data.gog_download_name(package)
+            if id is None or id not in owned:
+                continue
+            if lang_score(package.lang) == 0:
+                continue
+            if package.better_version:
+                if data.gog_download_name(data.packages[package.better_version]):
+                    continue
+            installed = PACKAGE_CACHE.is_installed(package.name)
+            if parsed.new and installed:
+                continue
+            found_games.add(game)
+            found_packages.append({
+                'game' : game,
+                'type' : 1 if package.type == 'full' else 2,
+                'package': package.name,
+                'installed': installed,
+                'longname': package.longname or data.longname,
+                'id': id,
+               })
+    if not found_games:
+        logger.error('No supported GOG.com games found')
+        return
+
+    print('[x] = package is already installed')
+    found_packages = sorted(found_packages, key=lambda k: (k['game'], k['type'], k['longname']))
+    for g in sorted(found_games):
+        ids = set()
+        for p in found_packages:
+            if p['game'] == g:
+                ids.add('"%s"' % p['id'])
+        print('%s - provided by %s' % (g, ','.join(ids)))
+        for p in found_packages:
+            if p['game'] == g:
+                print('[%s] %-42s    %s' % ('x' if p['installed'] else ' ',
+                                        p['package'], ascii_safe(p['longname'])))
+        print()
diff --git a/game_data_packager/steam.py b/game_data_packager/steam.py
index 5e38b4d..0e5483d 100644
--- a/game_data_packager/steam.py
+++ b/game_data_packager/steam.py
@@ -16,10 +16,22 @@
 # /usr/share/common-licenses/GPL-2.
 
 import glob
+import logging
 import os
+import tempfile
 import xml.etree.ElementTree
 import urllib.request
-from .util import AGENT
+
+from .build import (DownloadsFailed,
+        NoPackagesPossible)
+from .util import (AGENT,
+        PACKAGE_CACHE,
+        ascii_safe,
+        install_packages,
+        lang_score,
+        rm_rf)
+
+logger = logging.getLogger('game-data-packager.steam')
 
 def parse_acf(path):
     for manifest in glob.glob(path + '/*.acf'):
@@ -65,3 +77,132 @@ def get_steam_id():
             line = line.strip('\t\n "')
             if line not in ('users', '{'):
                 return line
+
+def run_steam_meta_mode(parsed, games):
+    logger.info('Visit our community page: https://steamcommunity.com/groups/debian_gdp#curation')
+    owned = set()
+    if parsed.download:
+        steam_id = get_steam_id()
+        if steam_id is None:
+            logger.error("Couldn't read SteamID from ~/.steam/config/loginusers.vdf")
+        else:
+            logger.info('Getting list of owned games from '
+                        'http://steamcommunity.com/profiles/' + steam_id)
+            owned = set(g[0] for g in owned_steam_games(steam_id))
+
+    logging.info('Searching for locally installed Steam games...')
+    found_games = []
+    found_packages = []
+    for game, gamedata in games.items():
+        for package in gamedata.packages.values():
+            id = package.steam.get('id') or gamedata.steam.get('id')
+            if not id:
+                continue
+
+            if package.type == 'demo':
+                continue
+            # ignore other translations for "I Have No Mouth"
+            if lang_score(package.lang) == 0:
+                continue
+
+            installed = PACKAGE_CACHE.is_installed(package.name)
+            if parsed.new and installed:
+                continue
+
+            paths = []
+            for path in gamedata.iter_steam_paths((package,)):
+                if path not in paths:
+                    paths.append(path)
+            if not paths and id not in owned:
+                continue
+
+            if game not in found_games:
+                found_games.append(game)
+            found_packages.append({
+                'game' : game,
+                'type' : 1 if package.type == 'full' else 2,
+                'package': package.name,
+                'installed': installed,
+                'longname': package.longname or gamedata.longname,
+                'paths': paths,
+               })
+    if not found_games:
+        logger.error('No Steam games found')
+        return
+
+    print('[x] = package is already installed')
+    print('----------------------------------------------------------------------\n')
+    found_packages = sorted(found_packages, key=lambda k: (k['game'], k['type'], k['longname']))
+    for g in sorted(found_games):
+        print(g)
+        for p in found_packages:
+            if p['game'] != g:
+                continue
+            print('[%s] %-42s    %s' % ('x' if p['installed'] else ' ',
+                                        p['package'], ascii_safe(p['longname'])))
+            for path in p['paths']:
+                print(path)
+            if not p['paths']:
+                print('<game owned but not installed/found>')
+        print()
+
+    if not parsed.new and not parsed.all:
+       logger.info('Please specify --all or --new to create desired packages.')
+       return
+
+    preserve_debs = (getattr(parsed, 'destination', None) is not None)
+    install_debs = getattr(parsed, 'install', True)
+    if getattr(parsed, 'compress', None) is None:
+        # default to not compressing if we aren't going to install it
+        # anyway
+        parsed.compress = preserve_debs
+
+    all_debs = set()
+
+    for shortname in sorted(found_games):
+        game = games[shortname]
+        game.verbose = getattr(parsed, 'verbose', False)
+        game.save_downloads = parsed.save_downloads
+        game.look_for_files()
+
+        todo = list()
+        for packages in found_packages:
+            if packages['game'] == shortname:
+                todo.append(game.packages[packages['package']])
+        try:
+            ready = game.prepare_packages(log_immediately=False,
+                                          packages=todo)
+        except NoPackagesPossible:
+            logger.error('No package possible for %s.' % game.shortname)
+            continue
+        except DownloadsFailed:
+            logger.error('Unable to complete any packages of %s'
+                         ' because downloads failed.' % game.shortname)
+            continue
+
+        if parsed.destination is None:
+            destination = workdir = tempfile.mkdtemp(prefix='gdptmp.')
+        else:
+            workdir = None
+            destination = parsed.destination
+
+        debs = game.build_packages(ready,
+                compress=getattr(parsed, 'compress', True),
+                destination=destination)
+        rm_rf(os.path.join(game.get_workdir(), 'tmp'))
+
+        if preserve_debs:
+            for deb in debs:
+                print('generated "%s"' % os.path.abspath(deb))
+        all_debs = all_debs.union(debs)
+
+    if not all_debs:
+        logger.error('Unable to package any game.')
+        if workdir:
+           rm_rf(workdir)
+        raise SystemExit(1)
+
+    if install_debs:
+        install_packages(all_debs)
+    if workdir:
+        rm_rf(workdir)

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