[game-data-packager] 01/01: avoid calling external shell with find, xargs, md5sum *
Alexandre Detiste
detiste-guest at moszumanska.debian.org
Sun Jan 10 17:57:13 UTC 2016
This is an automated email from the git hooks/post-receive script.
detiste-guest pushed a commit to branch master
in repository game-data-packager.
commit 4d9b9521ef130106a62ef1a2ffec30b6ad7f6e2c
Author: Alexandre Detiste <alexandre.detiste at gmail.com>
Date: Sun Jan 10 18:56:09 2016 +0100
avoid calling external shell with find,xargs,md5sum *
we already know the md5's for most of these files;
at least the biggest ones
---
debian/changelog | 1 +
game_data_packager/__init__.py | 4 ++++
game_data_packager/build.py | 32 +++++++++++++++++++++++++-------
3 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 7465db1..d3062f8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -79,6 +79,7 @@ game-data-packager (44) UNRELEASED; urgency=medium
* man pages: install man pages in Makefile
* refactor packaging for various games
* re-add Doom 2 - MasterLevels launcher icon that got lost in v42 or v43
+ * avoid computing known md5 again in our dh_md5sums implementation
[ Simon McVittie ]
* quake, quake2: make aliases consistently strings
diff --git a/game_data_packager/__init__.py b/game_data_packager/__init__.py
index 5dbda15..b3500eb 100644
--- a/game_data_packager/__init__.py
+++ b/game_data_packager/__init__.py
@@ -313,6 +313,10 @@ class GameDataPackage(object):
# archives actually used to built a package
self.used_sources = set()
+ # Remember the md5 of installed files
+ # that will end up in DEBIAN/md5sums
+ self.md5sums = dict()
+
@property
def aliases(self):
return self._aliases
diff --git a/game_data_packager/build.py b/game_data_packager/build.py
index 5bae6b1..af73c78 100644
--- a/game_data_packager/build.py
+++ b/game_data_packager/build.py
@@ -1576,15 +1576,28 @@ class PackagingTask(object):
return specfile
def fill_dest_dir_deb(self, package, destdir):
+ # same output as in dh_md5sums
+
+ # we only compute here the md5 we don't have yet,
+ # for the (small) GDP-generated files
+ for dirpath, dirnames, filenames in os.walk(destdir):
+ for fn in filenames:
+ full = os.path.join(dirpath, fn)
+ if os.path.islink(full):
+ continue
+ file = full[len(destdir)+1:]
+ if file not in package.md5sums:
+ with open(full, 'rb') as opened:
+ hf = HashedFile.from_file(full, opened)
+ package.md5sums[file] = hf.md5
+
debdir = os.path.join(destdir, 'DEBIAN')
mkdir_p(debdir)
-
- # adapted from dh_md5sums
- 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)
+ md5sums = os.path.join(destdir, 'DEBIAN/md5sums')
+ with open(md5sums, 'w', encoding='utf8') as outfile:
+ for file in sorted(package.md5sums.keys()):
+ outfile.write('%s %s\n' % (package.md5sums[file], file))
+ os.chmod(md5sums, 0o644)
try:
control_in = open(self.get_control_template(package),
@@ -1614,10 +1627,12 @@ class PackagingTask(object):
if wanted.name in self.found:
copy_from = self.found[wanted.name]
+ md5 = wanted.md5
else:
for alt in wanted.alternatives:
if alt in self.found:
copy_from = self.found[alt]
+ md5 = self.game.files[alt].md5
if wanted.install_as == '$alternative':
install_as = self.game.files[alt].install_as
break
@@ -1657,6 +1672,9 @@ class PackagingTask(object):
else:
os.chmod(copy_to, 0o644)
+ fullname = os.path.join(install_to, install_as)
+ package.md5sums[fullname] = md5
+
install_to = self.packaging.substitute(package.install_to,
package.name).lstrip('/')
--
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