[game-data-packager] 08/39: For YAML packages, generate *.deb in Python, not shell
Simon McVittie
smcv at debian.org
Sun Jan 11 01:52:21 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 af915d44198295e28dfcd43429d47c458d5a8b76
Author: Simon McVittie <smcv at debian.org>
Date: Fri Jan 9 10:49:39 2015 +0000
For YAML packages, generate *.deb in Python, not shell
---
Makefile | 6 +-
...ata.control.m4 => jedi-academy-data.control.in} | 0
...ata.control.m4 => jedi-outcast-data.control.in} | 0
...ake3-data.control.m4 => quake3-data.control.in} | 0
...ontrol.m4 => quake3-team-arena-data.control.in} | 0
.../{rott-data.control.m4 => rott-data.control.in} | 0
.../{rtcw-data.control.m4 => rtcw-data.control.in} | 0
...rian-data.control.m4 => tyrian-data.control.in} | 0
debian/control | 1 +
debian/game-data-packager.install | 2 +-
debian/rules | 12 ++--
lib/game_data_packager/__init__.py | 69 ++++++++++++++++++----
lib/game_data_packager/__main__.py | 2 +-
lib/game_data_packager/make_template.py | 9 +--
lib/game_data_packager/util.py | 5 ++
lib/game_data_packager/version.py | 7 +++
lib/via-python | 53 +----------------
17 files changed, 84 insertions(+), 82 deletions(-)
diff --git a/Makefile b/Makefile
index 06b76ae..ce8f5ae 100644
--- a/Makefile
+++ b/Makefile
@@ -6,12 +6,8 @@ default: $(DIRS)
gzip -nc9 debian/changelog > ./out/changelog.gz
chmod 0644 ./out/changelog.gz
install -m644 data/*.yaml out/
+ install -m644 data/*.control.in out/
install -m644 data/*.copyright out/
- set -e; for x in data/*.*.m4; do \
- o="out/$${x#data/}"; \
- o="$${o%.m4}"; \
- m4 -DVERSION=${VERSION} < $$x > $$o; \
- done
make -f doom-common.mk IWAD=doom LONG="Doom" VERSION=$(VERSION)
make -f doom-common.mk IWAD=doom2 \
LONG="Doom 2: Hell on Earth" VERSION=$(VERSION)
diff --git a/data/jedi-academy-data.control.m4 b/data/jedi-academy-data.control.in
similarity index 100%
rename from data/jedi-academy-data.control.m4
rename to data/jedi-academy-data.control.in
diff --git a/data/jedi-outcast-data.control.m4 b/data/jedi-outcast-data.control.in
similarity index 100%
rename from data/jedi-outcast-data.control.m4
rename to data/jedi-outcast-data.control.in
diff --git a/data/quake3-data.control.m4 b/data/quake3-data.control.in
similarity index 100%
rename from data/quake3-data.control.m4
rename to data/quake3-data.control.in
diff --git a/data/quake3-team-arena-data.control.m4 b/data/quake3-team-arena-data.control.in
similarity index 100%
rename from data/quake3-team-arena-data.control.m4
rename to data/quake3-team-arena-data.control.in
diff --git a/data/rott-data.control.m4 b/data/rott-data.control.in
similarity index 100%
rename from data/rott-data.control.m4
rename to data/rott-data.control.in
diff --git a/data/rtcw-data.control.m4 b/data/rtcw-data.control.in
similarity index 100%
rename from data/rtcw-data.control.m4
rename to data/rtcw-data.control.in
diff --git a/data/tyrian-data.control.m4 b/data/tyrian-data.control.in
similarity index 100%
rename from data/tyrian-data.control.m4
rename to data/tyrian-data.control.in
diff --git a/debian/control b/debian/control
index a478403..b334e03 100644
--- a/debian/control
+++ b/debian/control
@@ -21,6 +21,7 @@ Package: game-data-packager
Depends: fakeroot, ${misc:Depends}, ${shlib:Depends},
# for jedi-*, rtcw, and hopefully more soon
python3,
+ python3-debian,
python3-yaml,
${python3:Depends},
# for quake, quake2, rott, wolf3d
diff --git a/debian/game-data-packager.install b/debian/game-data-packager.install
index e7b21d0..4bfbec5 100644
--- a/debian/game-data-packager.install
+++ b/debian/game-data-packager.install
@@ -3,7 +3,7 @@ game-data-packager usr/games
supported/* usr/share/games/game-data-packager/supported
etc/game-data-packager.conf etc
etc/*-mirrors etc/game-data-packager
-out/*.control usr/share/games/game-data-packager
+out/*.control.in usr/share/games/game-data-packager
out/*.copyright usr/share/games/game-data-packager
out/*.deb usr/share/games/game-data-packager
out/changelog.gz usr/share/games/game-data-packager
diff --git a/debian/rules b/debian/rules
index 37279c3..68ad19f 100755
--- a/debian/rules
+++ b/debian/rules
@@ -4,16 +4,16 @@
#export DH_VERBOSE=1
export DH_OPTIONS
+include /usr/share/dpkg/pkg-info.mk
+
%:
dh $@ --with python3
-VERSION := $(shell dpkg-parsechangelog | grep ^Version | cut -d' ' -f2-)
-
override_dh_auto_build:
- $(MAKE) VERSION=$(VERSION)
+ $(MAKE) VERSION=$(DEB_VERSION)
override_dh_auto_clean:
- $(MAKE) clean VERSION=$(VERSION)
+ $(MAKE) clean VERSION=$(DEB_VERSION)
@if [ "`echo *.deb`" != "*.deb" ]; then \
echo; \
echo "*************************************************"; \
@@ -24,5 +24,9 @@ override_dh_auto_clean:
exit 1; \
fi
+override_dh_install:
+ dh_install
+ echo 'GAME_PACKAGE_VERSION = """$(DEB_VERSION)"""' > debian/game-data-packager/usr/lib/game-data-packager/game_data_packager/version.py
+
override_dh_installdocs:
dh_installdocs -XTODO
diff --git a/lib/game_data_packager/__init__.py b/lib/game_data_packager/__init__.py
index 36f99c5..5eda7ee 100644
--- a/lib/game_data_packager/__init__.py
+++ b/lib/game_data_packager/__init__.py
@@ -33,9 +33,10 @@ import tempfile
import urllib.request
import zipfile
+from debian.deb822 import Deb822
import yaml
-from .util import TemporaryUmask, mkdir_p, human_size, MEBIBYTE
+from .util import TemporaryUmask, mkdir_p, rm_rf, human_size, MEBIBYTE
logging.basicConfig()
logger = logging.getLogger('game-data-packager')
@@ -47,6 +48,8 @@ if os.environ.get('DEBUG'):
else:
logging.getLogger().setLevel(logging.INFO)
+from .version import GAME_PACKAGE_VERSION
+
# arbitrary cutoff for providing progress bars
QUITE_LARGE = 50 * MEBIBYTE
@@ -229,6 +232,8 @@ class GameDataPackage(object):
# expansion packages include quake-armagon, quake-music, quake2-rogue
self._type = 'full'
+ self.version = GAME_PACKAGE_VERSION
+
@property
def install(self):
return self._install
@@ -970,8 +975,6 @@ class GameData(object):
debdir = os.path.join(destdir, 'DEBIAN')
mkdir_p(debdir)
- shutil.copyfile(os.path.join(self.datadir, package.name + '.control'),
- os.path.join(debdir, 'control'))
for ms in ('preinst', 'postinst', 'prerm', 'postrm'):
maintscript = os.path.join(self.datadir, package.name + '.' + ms)
@@ -1032,17 +1035,29 @@ class GameData(object):
mkdir_p(os.path.dirname(os.path.join(destdir, symlink)))
os.symlink(target, os.path.join(destdir, symlink))
- # FIXME: eventually we should build the .deb in Python, but for now
- # we let the shell script do it
-
- # Hackish way to communicate to shell script that we don't want
- # compression
- if not self.compress_deb:
- open(os.path.join(self.workdir, 'DO-NOT-COMPRESS'), 'w').close()
+ # adapted from dh_md5sums
+ subprocess.check_call("find . -type f ! -regex '\./DEBIAN/.*' " +
+ "-printf '%P\\0' | LC_ALL=C sort -z | " +
+ "xargs -r0 md5sum > DEBIAN/md5sums",
+ shell=True, cwd=destdir)
+ os.chmod(os.path.join(destdir, 'DEBIAN/md5sums'), 0o644)
+
+ control_in = open(os.path.join(self.datadir,
+ package.name + '.control.in'))
+ control = Deb822(control_in)
+ size = subprocess.check_output(['du', '-sk', '--exclude=./DEBIAN',
+ '.'], cwd=destdir).decode('utf-8').rstrip('\n')
+ control['Installed-Size'] = size
+ package.version = control['Version'].replace('VERSION',
+ GAME_PACKAGE_VERSION)
+ control['Version'] = package.version
+ control.dump(fd=open(os.path.join(debdir, 'control'), 'wb'),
+ encoding='utf-8')
+ os.chmod(os.path.join(debdir, 'control'), 0o644)
return True
- def run_command_line(self, argv):
+ def run_command_line(self, argv, outdir=''):
parser = argparse.ArgumentParser(description='Package game files.',
prog='game-data-packager ' + self.shortname)
parser.add_argument('--repack', action='store_true')
@@ -1147,4 +1162,34 @@ class GameData(object):
if not self.fill_dest_dir(package, destdir):
raise SystemExit(1)
- # FIXME: make the .deb (currently done in shell script by the wrapper)
+ # it had better have a /usr and a DEBIAN directory or
+ # something has gone very wrong
+ assert os.path.isdir(os.path.join(destdir, 'usr')), destdir
+ assert os.path.isdir(os.path.join(destdir, 'DEBIAN')), destdir
+
+ deb_basename = '%s_%s_all.deb' % (package.name, package.version)
+
+ if outdir:
+ outfile = os.path.join(os.path.abspath(outdir), deb_basename)
+ os.symlink(outfile, os.path.join(self.get_workdir(),
+ deb_basename))
+ else:
+ outfile = os.path.join(self.get_workdir(), deb_basename)
+
+ if self.compress_deb:
+ dpkg_deb_args = []
+ else:
+ dpkg_deb_args = ['-Znone']
+
+ try:
+ subprocess.check_output(['fakeroot', 'dpkg-deb'] +
+ dpkg_deb_args +
+ ['-b', '%s.deb.d' % package.name, outfile],
+ cwd=self.get_workdir())
+ except subprocess.CalledProcessError as cpe:
+ print(cpe.output)
+ raise
+
+ rm_rf(destdir)
+
+ rm_rf(os.path.join(self.get_workdir(), 'tmp'))
diff --git a/lib/game_data_packager/__main__.py b/lib/game_data_packager/__main__.py
index 308d8c2..2ccdd19 100644
--- a/lib/game_data_packager/__main__.py
+++ b/lib/game_data_packager/__main__.py
@@ -26,4 +26,4 @@ if __name__ == '__main__':
workdir=os.environ['WORKDIR'],
etcdir=os.environ['ETCDIR'],
) as game:
- game.run_command_line(sys.argv[2:])
+ game.run_command_line(sys.argv[2:], outdir=os.environ['OUTDIR'])
diff --git a/lib/game_data_packager/make_template.py b/lib/game_data_packager/make_template.py
index 0fe9229..f6f4eea 100644
--- a/lib/game_data_packager/make_template.py
+++ b/lib/game_data_packager/make_template.py
@@ -22,14 +22,9 @@ import subprocess
import sys
import tarfile
+from debian.deb822 import Deb822
import yaml
-try:
- from debian.deb822 import Deb822
-except ImportError:
- raise SystemExit('"game-data-packager make-template" requires ' +
- 'python3-debian')
-
from . import HashedFile
logging.basicConfig()
@@ -90,7 +85,7 @@ def do_one_deb(deb):
if name == 'control':
reader = ctrl_tarfile.extractfile(entry)
control = Deb822(reader)
- print('# data/%s.control.m4' % control['package'])
+ print('# data/%s.control.in' % control['package'])
control['version'] = 'VERSION'
control.dump(fd=sys.stdout, text_mode=True)
print('')
diff --git a/lib/game_data_packager/util.py b/lib/game_data_packager/util.py
index c963bdc..16553a7 100644
--- a/lib/game_data_packager/util.py
+++ b/lib/game_data_packager/util.py
@@ -16,6 +16,7 @@
# /usr/share/common-licenses/GPL-2.
import os
+import shutil
KIBIBYTE = 1024
MEBIBYTE = KIBIBYTE * KIBIBYTE
@@ -44,6 +45,10 @@ def mkdir_p(path):
with TemporaryUmask(0o022):
os.makedirs(path)
+def rm_rf(path):
+ if os.path.exists(path):
+ shutil.rmtree(path)
+
def human_size(size):
# 0.0 KiB up to 1024.0 KiB
if size < MEBIBYTE:
diff --git a/lib/game_data_packager/version.py b/lib/game_data_packager/version.py
new file mode 100644
index 0000000..252b942
--- /dev/null
+++ b/lib/game_data_packager/version.py
@@ -0,0 +1,7 @@
+# This version of this file is only used when run uninstalled. It is replaced
+# with a generated version during installation.
+
+from debian.changelog import Changelog
+
+cl = Changelog(open('debian/changelog'), strict=False)
+GAME_PACKAGE_VERSION = str(cl.full_version)
diff --git a/lib/via-python b/lib/via-python
index de2150b..0730576 100644
--- a/lib/via-python
+++ b/lib/via-python
@@ -21,6 +21,7 @@ gdp_data_driven () {
(
export ETCDIR
export DATADIR
+ export OUTDIR
export WORKDIR
PYTHONPATH="$LIBDIR"
export PYTHONPATH
@@ -35,59 +36,7 @@ gdp_data_driven () {
exit $?
fi
- # We still do the actual .deb creation in shell, for now
-
- if [ -e "$WORKDIR/DO-NOT-COMPRESS" ]; then
- COMPRESS=no
- fi
-
- for DESTDIR in "$WORKDIR"/*.deb.d; do
- deb="${DESTDIR%.deb.d}"
- deb="${deb##*/}"
-
- # it had better have a /usr and a DEBIAN directory or something has
- # gone very wrong
- if ! [ -e "$DESTDIR/usr" ]; then
- echo "internal error: $DESTDIR/usr not found" >&2
- exit 1
- fi
- if ! [ -e "$DESTDIR/DEBIAN" ]; then
- echo "internal error: $DESTDIR/DEBIAN not found" >&2
- exit 1
- fi
-
- output="${deb}_${VERSION_PREFIX:-}${GAME_PACKAGE_VERSION}_all.deb"
-
- if [ "" = "$OUTDIR" ]; then
- OUTFILE="$WORKDIR/$output"
- else
- OUTFILE="$(unravel "$OUTDIR")/$output"
- ln -s "$OUTFILE" "$WORKDIR/$output"
- fi
-
- ( cd "$DESTDIR" && find usr -type f -print0 | xargs -0 md5sum ) > \
- "$DESTDIR/DEBIAN/md5sums"
-
- # slipstream_* assume this naming
- if [ -e "$WORKDIR/slipstream.unpacked" ]; then
- echo "internal error: $WORKDIR/slipstream.unpacked exists" >&2
- exit 1
- fi
- mv "$DESTDIR" "$WORKDIR/slipstream.unpacked"
-
- debug "building .deb: $OUTFILE"
- ( cd "$WORKDIR" && slipstream_instsize )
- ( cd "$WORKDIR" && slipstream_repack "$OUTFILE" )
-
- rm -fr "$WORKDIR/slipstream.unpacked"
- done
-
# Special value to signal that gdp should just install every .deb
# in $WORKDIR
OUTFILE="*.deb"
-
- rm -f "$WORKDIR/DO-NOT-COMPRESS"
-
- # The Python code does all its work in this directory
- rm -fr "$WORKDIR/tmp"
}
--
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