Backported --html options of addon manager to 1.4.
This commit is contained in:
parent
7bbbdddfbb
commit
4b54a8b042
4 changed files with 170 additions and 1 deletions
|
@ -17,6 +17,8 @@ if __name__ == "__main__":
|
|||
optionparser = optparse.OptionParser()
|
||||
optionparser.add_option("-a", "--address", help = "specify server address",
|
||||
default = "add-ons.wesnoth.org")
|
||||
optionparser.add_option("--html",
|
||||
help = "Output HTML overview into the givendirectory.",)
|
||||
optionparser.add_option("-p", "--port",
|
||||
help = "specify server port or BfW version (%s)" % " or ".join(
|
||||
map(lambda x: x[1], CampaignClient.portmap)),
|
||||
|
@ -125,7 +127,15 @@ if __name__ == "__main__":
|
|||
version = info.get_or_create_sub("info").get_text_val("version", "")
|
||||
return uploads, version
|
||||
|
||||
if options.list:
|
||||
if options.html:
|
||||
cs = CampaignClient(address)
|
||||
data = cs.list_campaigns()
|
||||
if data:
|
||||
import campaigns_client.html
|
||||
campaigns_client.html.output(options.html, data)
|
||||
else:
|
||||
sys.stderr.write("Could not connect.\n")
|
||||
elif options.list:
|
||||
cs = CampaignClient(address)
|
||||
data = cs.list_campaigns()
|
||||
if data:
|
||||
|
|
1
utils/campaigns_client/__init__.py
Normal file
1
utils/campaigns_client/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# This let's python know about the addon_manager module.
|
89
utils/campaigns_client/html.py
Normal file
89
utils/campaigns_client/html.py
Normal file
|
@ -0,0 +1,89 @@
|
|||
import time, os, glob, sys
|
||||
|
||||
def output(path, data):
|
||||
try: os.mkdir(path)
|
||||
except OSError: pass
|
||||
|
||||
f = open(path + "/index.html", "w")
|
||||
def w(x):
|
||||
f.write(x + "\n")
|
||||
w("""\
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<link rel=stylesheet href=\"style.css\" type=\"text/css\">
|
||||
</head>
|
||||
<body>""")
|
||||
|
||||
w("""\
|
||||
<div class="header">
|
||||
<a href="http://www.wesnoth.org">
|
||||
<img src="http://www.wesnoth.org/mw/skins/glamdrol/wesnoth-logo.jpg" alt="Wesnoth logo"/>
|
||||
</a>
|
||||
</div>
|
||||
<div class="topnav">
|
||||
<a href="index.html">Wesnoth Addons</a>
|
||||
</div>""")
|
||||
|
||||
os.system("cp -u utils/campaigns_client/style.css " + path)
|
||||
|
||||
campaigns = data.get_or_create_sub("campaigns")
|
||||
w("<table id=\"campaigns\">")
|
||||
w("<tr>")
|
||||
w("<th></th>")
|
||||
w("<th>Addon</th>")
|
||||
w("<th>Size</th>")
|
||||
w("<th>Traffic</th>")
|
||||
w("<th>Date</th>")
|
||||
w("<th>Notes</th>")
|
||||
w("</tr>")
|
||||
for campaign in campaigns.get_all("campaign"):
|
||||
v = campaign.get_text_val
|
||||
w("<tr>")
|
||||
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 = "./data/core/images/units/random-enemy.png"
|
||||
imgurl = "icons/random-enemy.png"
|
||||
else:
|
||||
imgurl = "icons/" + os.path.basename(icon)
|
||||
else:
|
||||
imgurl = "icons/" + os.path.basename(icon)
|
||||
os.system("cp -u " + src + " " + path + "/icons")
|
||||
|
||||
name = v("name", "unknown").replace("_", " ")
|
||||
w(('<td><img alt="%s" src="%s" width="72px" height="72px"/>'
|
||||
) % (icon, imgurl))
|
||||
w('<div class="desc"><b>%s</b><br/>%s</div></td>' % (
|
||||
name, v("description", "(no description)")))
|
||||
w("<td><b>%s</b><br/>" % name)
|
||||
w("Version: %s<br/>" % v("version", "unknown"))
|
||||
w("Author: %s</td>" % v("author", "unknown"))
|
||||
w("<td>%.1fMB</td>" % (float(v("size", "unknown")) / 1024 / 1024))
|
||||
w("<td><b>%s</b> down<br/>" % v("downloads", "unknown"))
|
||||
w("%s up</td>" % v("uploads", "unknown"))
|
||||
t = time.localtime(int(v("timestamp", "unknown")))
|
||||
w("<td>%s</td>" % time.strftime("%b %d %Y", t))
|
||||
w("<td>%s</td>" % v("translate", ""))
|
||||
w("</tr>")
|
||||
w("</table>")
|
||||
|
||||
w("""\
|
||||
<div id="footer">
|
||||
<p><a href="http://www.wesnoth.org/wiki/Site_Map">Site map</a></p>
|
||||
<p><a href="http://www.wesnoth.org/wiki/Wesnoth:Copyrights">Copyright</a> © 2003-2008 The Battle for Wesnoth</p>
|
||||
<p>Supported by <a href="http://www.jexiste.fr/">Jexiste</a></p>
|
||||
<p><a href="http://www.ibiblio.org/"><img src="http://www.ibiblio.org/hosted/images/ibiblio_hosted-110x32.png" width="110" height="32" border="0" alt="hosted by ibiblio" /></a></p>
|
||||
</div>
|
||||
</body></html>""")
|
69
utils/campaigns_client/style.css
Normal file
69
utils/campaigns_client/style.css
Normal file
|
@ -0,0 +1,69 @@
|
|||
body {
|
||||
background-color: #fffbf0;
|
||||
margin: 0px;
|
||||
}
|
||||
h1 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
div.header {
|
||||
background:#444444 url("http://www.wesnoth.org/mw/skins/glamdrol/headerbg.jpg") repeat-x scroll center top;
|
||||
border-bottom:1px solid #000000;
|
||||
margin:0pt;
|
||||
padding:0pt;
|
||||
width:100%;
|
||||
text-align: center;
|
||||
}
|
||||
div.topnav {
|
||||
background:#272727 url("http://www.wesnoth.org/mw/skins/glamdrol/navbg.png") repeat-x scroll center bottom;
|
||||
border-top:1px solid #595959;
|
||||
margin:0pt;
|
||||
padding:3px 4px 15px;
|
||||
text-align:center;
|
||||
}
|
||||
div.topnav a {
|
||||
color:#B48648;
|
||||
font-family:"Trebuchet MS",sans-serif;
|
||||
line-height:0.8em;
|
||||
font-size:0.8em;
|
||||
font-weight:bold;
|
||||
text-decoration:none;
|
||||
}
|
||||
div.topnav a:hover {
|
||||
color:#CCCCCC;
|
||||
}
|
||||
img {
|
||||
border: none;
|
||||
}
|
||||
div.header img {
|
||||
vertical-align:middle;
|
||||
}
|
||||
|
||||
div#footer {
|
||||
clear: both;
|
||||
font-size: x-small;
|
||||
border-top: 1px solid black;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
table#campaigns th {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
table#campaigns td img {
|
||||
float: left;
|
||||
}
|
||||
|
||||
div.desc {
|
||||
display: none;
|
||||
}
|
||||
|
||||
td:hover div.desc {
|
||||
display: block;
|
||||
left: 72px;
|
||||
position: absolute;
|
||||
width: 20em;
|
||||
background-color: #ffffff;
|
||||
border: 1px solid black;
|
||||
padding: 8px;
|
||||
}
|
Loading…
Add table
Reference in a new issue