[game-data-packager] 03/03: add tools/mirror.py, part of #787990

Alexandre Detiste detiste-guest at moszumanska.debian.org
Tue Nov 10 07:18:44 UTC 2015


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 23e06d0b1b93ffd3d999aa91622bd7cdf1b0377f
Author: Alexandre Detiste <alexandre.detiste at gmail.com>
Date:   Tue Nov 10 08:16:16 2015 +0100

    add tools/mirror.py, part of #787990
    
    this tool will create/verify of a all downloadable files
    by default files are stored in /var/www/html
    
    if a webserver is running, this host can then be
    referenced from an other host by setting accordingly
    the GDP_MIRROR= variable
---
 tools/mirror.py | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 91 insertions(+)

diff --git a/tools/mirror.py b/tools/mirror.py
new file mode 100755
index 0000000..2137c6e
--- /dev/null
+++ b/tools/mirror.py
@@ -0,0 +1,91 @@
+#!/usr/bin/python3
+# encoding=utf-8
+#
+# Copyright © 2015 Alexandre Detiste <alexandre at detiste.be>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# You can find the GPL license text on a Debian system under
+# /usr/share/common-licenses/GPL-2.
+
+# a small tool to create or verify a mirror
+# of downloadable files needed by GDP
+
+# call it this way:
+#   GDP_UNINSTALLED=1 python3 -m tools.mirror
+
+# this tool will never remove any bad file,
+# you'll have to investigate by yourself
+
+WEBROOT = '/var/www/html'
+
+import os
+import subprocess
+
+from game_data_packager import (load_games,HashedFile)
+from game_data_packager.build import (choose_mirror)
+
+archives = []
+
+os.environ.pop('GDP_MIRROR')
+
+for gamename, game in load_games().items():
+    game.load_file_data()
+    for filename, file in game.files.items():
+        if file.unsuitable:
+            # quake2-rogue-2.00.tar.xz could have been tagged this way
+            archive = os.path.join(WEBROOT, filename)
+            if os.path.isfile(archive):
+                print('Obsolete archive: %s (%s)' % (archive, file.unsuitable))
+        elif filename == 'tnt31fix.zip?repack':
+            continue
+        elif file.download:
+            url = choose_mirror(file)[0]
+            if '?' not in url:
+                destname = os.path.basename(url)
+            elif '?' not in filename:
+                destname = filename
+            elif url.endswith('?download'):
+                destname = os.path.basename(url)
+                destname = destname[0:len(destname)-len('?download')]
+            else:
+                exit("Can't compute filename for %s = %s" % (filename, url))
+            archives.append({
+             'name': destname,
+             'size': file.size,
+             'md5': file.md5,
+             'sha1': file.sha1,
+             'download': url,
+             })
+
+archives = sorted(archives, key=lambda k: (k['size']))
+
+for a in archives:
+   archive = os.path.join(WEBROOT, a['name'])
+
+   if not os.path.isfile(archive):
+       statvfs = os.statvfs(WEBROOT)
+       freespace = statvfs.f_frsize * statvfs.f_bavail
+       if a['size'] > freespace:
+           exit('out of space, can not download' % a['name'])
+       subprocess.check_call(['wget', a['download'],
+                              '-O', a['name']],
+                              cwd=WEBROOT)
+
+   if os.path.getsize(archive) == 0:
+       exit("%s is empty !!!" % archive)
+   if os.path.getsize(archive) != a['size']:
+       exit("%s has the wrong size !!!" % archive)
+   hf = HashedFile.from_file(archive, open(archive, 'rb'))
+   print('checking %s ...' % archive)
+   if a['md5'] and a['md5'] != hf.md5:
+       exit("md5 doesn't match for %s !!!" % archive)
+   if a['sha1'] and a['sha1'] != hf.sha1:
+       exit("sha1 doesn't match for %s !!!" % archive)

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