mail[Wesnoth-commits] r28842 - in /trunk/data/tools: wesnoth/campaignserver_client.py wesnoth_addon_manager


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by elias on August 22, 2008 - 17:39:
Author: elias
Date: Fri Aug 22 17:39:13 2008
New Revision: 28842

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28842&view=rev
Log:
Attempted to fix bug #12205 - un-escaping wasn't properly done in 
wesnoth_addon_manager. I can't test if downloading campaigns works now or 
not, but it might. Uploading is still broken, will look into that later.

Modified:
    trunk/data/tools/wesnoth/campaignserver_client.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=28842&r1=28841&r2=28842&view=diff
==============================================================================
--- trunk/data/tools/wesnoth/campaignserver_client.py (original)
+++ trunk/data/tools/wesnoth/campaignserver_client.py Fri Aug 22 17:39:13 2008
@@ -3,6 +3,7 @@
 import wesnoth.wmldata as wmldata
 import wesnoth.wmlparser as wmlparser
 
+# See src/addon_management.cpp for specifications, among other files
 
 EMPTY_STRING = ''
 GZ_WRITE_MODE = 'wb'
@@ -150,22 +151,35 @@
         return packet
 
     def decode( self, data ):
-        if self.isBWML( data ):
+        if self.isBWML(data):
             data = self.decode_BWML( data )
-
         else:
             data = self.decode_WML( data )
 
         return data
 
-    def decode_WML( self, data ):
+    def unescape(self, data):
+        # 01 is used as escape character
+        data2 = ""
+        escape = False
+        for c in data:
+            if escape:
+                data2 += chr(ord(c) - 1)
+                escape = False
+            elif c == "\01":
+                escape = True
+            else:
+                data2 += c
+        return data2
+
+    def decode_WML(self, data):
         p = wmlparser.Parser( None, no_macros_in_string=True )
         p.verbose = False
         p.do_preprocessor_logic = True
         p.no_macros = True
-        p.parse_text( data, binary=True )
+        p.parse_text(data, binary=True)
         doc = wmldata.DataSub( "WML" )
-        p.parse_top( doc )
+        p.parse_top(doc)
 
         return doc
 
@@ -349,15 +363,14 @@
         Downloads the named campaign and returns it as a raw binary WML 
packet.
         """
         request = wmldata.DataSub("request_campaign")
-        request.insert( wmldata.DataText("name", name) )
-        self.send_packet( self.makePacket( request ) )
+        request.insert(wmldata.DataText("name", name))
+        self.send_packet(self.makePacket(request))
         raw_packet = self.read_packet()
-        packet = self.decode( raw_packet )
 
         if self.canceled:
             return None
 
-        return packet
+        return raw_packet
 
     def get_campaign(self, name):
         """
@@ -367,7 +380,7 @@
         packet = self.get_campaign_raw(name)
 
         if packet:
-            return self.decode( packet )
+            return self.decode(packet)
 
         return None
 
@@ -437,9 +450,9 @@
 
         return self.decode( self.read_packet( True ) )
 
-    def get_campaign_async(self, name, raw = False):
-        """
-        This is like get_campaign, but returns immediately, 
+    def get_campaign_raw_async(self, name, raw = False):
+        """
+        This is like get_campaign_raw, but returns immediately, 
         doing server communications in a background thread.
         """
         class MyThread(threading.Thread):
@@ -517,9 +530,8 @@
 
             # We MUST un-escape our data
             # Order we apply escape sequences matter here
-            contents = contents.replace( "\x01\x01", "\x00" )
-            contents = contents.replace( "\x01\x02", "\x01" )
-            save.write( contents )
+            contents = self.unescape(contents)
+            save.write(contents)
             save.close()
 
         for dir in data.get_all("dir"):

Modified: trunk/data/tools/wesnoth_addon_manager
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wesnoth_addon_manager?rev=28842&r1=28841&r2=28842&view=diff
==============================================================================
--- trunk/data/tools/wesnoth_addon_manager (original)
+++ trunk/data/tools/wesnoth_addon_manager Fri Aug 22 17:39:13 2008
@@ -98,7 +98,7 @@
         address += ":" + str(port)
 
     def get(name, version, uploads, cdir):
-        mythread = cs.get_campaign_async(name, options.raw_download)
+        mythread = cs.get_campaign_raw_async(name, options.raw_download)
 
         pcounter = 0
         while not mythread.event.isSet():
@@ -110,8 +110,9 @@
         if options.raw_download:
             file(name, "w").write(mythread.data)
         else:
+            decoded = cs.decode(myhread.data)
             print "Unpacking %s..." % name
-            cs.unpackdir(mythread.data, cdir,  verbose = options.verbose)
+            cs.unpackdir(decoded, cdir,  verbose = options.verbose)
             d = os.path.join(cdir, name)
             info = os.path.join(d, "_info.cfg")
             try:
@@ -121,7 +122,7 @@
                 f.close()
             except OSError:
                 pass
-            for message in mythread.data.find_all("message", "error"):
+            for message in decoded.find_all("message", "error"):
                 print message.get_text_val("message")
 
     def get_info(name):
@@ -207,6 +208,13 @@
                 if options.verbose:
                     print "Not downloading", name, \
                         "because it is already up-to-date."
+                        
+    elif options.unpack:
+        cs = CampaignClient(address)
+        data = file(options.unpack).read()
+        decoded = cs.decode(data)
+        print "Unpacking %s..." % options.unpack
+        cs.unpackdir(decoded, options.campaigns_dir,  verbose = True)
     elif options.remove:
         cs = CampaignClient(address)
         data = cs.delete_campaign(options.remove, options.password)




Related Messages


Powered by MHonArc, Updated Fri Aug 22 19:02:05 2008