# encoding: utf-8 import time, os, glob, sys, re from subprocess import Popen 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("Add-ons for Wesnoth %s" % os.path.basename(path)) 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. Remember that not all add-ons are campaigns!

Note: Hover over the type field to see an explanation of the type and over an icon to see the description of the add-on.

""") if url: w("""

PS: If you really have to download an add-on from here uncompress it to the userdata/data/add-ons/ directory for wesnoth to find it. """) am_dir = os.path.dirname(__file__) + "/" for name in ["style.css", "jquery.js", "tablesorter.js", "asc.gif", "bg.gif", "desc.gif"]: Popen(["cp", "-u", am_dir + name, path]) campaigns = data.get_all(tag = "campaigns")[0] w("") w("") w("") for header in ["Type", "Icon", "Addon", "Size", "Traffic", "Date", "Notes"]: w("" % header) w("") w("") w("") root_dir = am_dir + "../../../" images_to_tc = [] for campaign in campaigns.get_all(tag = "campaign"): v = campaign.get_text_val translations = campaign.get_all(tag = "translation") languages = [x.get_text_val("language") for x in translations] w("") icon = v("icon", "") imgurl = "" if icon: icon = icon.strip() tilde = icon.find("~") if tilde >= 0: icon = icon[:tilde] if "\\" in icon: icon = icon.replace("\\", "/") try: os.mkdir(path + "/icons") except OSError: pass if "." not in icon: icon += ".png" src = root_dir + icon imgurl = "icons/" + os.path.basename(icon) if not os.path.exists(src): src = root_dir + "data/core/images/" + icon if not os.path.exists(src): src = root_dir + "images/" + icon if not os.path.exists(src): src = glob.glob(root_dir + "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 = root_dir + "images/misc/missing-image.png" imgurl = "icons/missing-image.png" images_to_tc.append( (src, path + "/" + imgurl) ) type = v("type", "none") size = float(v("size", "0")) name = v("title", "unknown") if type == "scenario": w("""\ """) elif type == "campaign": w("""\ """) elif type == "campaign_sp_mp": w("""\ """) elif type == "campaign_mp": w("""\ """) elif type == "scenario_mp": w("""\ """) elif type == "map_pack": w("""\ """) elif type == "era": w("""\ """) elif type == "faction": w("""\ """) elif type == "mod_mp": w("""\ """) elif type == "media": w("""\ """) else: w(('') % type) w(('' % ( name, described)) 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("" % (", ".join(languages))) w("") w("") w("
%s   
Scenario
single player scenario
After install the scenario will show up in the list you get when choosing "Campaign" in the main menu. (Basically it's just a campaign with only one scenario.)
Campaign
single player campaign
After install the campaign will show up in the list you get when choosing "Campaign" in the main menu.
SP/SP Campaign
single/multi player campaign
After install the campaign will show up both in the list you get when choosing "Campaign" in the main menu, and in the map list in the multiplayer "Create Game" dialog.
MP Campaign
multiplayer campaign
After install the first scenario of the campaign will be available in the map list in the multiplayer "Create Game" dialog.
MP Scenario
multiplayer scenario
After install the scenario will be available in the map list in the multiplayer "Create Game" dialog.
MP map-pack
multiplayer map pack
After install the maps/scenarios will be available in the map list in the multiplayer "Create Game" dialog.
MP era
multiplayer era
After install the included era(s) will be available in the multiplayer "Create Game" dialog.
MP faction
multiplayer faction
Usually comes with an era or is dependency of another add-on.
MP modification
multiplayer modification
After install the included MP gameplay modification(s) will be available in the multiplayer "Create Game" dialog.
Resources
miscellaneous content/media
Unit packs, terrain packs, music packs, etc. Usually a (perhaps optional) dependency of another add-on.
%s%s' ) % (icon, imgurl)) described = v("description", "(no description)") if described != "(no description)": described = re.sub(r'(?])http://([\w/=%~-]|[.?&]\w)+', r'\g<0>', described) described = re.sub(r'(?"/])(forums?|r|R|wiki)\.wesnoth\.org([\w/=%~-]|[.?&]\w)*', r'\g<0>', described) w('
%s
%s
%s
" % name) w("Version: %s
" % v("version", "unknown")) w("Author: %s
%d%.2fMiB" % (size, size / MiB)) if url: link = url.rstrip("/") + "/" + v("name") + ".tar.bz2" w("
download
%d down
" % (downloads)) w("%s up
%d%s%s
") w("""\

""") sys.stderr.write("Done outputting html, now generating %d TC'ed images\n" % len(images_to_tc)) for pair in images_to_tc: Popen([os.path.join(am_dir, "../unit_tree/TeamColorizer"), pair[0], pair[1]]).wait() # wait() to ensure only one process is exists at any time