From 64fe72be53ff7a16d2b715d379b604fcfa574fd8 Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Tue, 17 Jun 2014 05:36:27 +0000 Subject: [PATCH] Support data directory indices in YAML * lib/mudpy/data.py(DataFile.load_yaml,DataFile.load_mpy): Add routines to look for a YAML file index as well as the old INI-based format. For YAML files, don't bother recasting entries to lists or dicts since they should already be returned as the desired type. --- lib/mudpy/data.py | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/mudpy/data.py b/lib/mudpy/data.py index 9ee09e1..7629456 100644 --- a/lib/mudpy/data.py +++ b/lib/mudpy/data.py @@ -54,8 +54,7 @@ class DataFile: includes = [] if "__control__" in self.data: if "include_files" in self.data["__control__"]: - for included in makelist( - self.data["__control__"]["include_files"]): + for included in self.data["__control__"]["include_files"]: included = find_file( included, relative=self.filename, @@ -64,9 +63,20 @@ class DataFile: includes.append(included) if "include_dirs" in self.data["__control__"]: for included in [ - os.path.join(x, "__init__.mpy") for x in makelist( + os.path.join(x, "__init__.yaml") for x in self.data["__control__"]["include_dirs"] + ]: + included = find_file( + included, + relative=self.filename, + universe=self.universe ) + if included not in includes: + includes.append(included) + # TODO(fungi): remove this loop after the YAML transition + for included in [ + os.path.join(x, "__init__.mpy") for x in + self.data["__control__"]["include_dirs"] ]: included = find_file( included, @@ -76,9 +86,7 @@ class DataFile: if included not in includes: includes.append(included) if "default_files" in self.data["__control__"]: - origins = makedict( - self.data["__control__"]["default_files"] - ) + origins = self.data["__control__"]["default_files"] for key in origins.keys(): origins[key] = find_file( origins[key], @@ -91,9 +99,7 @@ class DataFile: if key not in self.universe.categories: self.universe.categories[key] = {} if "private_files" in self.data["__control__"]: - for item in makelist( - self.data["__control__"]["private_files"] - ): + for item in self.data["__control__"]["private_files"]: item = find_file( item, relative=self.filename, @@ -142,6 +148,18 @@ class DataFile: includes.append(included) if self.data.has_option("__control__", "include_dirs"): for included in [ + os.path.join(x, "__init__.yaml") for x in makelist( + self.data["__control__"]["include_dirs"] + ) + ]: + included = find_file( + included, + relative=self.filename, + universe=self.universe + ) + if included not in includes: + includes.append(included) + for included in [ os.path.join(x, "__init__.mpy") for x in makelist( self.data.get("__control__", "include_dirs") ) -- 2.11.0