Author: esr
Date: Tue Apr 14 15:41:28 2009
New Revision: 34907
URL: http://svn.gna.org/viewcvs/wesnoth?rev=34907&view=rev
Log:
Wesnoth WML tools module now has an issave() entry pointy that detects
savefiles, including compressed savefiles.
Modified:
trunk/data/tools/wesnoth/wmltools.py
Modified: trunk/data/tools/wesnoth/wmltools.py
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wesnoth/wmltools.py?rev=34907&r1=34906&r2=34907&view=diff
==============================================================================
--- trunk/data/tools/wesnoth/wmltools.py (original)
+++ trunk/data/tools/wesnoth/wmltools.py Tue Apr 14 15:41:28 2009
@@ -3,7 +3,7 @@
"""
-import sys, os, re, sre_constants, md5, glob
+import sys, os, re, sre_constants, md5, glob, gzip
resource_extensions = ("png", "jpg", "jpeg", "ogg", "wav", "map", "mask")
image_reference = r"[A-Za-z0-9{}.][A-Za-z0-9_/+{}.-]*\.(png|jpg)(?=(~.*)?)"
@@ -118,6 +118,16 @@
def iswml(filename):
"Is the specified filename WML?"
return filename.endswith(".cfg")
+
+def issave(filename):
+ "Is the specified filename a WML save? (Detects compressed saves too.)"
+ if isresource(filename):
+ return False
+ if filename.endswith(".gz"):
+ firstline = gzip.open(filename).readline()
+ else:
+ firstline = open(filename).readline()
+ return firstline.startswith("label=")
def isresource(filename):
"Is the specified name a resource?"
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits