Added two options to wesnto_addon_manager:

--tar Causes tarballs to be generated for each addon newly downloaded
with --download.

--url=... Adds download links to the --html output, with the given
base URL.
This commit is contained in:
Elias Pschernig 2008-10-09 19:09:00 +00:00
parent 98620b3391
commit a33b05979b
2 changed files with 26 additions and 7 deletions

View file

@ -1,6 +1,6 @@
import time, os, glob, sys
def output(path, data):
def output(path, url, data):
try: os.mkdir(path)
except OSError: pass
@ -74,7 +74,13 @@ Select the add-on you want to install from the list and click "OK". The download
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))
MB = 1024 * 1024
w("<td>%.2fMB" % (float(v("size", "unknown")) / MB))
if url:
link = url.rstrip("/") + "/" + v("name") + ".tar.bz2"
w("<br/><a href=\"%s\">download</a></td>" % link)
else:
w("</td>")
w("<td><b>%s</b> down<br/>" % v("downloads", "unknown"))
w("%s up</td>" % v("uploads", "unknown"))
t = time.localtime(int(v("timestamp", "unknown")))

View file

@ -28,7 +28,7 @@ if __name__ == "__main__":
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.",)
help = "Output a HTML overview into the given directory.",)
optionparser.add_option("-p", "--port",
help = "specify server port or BfW version (%s)" % " or ".join(
map(lambda x: x[1], CampaignClient.portmap)),
@ -51,6 +51,9 @@ if __name__ == "__main__":
"name may be a Python regexp matched against all add-on names " +
"(specify the path where to put it with -c, " +
"current directory will be used by default)")
optionparser.add_option("-t", "--tar", action = "store_true",
help = "When used together with --download, create tarballs of any " +
"downloaded addons.")
optionparser.add_option("-u", "--upload",
help = "Upload an add-on. " +
"UPLOAD should be either the name of an add-on subdirectory," +
@ -73,6 +76,9 @@ if __name__ == "__main__":
optionparser.add_option("-R", "--raw-download",
action = "store_true",
help = "download as a binary WML packet")
optionparser.add_option("--url", help = "When used with --html, " +
"a download link will be added for each campaign, with the given " +
"base URL.")
optionparser.add_option("-U", "--unpack",
help = "unpack the file UNPACK as a binary WML packet " +
"(specify the add-on path with -c)")
@ -110,9 +116,9 @@ if __name__ == "__main__":
else:
decoded = cs.decode(mythread.data)
print "Unpacking %s..." % name
cs.unpackdir(decoded, cdir, verbose = options.verbose)
d = os.path.join(cdir, name)
info = os.path.join(d, "_info.cfg")
cs.unpackdir(decoded, cdir, verbose = options.verbose)
dirname = os.path.join(cdir, name)
info = os.path.join(dirname, "_info.cfg")
try:
f = file(info, "w")
f.write("[info]\nversion=\"%s\"\nuploads=\"%s\"\n[/info]\n" %
@ -123,6 +129,13 @@ if __name__ == "__main__":
for message in decoded.find_all("message", "error"):
print message.get_text_val("message")
if options.tar:
tarname = cdir + "/" + name + ".tar.bz2"
if options.verbose:
sys.stderr.write("Creating tarball %(tarname)s.\n" %
locals())
os.system("tar cjf %(tarname)s %(dirname)s" % locals())
def get_info(name):
"""
Get info for a locally installed add-on. It expects a direct path
@ -144,7 +157,7 @@ if __name__ == "__main__":
data = cs.list_campaigns()
if data:
import addon_manager.html
addon_manager.html.output(options.html, data)
addon_manager.html.output(options.html, options.url, data)
else:
sys.stderr.write("Could not connect.\n")