Wesnoth WML tools module now has an issave() entry pointy...

...that detects savefiles, including compressed savefiles.
This commit is contained in:
Eric S. Raymond 2009-04-14 13:41:28 +00:00
parent 590083fa78
commit 9cd76d490c

View file

@ -3,7 +3,7 @@ wmltools.py -- Python routines for working with a Battle For Wesnoth WML tree
"""
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)(?=(~.*)?)"
@ -119,6 +119,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?"
(root, ext) = os.path.splitext(filename)