Author: elias
Date: Mon Oct 6 21:20:57 2008
New Revision: 29925
URL: http://svn.gna.org/viewcvs/wesnoth?rev=29925&view=rev
Log:
Another go at bug #12205 - now uploading with the -u option should work again,
for what it's worth.
Modified:
trunk/data/tools/wesnoth/campaignserver_client.py
trunk/data/tools/wesnoth/wmldata.py
trunk/data/tools/wesnoth_addon_manager
Modified: trunk/data/tools/wesnoth/campaignserver_client.py
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wesnoth/campaignserver_client.py?rev=29925&r1=29924&r2=29925&view=diff
==============================================================================
--- trunk/data/tools/wesnoth/campaignserver_client.py (original)
+++ trunk/data/tools/wesnoth/campaignserver_client.py Mon Oct 6 21:20:57 2008
@@ -78,15 +78,6 @@
except socket.error:
pass # Well, what can we do?
- def isBWML( self, packet ):
- """
- Return True if packet is encoded as binary WML. Else
- return False.
- """
- if packet[0] in "\x00\x01\x02\x03":
- return True
-
- return False
def make_packet(self, doc):
root = wmldata.DataSub("WML")
@@ -148,14 +139,9 @@
return packet
def decode( self, data ):
- if self.isBWML(data):
- if self.verbose:
- sys.stderr.write("Decoding binary WML...\n")
- data = self.decode_BWML( data )
- else:
- if self.verbose:
- sys.stderr.write("Decoding text WML...\n")
- data = self.decode_WML( data )
+ if self.verbose:
+ sys.stderr.write("Decoding text WML...\n")
+ data = self.decode_WML( data )
return data
@@ -183,32 +169,6 @@
p.parse_top(doc)
return doc
-
- def decode_BWML(self, data):
- """
- Given a block of binary data, decode it as binary WML
- and return it as a WML object.
-
- The binary WML format is a byte stream. The format is:
- 0 3 <name> means a new element <name> is opened
- 0 4..255 means the same as 0 3 but with a coded name
- 1 means the current element is closed
- 2 <name> means, add a new code for <name> to the dictionary
- 3 <name> <data> means, a new attribute <name> is added with <data>
- 4..255 <data> means, the same as above but with a coded name
-
- For example if we got:
- [message]text=blah[/message]
- [message]text=bleh[/message]
- It would look like:
- 0 2 message 4 2 text 5 blah 1 0 4 5 bleh 1
- This would be the same:
- 0 3 message 3 text blah 1 0 3 message 3 text bleh 1
- """
- WML = wmldata.DataSub("campaign_server")
- pos = [0]
- tag = [WML]
- open_element = False
def done():
return pos[0] >= len(data)
@@ -265,48 +225,6 @@
"""
pass
- def encode_BWML(self, data):
- """
- Given a WML object, encode it into binary WML
- and return it as a python string.
- """
- packet = str("")
-
- def literal(data):
- if not data:
- return str("")
- data = data.replace("\01", "\01\02")
- data = data.replace("\00", "\01\01")
- return str(data)
-
- def encode(name):
- if name in self.codes:
- return self.codes[name]
- what = literal(name)
- # Gah.. why didn't nobody tell me about the 20 characters limit?
- # Without adhering to this (hardcoded in the C++ code) limit, the
- # campaign server simply will crash if we talk to it.
- if len(what) <= 20 and self.codescount < 256:
- data = "\02" + what + "\00" + chr(self.codescount)
- self.codes[name] = chr(self.codescount)
- self.codescount += 1
- return data
- return "\03" + what + "\00"
-
- if isinstance(data, wmldata.DataSub):
- packet += "\00" + encode(data.name)
- for item in data.data:
- encoded = self.encode_BWML(item)
- packet += encoded
- packet += "\01"
- elif isinstance(data, wmldata.DataText):
- packet += encode(data.name)
- packet += literal(data.data) + "\00"
- elif isinstance(data, wmldata.DataBinary):
- packet += encode(data.name)
- packet += literal(data.data) + "\00"
- return packet
-
def encode( self, data ):
"""
Always encode GZIP compressed - future use ZLIB
@@ -403,6 +321,9 @@
request.set_text_val("title", title)
request.set_text_val("version", version)
request.set_text_val("icon", icon)
+
+ data = wmldata.DataSub("data")
+ request.insert(data)
def put_file(name, f):
fileNode = wmldata.DataSub("file")
@@ -412,8 +333,9 @@
contents = contents.replace("\x01", "\x01\x02" )
contents = contents.replace("\x00", "\x01\x01")
contents = contents.replace("\x0d", "\x01\x0e")
-
- fileContents = wmldata.DataText( "contents", contents )
+ contents = contents.replace("\xfe", "\x01\xff")
+
+ fileContents = wmldata.DataText("contents", contents)
fileNode.insert(fileContents)
fileNode.set_text_val("name", name)
@@ -425,7 +347,7 @@
for fn in glob.glob(path + "/*"):
if os.path.isdir(fn):
sub = put_dir(os.path.basename(fn), fn)
- elif filter(lambda x: fn.endswith(x), CampaignClient.excluded):
+ elif [x for x in CampaignClient.excluded if fn.endswith(x)]:
continue
else:
sub = put_file(os.path.basename(fn), file(fn))
@@ -434,11 +356,11 @@
# Only used if it's an old-style campaign directory
# with an external config.
- if os.path.exists(cfgfile):
- request.insert(put_file(name + ".cfg", file(cfgfile)))
+ if cfgfile:
+ data.insert(put_file(name + ".cfg", file(cfgdile)))
sys.stderr.write("Adding directory %s as %s.\n" % (directory, name))
- request.insert(put_dir(name, directory))
+ data.insert(put_dir(name, directory))
packet = self.make_packet(request)
sys.stderr.write("Packet length is %d bytes.\n" % len(packet))
Modified: trunk/data/tools/wesnoth/wmldata.py
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wesnoth/wmldata.py?rev=29925&r1=29924&r2=29925&view=diff
==============================================================================
--- trunk/data/tools/wesnoth/wmldata.py (original)
+++ trunk/data/tools/wesnoth/wmldata.py Mon Oct 6 21:20:57 2008
@@ -22,7 +22,7 @@
self.name = name
def __str__( self ):
- return self.debug( show_contents=True, write=False )
+ return self.debug(show_contents = True, write = False)
def debug(self, show_contents = False, use_color = False, indent=0,
write=True):
if use_color:
@@ -35,9 +35,14 @@
if show_contents:
result += "'" + self.get_value() + "'"
if write:
- # The below is a pretty ugly hack forcing python to accept utf-8
- # If your terminal can't handle utf-8, you'll obviously get a big
mess (but otherwise you'd get a crash)
- codecs.getwriter('utf-8')(sys.stdout).write(result + "\n")
+ # The input usually is utf8, but it also may be not - for example
+ # if a .png image is transmitted over WML. As this is only for
+ # display purposes, we ask Python to replace any garbage - and then
+ # re-encode as utf8 for console output.
+ text = result.decode("utf8", "replace")
+ text = text.encode("utf8", "replace")
+ sys.stdout.write(text)
+ sys.stdout.write("\n")
else: return result
@@ -236,8 +241,10 @@
elif isinstance(item, DataClosingTag):
result.append("[/%s]\n" % item.name)
- elif isinstance( item, DataBinary ):
- result.append( "[%s][/%s]\n" % item.name )
+ elif isinstance(item, DataBinary):
+ data = item.data.replace('"', r'""')
+ result.append("%s=\"%s\"\n" % (
+ item.name, data))
else:
raise WMLException("Unknown item: %s" %
item.__class__.__name__)
Modified: trunk/data/tools/wesnoth_addon_manager
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wesnoth_addon_manager?rev=29925&r1=29924&r2=29925&view=diff
==============================================================================
--- trunk/data/tools/wesnoth_addon_manager (original)
+++ trunk/data/tools/wesnoth_addon_manager Mon Oct 6 21:20:57 2008
@@ -53,7 +53,7 @@
"current directory will be used by default)")
optionparser.add_option("-u", "--upload",
help = "Upload an add-on. " +
- "UPLOAD should be either the name of a add-on subdirectory," +
+ "UPLOAD should be either the name of an add-on subdirectory," +
"(in which case the client looks for _server.pbl beneath it) " +
"or a path to the .pbl file (in which case the name of the " +
"add-on subdirectory is the name of the path with .pbl removed)")
@@ -173,7 +173,7 @@
campaign.get_text_val("uploads", "?"),
campaign.get_text_val("downloads", "?"),
campaign.get_text_val("size", "?"),
- time.ctime(int(campaign.get_text_val("timestamp",
"?"))),
+ time.ctime(int(campaign.get_text_val("timestamp",
"0"))),
campaign.get_text_val("translate", "false")]
columns.append(column)
for i, s in enumerate(column_sizes):
@@ -241,17 +241,19 @@
elif options.upload:
cs = CampaignClient(address)
- if os.path.isdir(os.path.join(options.campaigns_dir, options.upload)):
+ if os.path.isdir(options.upload):
# New style with _server.pbl
- pblfile = os.path.join(options.campaigns_dir, options.upload,
"_server.pbl")
+ pblfile = os.path.join(options.upload, "_server.pbl")
name = os.path.basename(options.upload)
- wmldir = os.path.join(options.campaigns_dir, name)
+ wmldir = options.upload
+ cfgfile = None # _main.cfg will be uploaded with the rest
else:
# Old style with external .pbl file
pblfile = options.upload
name = os.path.basename(options.upload)
name = os.path.splitext(name)[0]
wmldir = os.path.join(os.path.dirname(options.upload), name)
+ cfgfile = options.upload.replace(".pbl", ".cfg")
pbl = wmldata.read_file(pblfile, "PBL")
mythread = cs.put_campaign_async(
@@ -262,7 +264,7 @@
pbl.get_text_val("description"),
pbl.get_text_val("version"),
pbl.get_text_val("icon"),
- options.upload.replace(".pbl", ".cfg"), wmldir)
+ cfgfile, wmldir)
pcounter = 0
while not mythread.event.isSet():
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits