From eaee9f078114863880cc790bdb7f0ffd88fa48ec Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Sun, 24 Aug 2014 09:10:20 +0200 Subject: [PATCH] build-addon-index.py will now build the .zip files from src/ --- tools/build-addon-index.py | 94 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 28 deletions(-) diff --git a/tools/build-addon-index.py b/tools/build-addon-index.py index 0159ab9d7..5e1e2f7b0 100755 --- a/tools/build-addon-index.py +++ b/tools/build-addon-index.py @@ -1,7 +1,7 @@ #!/usr/bin/env python - +# # SuperTux -# Copyright (C) 2006 Matthias Braun +# Copyright (C) 2014 Ingo Ruhnke # # 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 @@ -17,15 +17,20 @@ # along with this program. If not, see . -import sexpr -import sys -import os +import argparse import glob import hashlib +import os +import subprocess +import sys + +import sexpr + def escape_str(str): return "\"%s\"" % str.replace("\"", "\\\"") + class Addon: def __init__(self, filename): lst = sexpr.parse(filename) @@ -60,36 +65,69 @@ class Addon: fout.write(" (title %s)\n" % escape_str(self.title)) fout.write(" (author %s)\n" % escape_str(self.author)) fout.write(" (license %s)\n" % escape_str(self.license)) - fout.write(" (http-url %s)\n" % escape_str(self.url)) + fout.write(" (url %s)\n" % escape_str(self.url)) fout.write(" (md5 %s)\n" % escape_str(self.md5)) fout.write(" )\n") + -def process_addon(addon_dir, nfo, md5, url): +def process_addon(fout, addon_dir, nfo, base_url, zipdir): # print addon_dir, nfo with open(nfo) as fin: addon = Addon(fin.read()) - addon.md5 = md5 - addon.url = url - addon.write(sys.stdout) -sys.stdout.write(";; automatically generated by build-addon-index.py\n") -sys.stdout.write("(supertux-addons\n") -for directory in sys.argv[1:]: + zipfile = addon.id + "_v" + str(addon.version) + ".zip" + + # see http://pivotallabs.com/barriers-deterministic-reproducible-zip-files/ + os.remove(os.path.join(zipdir, zipfile)) + zipout = os.path.relpath(os.path.join(zipdir, zipfile), addon_dir) + subprocess.call(["zip", "-X", "-r", "--quiet", zipout, "."], cwd=addon_dir) + + with open(os.path.join(zipdir, zipfile), 'rb') as fin: + addon.md5 = hashlib.md5(fin.read()).hexdigest() + + addon.url = base_url + zipfile + + addon.write(fout) + + +def generate_index(fout, directory, base_url, zipdir): + fout.write(";; automatically generated by build-addon-index.py\n") + fout.write("(supertux-addons\n") for addon_dir in os.listdir(directory): - zipfile = os.path.normpath(os.path.join(directory, "../repository/", addon_dir + ".zip")) - with open(zipfile, 'rb') as fin: - md5 = hashlib.md5(fin.read()).hexdigest() - url = "http://localhost:8000/repository/%s" % (addon_dir + ".zip") - nfos = glob.glob(os.path.join(directory, addon_dir, "*.nfo")) - if len(nfos) == 0: - raise Exception(".nfo file missing") - elif len(nfos) > 1: - raise Exception("to many .nfo files") - else: - try: - process_addon(os.path.join(directory, addon_dir), nfos[0], md5, url) - except Exception, e: - sys.stderr.write("%s: ignoring addon because: %s\n" % (addon_dir, e)) -sys.stdout.write(")\n\n;; EOF ;;\n") + addon_dir = os.path.join(directory, addon_dir) + if os.path.isdir(addon_dir): + print addon_dir + nfos = glob.glob(os.path.join(addon_dir, "*.nfo")) + if len(nfos) == 0: + raise Exception(".nfo file missing from %s" % addon_dir) + elif len(nfos) > 1: + raise Exception("to many .nfo files in %s" % addon_dir) + else: + try: + process_addon(fout, addon_dir, nfos[0], base_url, zipdir) + except Exception, e: + sys.stderr.write("%s: ignoring addon because: %s\n" % (addon_dir, e)) + fout.write(")\n\n;; EOF ;;\n") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Addon Index/Zip Generator') + parser.add_argument('DIRECTORY', type=str, nargs=1, + help="directory containing the mods") + parser.add_argument('-o', '--output', metavar='FILE', type=str, required=False, + help="output file") + parser.add_argument('-z', '--zipdir', metavar="DIR", type=str, required=True, + help="generate zip files") + parser.add_argument('-u', '--url', metavar='FILE', type=str, + default="http://addons.supertux.googlecode.com/git/repository/", + help="base url") + args = parser.parse_args() + + if args.output is None: + fout = sys.stdout + generate_index(fout, args.DIRECTORY[0], args.url, args.zipdir) + else: + with open(args.output, "w") as fout: + generate_index(fout, args.DIRECTORY[0], args.url, args.zipdir) # EOF # -- 2.11.0