[game-data-packager] 02/39: Move most g-d-p Python code into the library file

Simon McVittie smcv at debian.org
Sun Jan 11 01:52:20 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 0eb82c834dd1564acb17ecbaa9f97b6837835121
Author: Simon McVittie <smcv at debian.org>
Date:   Fri Jan 9 09:45:59 2015 +0000

    Move most g-d-p Python code into the library file
---
 lib/game_data_packager/__init__.py | 108 +++++++++++++++++++++++++++++++++
 lib/game_data_packager/__main__.py | 119 +------------------------------------
 2 files changed, 111 insertions(+), 116 deletions(-)

diff --git a/lib/game_data_packager/__init__.py b/lib/game_data_packager/__init__.py
index 931f6c1..44f7813 100644
--- a/lib/game_data_packager/__init__.py
+++ b/lib/game_data_packager/__init__.py
@@ -18,6 +18,7 @@
 """Prototype for a more data-driven game-data-packager implementation.
 """
 
+import argparse
 import hashlib
 import io
 import logging
@@ -1040,3 +1041,110 @@ class GameData(object):
             open(os.path.join(self.workdir, 'DO-NOT-COMPRESS'), 'w').close()
 
         return True
+
+    def run_command_line(self, argv):
+        parser = argparse.ArgumentParser(description='Package game files.',
+                prog='game-data-packager ' + self.shortname)
+        parser.add_argument('--repack', action='store_true')
+        parser.add_argument('paths', nargs='*',
+                metavar='DIRECTORY|FILE')
+        args = parser.parse_args(argv)
+
+        if args.repack:
+            can_repack = False
+            absent = set()
+
+            for package in self.packages.values():
+                path = '/' + package.install_to
+                if os.path.isdir(path):
+                    args.paths.insert(0, path)
+                    can_repack = True
+                elif (package.name == 'quake3-data' and
+                        os.path.isdir('/usr/share/games/quake3')):
+                    # FIXME: this is a hack, it would be better to
+                    # have alternative locations defined in the YAML
+                    args.paths.insert(0, path)
+                    can_repack = True
+                else:
+                    absent.add(path)
+
+            if not can_repack:
+                raise SystemExit('cannot repack %s: could not open %r' %
+                        (package, sorted(absent)))
+
+        for arg in args.paths:
+            self.consider_file_or_dir(arg)
+
+        possible = set()
+
+        for package in self.packages.values():
+            if argv[0] in self.packages and package.name != argv[0]:
+                continue
+
+            if self.fill_gaps(package, log=False):
+                logger.debug('%s is possible', package.name)
+                possible.add(package)
+            else:
+                logger.debug('%s is impossible', package.name)
+
+        if not possible:
+            logger.debug('No packages were possible')
+            # Repeat the process for the first (hopefully only)
+            # demo/shareware package, so we can log its errors.
+            for package in self.packages.values():
+                if package.type == 'demo':
+                    if self.fill_gaps(package=package, log=True):
+                        logger.error('%s unexpectedly succeeded on second ' +
+                                'attempt. Please report this as a bug',
+                                package.name)
+                        possible.add(package)
+                    else:
+                        raise SystemExit(1)
+            else:
+                # If no demo, repeat the process for the first
+                # (hopefully only) full package, so we can log *its* errors.
+                for package in self.packages.values():
+                    if package.type == 'full':
+                        if self.fill_gaps(package=package, log=True):
+                            logger.error('%s unexpectedly succeeded on ' +
+                                    'second attempt. Please report this as '
+                                    'a bug', package.name)
+                            possible.add(package)
+                        else:
+                            sys.exit(1)
+                else:
+                    raise SystemExit('Unable to complete any packages. ' +
+                            'Please provide more files or directories.')
+
+        ready = set()
+
+        have_full = False
+        for package in possible:
+            if package.type == 'full':
+                have_full = True
+
+        for package in possible:
+            if have_full and package.type == 'demo':
+                # no point in packaging the demo if we have the full
+                # version
+                logger.debug('will not produce %s because we have a full ' +
+                        'version', package.name)
+                continue
+
+            logger.debug('will produce %s', package.name)
+            if self.fill_gaps(package=package, download=True, log=True):
+                ready.add(package)
+            else:
+                logger.error('Failed to download necessary files for %s',
+                        package.name)
+
+        if not ready:
+            raise SystemExit(1)
+
+        for package in ready:
+            destdir = os.path.join(os.environ['WORKDIR'],
+                    '%s.deb.d' % package.name)
+            if not self.fill_dest_dir(package, destdir):
+                raise SystemExit(1)
+
+        # FIXME: make the .deb (currently done in shell script by the wrapper)
diff --git a/lib/game_data_packager/__main__.py b/lib/game_data_packager/__main__.py
index 237d59e..308d8c2 100644
--- a/lib/game_data_packager/__main__.py
+++ b/lib/game_data_packager/__main__.py
@@ -15,128 +15,15 @@
 # You can find the GPL license text on a Debian system under
 # /usr/share/common-licenses/GPL-2.
 
-import argparse
-import logging
 import os
 import sys
 
 from . import GameData
 
-logging.basicConfig()
-logger = logging.getLogger('game-data-packager')
-
-def go(argv):
-    parser = argparse.ArgumentParser(description='Package game files.',
-            prog='game-data-packager ' + os.environ['SHORTNAME'])
-    parser.add_argument('--repack', action='store_true')
-    parser.add_argument('paths', nargs='*',
-            metavar='DIRECTORY|FILE')
-    args = parser.parse_args(argv[1:])
-
-    with GameData(argv[0],
+if __name__ == '__main__':
+    with GameData(sys.argv[1],
             datadir=os.environ['DATADIR'],
             workdir=os.environ['WORKDIR'],
             etcdir=os.environ['ETCDIR'],
             ) as game:
-
-        if args.repack:
-            can_repack = False
-            absent = set()
-
-            for package in game.packages.values():
-                path = '/' + package.install_to
-                if os.path.isdir(path):
-                    args.paths.insert(0, path)
-                    can_repack = True
-                elif (package.name == 'quake3-data' and
-                        os.path.isdir('/usr/share/games/quake3')):
-                    # FIXME: this is a hack, it would be better to
-                    # have alternative locations defined in the YAML
-                    args.paths.insert(0, path)
-                    can_repack = True
-                else:
-                    absent.add(path)
-
-            if not can_repack:
-                raise SystemExit('cannot repack %s: could not open %r' %
-                        (package, sorted(absent)))
-
-        for arg in args.paths:
-            game.consider_file_or_dir(arg)
-
-        possible = set()
-
-        for package in game.packages.values():
-            if argv[0] in game.packages and package.name != argv[0]:
-                continue
-
-            if game.fill_gaps(package, log=False):
-                logger.debug('%s is possible', package.name)
-                possible.add(package)
-            else:
-                logger.debug('%s is impossible', package.name)
-
-        if not possible:
-            logger.debug('No packages were possible')
-            # Repeat the process for the first (hopefully only)
-            # demo/shareware package, so we can log its errors.
-            for package in game.packages.values():
-                if package.type == 'demo':
-                    if game.fill_gaps(package=package, log=True):
-                        logger.error('%s unexpectedly succeeded on second ' +
-                                'attempt. Please report this as a bug',
-                                package.name)
-                        possible.add(package)
-                    else:
-                        sys.exit(1)
-            else:
-                # If no demo, repeat the process for the first
-                # (hopefully only) full package, so we can log *its* errors.
-                for package in game.packages.values():
-                    if package.type == 'full':
-                        if game.fill_gaps(package=package, log=True):
-                            logger.error('%s unexpectedly succeeded on ' +
-                                    'second attempt. Please report this as '
-                                    'a bug', package.name)
-                            possible.add(package)
-                        else:
-                            sys.exit(1)
-                else:
-                    raise SystemExit('Unable to complete any packages. ' +
-                            'Please provide more files or directories.')
-
-        ready = set()
-
-        have_full = False
-        for package in possible:
-            if package.type == 'full':
-                have_full = True
-
-        for package in possible:
-            if have_full and package.type == 'demo':
-                # no point in packaging the demo if we have the full
-                # version
-                logger.debug('will not produce %s because we have a full ' +
-                        'version', package.name)
-                continue
-
-            logger.debug('will produce %s', package.name)
-            if game.fill_gaps(package=package, download=True, log=True):
-                ready.add(package)
-            else:
-                logger.error('Failed to download necessary files for %s',
-                        package.name)
-
-        if not ready:
-            sys.exit(1)
-
-        for package in ready:
-            destdir = os.path.join(os.environ['WORKDIR'],
-                    '%s.deb.d' % package.name)
-            if not game.fill_dest_dir(package, destdir):
-                sys.exit(1)
-
-    # FIXME: make the .deb (currently done in shell script by the wrapper)
-
-if __name__ == '__main__':
-    go(sys.argv[1:])
+        game.run_command_line(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