4 # Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 return "\"%s\"" % str.replace("\"", "\\\"")
30 def __init__(self, filename):
31 lst = sexpr.parse(filename)
32 if lst[0][0] != "supertux-addoninfo":
33 raise Exception("not a supertux-addoninfo: %s" % lst[0][0])
36 for k, v in lst[0][1:]:
50 raise Exception("unknown tag: %s" % k)
55 def write(self, fout):
56 fout.write(" (supertux-addoninfo\n")
57 fout.write(" (id %s)\n" % escape_str(self.id))
58 fout.write(" (version %d)\n" % self.version)
59 fout.write(" (type %s)\n" % escape_str(self.type))
60 fout.write(" (title %s)\n" % escape_str(self.title))
61 fout.write(" (author %s)\n" % escape_str(self.author))
62 fout.write(" (license %s)\n" % escape_str(self.license))
63 fout.write(" (http-url %s)\n" % escape_str(self.url))
64 fout.write(" (md5 %s)\n" % escape_str(self.md5))
67 def process_addon(addon_dir, nfo, md5, url):
68 # print addon_dir, nfo
69 with open(nfo) as fin:
70 addon = Addon(fin.read())
73 addon.write(sys.stdout)
75 sys.stdout.write(";; automatically generated by build-addon-index.py\n")
76 sys.stdout.write("(supertux-addons\n")
77 for directory in sys.argv[1:]:
78 for addon_dir in os.listdir(directory):
79 zipfile = os.path.normpath(os.path.join(directory, "../repository/", addon_dir + ".zip"))
80 with open(zipfile, 'rb') as fin:
81 md5 = hashlib.md5(fin.read()).hexdigest()
82 url = "http://localhost:8000/repository/%s" % (addon_dir + ".zip")
83 nfos = glob.glob(os.path.join(directory, addon_dir, "*.nfo"))
85 raise Exception(".nfo file missing")
87 raise Exception("to many .nfo files")
90 process_addon(os.path.join(directory, addon_dir), nfos[0], md5, url)
92 sys.stderr.write("%s: ignoring addon because: %s\n" % (addon_dir, e))
93 sys.stdout.write(")\n\n;; EOF ;;\n")