[game-data-packager] 11/11: Consistently apply the same substitutions to all install_to and symlinks

Simon McVittie smcv at debian.org
Tue Jan 5 09:55:28 UTC 2016


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 5ab47e402df1f1881cf406af970a3a455b991326
Author: Simon McVittie <smcv at debian.org>
Date:   Tue Jan 5 09:53:03 2016 +0000

    Consistently apply the same substitutions to all install_to and symlinks
    
    One minor exception is that ${install_to} only works for symlinks,
    because what would it mean in install_to? :-)
---
 game_data_packager/build.py              | 38 +++++++-------------------------
 game_data_packager/packaging/__init__.py | 13 +++++++++++
 2 files changed, 21 insertions(+), 30 deletions(-)

diff --git a/game_data_packager/build.py b/game_data_packager/build.py
index 55e5ed1..e8ea2b4 100644
--- a/game_data_packager/build.py
+++ b/game_data_packager/build.py
@@ -26,7 +26,6 @@ import random
 import shutil
 import stat
 import subprocess
-import string
 import sys
 import tempfile
 import time
@@ -1377,9 +1376,8 @@ class PackagingTask(object):
                      main_wad = f.install_as
                      exts.add(os.path.splitext(main_wad.lower())[1])
 
-            install_to = package.install_to
-            if install_to.startswith('$assets'):
-                install_to = self.packaging.ASSETS + install_to[7:]
+            install_to = self.packaging.substitute(package.install_to,
+                    package.name)
 
             if count_usr == 0 and count_doc == 1:
                 o.write('"/usr/share/doc/%s/%s"\n' % (package.name,
@@ -1594,15 +1592,8 @@ class PackagingTask(object):
                 if install_to is None:
                     install_to = package.install_to
 
-                if install_to.startswith('$assets'):
-                    install_to = self.packaging.ASSETS + install_to[7:]
-                elif install_to.startswith('$pkgdocdir'):
-                    install_to = pkgdocdir + install_to[10:]
-                elif install_to.startswith('$pkglicensedir'):
-                    mkdir_p(dest_pkglicensedir)
-                    install_to = pkglicensedir + install_to[14:]
-
-                install_to = install_to.lstrip('/')
+                install_to = self.packaging.substitute(install_to,
+                        package.name).lstrip('/')
 
                 copy_to = os.path.join(destdir, install_to, install_as)
                 copy_to_dir = os.path.dirname(copy_to)
@@ -1620,19 +1611,9 @@ class PackagingTask(object):
                     os.chmod(copy_to, 0o644)
 
         for symlink, real_file in package.symlinks.items():
-            symlink = string.Template(symlink).safe_substitute(
-                    assets=self.packaging.ASSETS,
-                    bindir=self.packaging.BINDIR,
-                    licensedir=self.packaging.LICENSEDIR,
-                    pkgdocdir=pkgdocdir,
-                    pkglicensedir=pkglicensedir,
+            symlink = self.packaging.substitute(symlink, package.name,
                     install_to=package.install_to)
-            real_file = string.Template(real_file).safe_substitute(
-                    assets=self.packaging.ASSETS,
-                    bindir=self.packaging.BINDIR,
-                    pkgdocdir=pkgdocdir,
-                    licensedir=self.packaging.LICENSEDIR,
-                    pkglicensedir=pkglicensedir,
+            real_file = self.packaging.substitute(real_file, package.name,
                     install_to=package.install_to)
 
             symlink = symlink.lstrip('/')
@@ -1661,11 +1642,8 @@ class PackagingTask(object):
         if package.rip_cd and self.cd_tracks.get(package.name):
             for i, copy_from in self.cd_tracks[package.name].items():
                 logger.debug('Found CD track %d at %s', i, copy_from)
-                install_to = package.install_to
-                if install_to.startswith('$assets'):
-                    install_to = self.packaging.ASSETS + install_to[7:]
-
-                install_to = install_to.lstrip('/')
+                install_to = self.packaging.substitute(package.install_to,
+                        package.name).lstrip('/')
                 install_as = package.rip_cd['filename_format'] % i
                 copy_to = os.path.join(destdir, install_to, install_as)
                 copy_to_dir = os.path.dirname(copy_to)
diff --git a/game_data_packager/packaging/__init__.py b/game_data_packager/packaging/__init__.py
index 5ca2acf..23faa11 100644
--- a/game_data_packager/packaging/__init__.py
+++ b/game_data_packager/packaging/__init__.py
@@ -17,6 +17,7 @@
 # /usr/share/common-licenses/GPL-2.
 
 from abc import (ABCMeta, abstractmethod)
+import string
 
 class PackagingSystem(metaclass=ABCMeta):
     ASSETS = 'usr/share'
@@ -57,6 +58,18 @@ class PackagingSystem(metaclass=ABCMeta):
         """Install one or more packages (a list of filenames)."""
         raise NotImplementedError
 
+    def substitute(self, template, package, **kwargs):
+        if '$' not in template:
+            return template
+
+        return string.Template(template).substitute(kwargs,
+                assets=self.ASSETS,
+                bindir=self.BINDIR,
+                licensedir=self.LICENSEDIR,
+                pkgdocdir='usr/share/doc/' + package,
+                pkglicensedir=self.LICENSEDIR + '/' + package,
+                )
+
 def get_native_packaging_system():
     # lazy import when actually needed
     from ..version import (FORMAT)

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