From 9cd76d490c9656acec926efd8aaab8c091ef03ca Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 14 Apr 2009 13:41:28 +0000 Subject: [PATCH] Wesnoth WML tools module now has an issave() entry pointy... ...that detects savefiles, including compressed savefiles. --- data/tools/wesnoth/wmltools.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/data/tools/wesnoth/wmltools.py b/data/tools/wesnoth/wmltools.py index 0c7c7a58a7c..85da6194784 100644 --- a/data/tools/wesnoth/wmltools.py +++ b/data/tools/wesnoth/wmltools.py @@ -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)