From 7549f8f2b17705dcd20e9ae827f2f4d067d8d9a6 Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Fri, 13 Jun 2014 00:25:05 +0000 Subject: [PATCH] File read-only check supports YAML * lib/mudpy/data.py(DataFile.is_writeable): Add support for determining read-only status of YAML data files. --- lib/mudpy/data.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/mudpy/data.py b/lib/mudpy/data.py index b97a8a3..9ee09e1 100644 --- a/lib/mudpy/data.py +++ b/lib/mudpy/data.py @@ -271,14 +271,20 @@ class DataFile: # unset the modified flag self.modified = False - # TODO(fungi): this should support writing YAML def is_writeable(self): """Returns True if the __control__ read_only is False.""" - return not self.data.has_option( - "__control__", "read_only" - ) or not self.data.getboolean( - "__control__", "read_only" - ) + # TODO(fungi): remove this indirection after the YAML transition + if self._format == "yaml": + try: + return not self.data["__control__"].get("read_only", False) + except KeyError: + return True + else: + return not self.data.has_option( + "__control__", "read_only" + ) or not self.data.getboolean( + "__control__", "read_only" + ) def find_file( -- 2.11.0