Wesnoth WML tools module now has an issave() entry pointy...
...that detects savefiles, including compressed savefiles.
This commit is contained in:
parent
590083fa78
commit
9cd76d490c
1 changed files with 11 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue