# encoding: utf8 import time, os, glob, sys def output(path, url, data): try: os.mkdir(path) except OSError: pass f = open(path + "/index.html", "w") def w(x): f.write(x + "\n") w("""\ """) w("""\
Wesnoth logo
Wesnoth Addons

To install an add-on please go to the title screen of Battle for Wesnoth. Select "Add-ons" from the menu and click "OK" to connect to add-ons.wesnoth.org. Select the add-on you want to install from the list and click "OK". The download will commence immediately. Wesnoth will then automatically install and load the add-on so you can use it.

Note: Hover over the icons to see the description of the add-on.

""") for name in ["style.css", "jquery.js", "tablesorter.js", "asc.gif", "bg.gif", "desc.gif"]: os.system("cp -u data/tools/addon_manager/" + name + " " + path) campaigns = data.get_or_create_sub("campaigns") w("") w("") w("") for header in ["Icon", "Addon", "Size", "Traffic", "Date", "Notes"]: w("" % header) w("") w("") w("") for campaign in campaigns.get_all("campaign"): v = campaign.get_text_val w("") icon = v("icon", "") if icon: tilde = icon.find("~") if tilde >= 0: icon = icon[:tilde] try: os.mkdir(path + "/icons") except OSError: pass if "." not in icon: icon += ".png" src = "./data/core/images/" + icon if not os.path.exists(src): src = glob.glob("./data/campaigns/*/images/" + icon) if src: src = src[0] if not src or not os.path.exists(src): sys.stderr.write("Cannot find icon " + icon + "\n") src = "./images/misc/missing-image.png" imgurl = "icons/missing-image.png" else: imgurl = "icons/" + os.path.basename(icon) else: imgurl = "icons/" + os.path.basename(icon) os.system("cp -u " + src + " " + path + "/icons") name = v("title", "unknown") w(('' % ( name, v("description", "(no description)"))) w("" % v("author", "unknown")) MiB = 1024 * 1024 w("" % link) else: w("") downloads = int(v("downloads", "0")) w("" % v("uploads", "unknown")) timestamp = int(v("timestamp", "0")) t = time.localtime(timestamp) w("" % (timestamp, time.strftime("%b %d %Y", t))) w("" % v("translate", "")) w("") w("") w("
%s   
%s' ) % (icon, imgurl)) w('
%s
%s
%s
" % name) w("Version: %s
" % v("version", "unknown")) w("Author: %s
%.2fMiB" % (float(v("size", "unknown")) / MiB)) if url: link = url.rstrip("/") + "/" + v("name") + ".tar.bz2" w("
download
%d down
" % (downloads)) w("%s up
%d%s%s
") w("""\
""")