home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 July / maximum-cd-2010-07.iso / DiscContents / wesnoth-1.8-win32.exe / data / tools / addon_manager / html.py < prev    next >
Encoding:
Python Source  |  2009-09-28  |  7.2 KB  |  167 lines

  1. # encoding: utf8
  2. import time, os, glob, sys
  3. from subprocess import Popen
  4.  
  5. def output(path, url, data):
  6.     try: os.mkdir(path)
  7.     except OSError: pass
  8.  
  9.     f = open(path + "/index.html", "w")
  10.     def w(x):
  11.         f.write(x + "\n")
  12.     w("""\
  13. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  14. <html>
  15. <head>
  16. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  17. <link rel=stylesheet href="style.css" type="text/css">
  18. <script type="text/javascript" src="jquery.js"></script>
  19. <script type="text/javascript" src="tablesorter.js"></script>
  20. <script type="text/javascript">
  21. $(document).ready(function() 
  22.     $("#campaigns").tablesorter(
  23.     {
  24.         headers: { 1: { sorter: false} }
  25.     }
  26.     ); 
  27. ); 
  28. </script>
  29. </head>
  30. <body>""")
  31.  
  32.     w("""\
  33. <div class="header">
  34. <a href="http://www.wesnoth.org">
  35. <img src="http://www.wesnoth.org/mw/skins/glamdrol/wesnoth-logo.jpg" alt="Wesnoth logo"/>
  36. </a>
  37. </div>
  38. <div class="topnav">
  39. <a href="index.html">Wesnoth Addons</a>
  40. </div>
  41. <div class="main">
  42. <p>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.
  43. 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!</p>
  44. <p>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.</p>
  45. """)
  46.     if url:
  47.         w("""<p>PS: If you really have to download an add-on from here uncompress it to the <a href="http://www.wesnoth.org/wiki/EditingWesnoth#Where_is_my_user_data_directory.3F">userdata</a>/data/add-ons/ directory for wesnoth to find it.
  48. """)
  49.  
  50.     am_dir = os.path.dirname(__file__) + "/"
  51.     for name in ["style.css", "jquery.js", "tablesorter.js",
  52.         "asc.gif", "bg.gif", "desc.gif"]:
  53.         Popen(["cp", "-u", am_dir + name, path])
  54.  
  55.     campaigns = data.get_or_create_sub("campaigns")
  56.     w("<table class=\"tablesorter\" id=\"campaigns\">")
  57.     w("<thead>")
  58.     w("<tr>")
  59.     for header in ["Type", "Icon", "Addon", "Size", "Traffic", "Date", "Notes"]:
  60.         w("<th>%s   </th>" % header)
  61.     w("</tr>")
  62.     w("</thead>")
  63.     w("<tbody>")
  64.     root_dir = am_dir + "../../../"
  65.     for campaign in campaigns.get_all("campaign"):
  66.         v = campaign.get_text_val
  67.         translations = campaign.get_all("translation")
  68.         languages = [x.get_text_val("language") for x in translations]
  69.         w("<tr>")
  70.         icon = v("icon", "")
  71.         imgurl = ""
  72.         if icon:
  73.             icon = icon.strip()
  74.             tilde = icon.find("~")
  75.             if tilde >= 0: icon = icon[:tilde]
  76.             try: os.mkdir(path + "/icons")
  77.             except OSError: pass
  78.             if "." not in icon: icon += ".png"
  79.             src = root_dir + icon
  80.             imgurl = "icons/" + os.path.basename(icon)
  81.             if not os.path.exists(src):
  82.                 src = root_dir + "data/core/images/" + icon
  83.             if not os.path.exists(src):
  84.                 src = root_dir + "images/" + icon
  85.             if not os.path.exists(src):
  86.                 src = glob.glob(root_dir + "data/campaigns/*/images/" + icon)
  87.                 if src: src = src[0]
  88.                 if not src or not os.path.exists(src):
  89.                     sys.stderr.write("Cannot find icon " + icon + "\n")
  90.                     src = root_dir + "images/misc/missing-image.png"
  91.                     imgurl = "icons/missing-image.png"
  92.             Popen([os.path.join(am_dir, "../unit_tree/TeamColorizer"),
  93.                 src, path + "/" + imgurl])
  94.                 
  95.         type = v("type", "none")
  96.         size = float(v("size", "0"))
  97.         name = v("title", "unknown")
  98.         if type == "scenario":
  99.             w("""\
  100. <td>Scenario<div class="type"><b>single player scenario</b><br/>
  101. 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.)</div></td>""")
  102.         elif type == "campaign":
  103.             w("""\
  104. <td>Campaign<div class="type"><b>single player campaign</b><br/>
  105. After install the campaign will show up in the list you get when choosing "Campaign" in the main menu.</div></td>""")
  106.         elif type == "campaign_mp":
  107.             w("""\
  108. <td>MP Campaign<div class="type"><b>multiplayer campaign</b><br/>
  109. After install the first scenario of the campaign will be available in the map list in the multiplayer "Create Game" dialog.</div></td>""")
  110.         elif type == "scenario_mp":
  111.             w("""\
  112. <td>MP Scenario<div class="type"><b>multiplayer scenario</b><br/>
  113. After install the scenario will be available in the map list in the multiplayer "Create Game" dialog.</div></td>""")
  114.         elif type == "map_pack":
  115.             w("""\
  116. <td>MP map-pack<div class="type"><b>multiplayer map pack</b><br/>
  117. After install the maps/scenarios will be available in the map list in the multiplayer "Create Game" dialog.</div></td>""")
  118.         elif type == "era":
  119.             w("""\
  120. <td>MP era<div class="type"><b>multiplayer era</b><br/>
  121. After install the included era(s) will be available in the multiplayer "Create Game" dialog.</div></td>""")
  122.         elif type == "faction":
  123.             w("""\
  124. <td>MP faction<div class="type"><b>multiplayer faction</b><br/>
  125. Usually comes with an era or is dependency of another add-on.</div></td>""")
  126.         elif type == "media":
  127.             w("""\
  128. <td>Resources<div class="type"><b>miscellaneous content/media</b><br/>
  129. unit packs, terrain packs, music packs, etc. Usually a (perhaps optional) dependency of another add-on.</div></td>""")
  130.         else: w(('<td>%s</td>') % type)
  131.         w(('<td><img alt="%s" src="%s" width="72px" height="72px"/>'
  132.             ) % (icon, imgurl))
  133.         w('<div class="desc"><b>%s</b><br/>%s</div></td>' % (
  134.             name, v("description", "(no description)")))
  135.         w("<td><b>%s</b><br/>" % name)
  136.         w("Version: %s<br/>" % v("version", "unknown"))
  137.         w("Author: %s</td>" % v("author", "unknown"))
  138.         MiB = 1024 * 1024
  139.         w("<td><span class=\"hidden\">%d</span><b>%.2f</b>MiB" % (size, size / MiB))
  140.         if url:
  141.             link = url.rstrip("/") + "/" + v("name") + ".tar.bz2"
  142.             w("<br/><a href=\"%s\">download</a></td>" % link)
  143.         else:
  144.             w("</td>")
  145.         downloads = int(v("downloads", "0"))
  146.         w("<td><b>%d</b> down<br/>" % (downloads))
  147.         w("%s up</td>" % v("uploads", "unknown"))
  148.         timestamp = int(v("timestamp", "0"))
  149.         t = time.localtime(timestamp)
  150.         w("<td><span class=\"hidden\">%d</span>%s</td>" % (timestamp,
  151.             time.strftime("%b %d %Y", t)))
  152.         w("<td>%s</td>" % (", ".join(languages)))
  153.         w("</tr>")
  154.     w("</tbody>")
  155.     w("</table>")
  156.  
  157.     w("""\
  158. </div>
  159. <div id="footer">
  160. <p><a href="http://www.wesnoth.org/wiki/Site_Map">Site map</a></p>
  161. <p><a href="http://www.wesnoth.org/wiki/Wesnoth:Copyrights">Copyright</a> © 2003-2009 The Battle for Wesnoth</p>
  162. <p>Supported by <a href="http://www.jexiste.fr/">Jexiste</a></p>
  163. </div>
  164. </body></html>""")
  165.