X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=lib%2Fmudpy%2Fdata.py;h=00ab923a5b316fed314ac7a5cda07fe9a6a4b981;hp=062bd8713c7af1b75f3935d5cfeafd5e5415e203;hb=4708e5ad2215bce4806578c9417a09ceccef0292;hpb=19558d35ce08fb9df044b3c9569eb66e7b3e6f9e diff --git a/lib/mudpy/data.py b/lib/mudpy/data.py index 062bd87..00ab923 100644 --- a/lib/mudpy/data.py +++ b/lib/mudpy/data.py @@ -1,6 +1,6 @@ """Data interface functions for the mudpy engine.""" -# Copyright (c) 2004-2015 Jeremy Stanley . Permission +# Copyright (c) 2004-2016 Jeremy Stanley . Permission # to use, copy, modify, and distribute this software is granted under # terms provided in the LICENSE file distributed with this software. @@ -14,7 +14,7 @@ import yaml class DataFile: - """A file containing universe elements.""" + """A file containing universe elements and their facets.""" def __init__(self, filename, universe): self.filename = filename @@ -23,10 +23,10 @@ class DataFile: self.load() def load(self): - """Read a file and create elements accordingly.""" + """Read a file, create elements and poplulate facets accordingly.""" self.modified = False try: - self.data = yaml.load(open(self.filename)) + self.data = yaml.safe_load(open(self.filename)) except FileNotFoundError: # it's normal if the file is one which doesn't exist yet log_entry = ("File %s is unavailable." % self.filename, 6) @@ -84,9 +84,24 @@ class DataFile: includes.append(item) if item not in self.universe.private_files: self.universe.private_files.append(item) - for element in self.data: - if element != "__control__": - mudpy.misc.Element(element, self.universe, self.filename) + for node in list(self.data): + if node == "__control__": + continue + facet_pos = node.rfind(".") + 1 + if not facet_pos: + mudpy.misc.Element(node, self.universe, self.filename, + old_style=True) + else: + prefix = node[:facet_pos].strip(".") + try: + element = self.universe.contents[prefix] + except KeyError: + element = mudpy.misc.Element(prefix, self.universe, + self.filename) + element.set(node[facet_pos:], self.data[node]) + if prefix.startswith("mudpy.movement."): + self.universe.directions.add( + prefix[prefix.rfind(".") + 1:]) for include_file in includes: if not os.path.isabs(include_file): include_file = find_file( @@ -120,11 +135,8 @@ class DataFile: "__control__"]: max_count = self.data["__control__"]["backup_count"] else: - max_count = self.universe.categories[ - "internal" - ][ - "limits" - ].get("default_backup_count") + max_count = self.universe.contents["mudpy.limit"].get( + "backups") if os.path.exists(self.filename) and max_count: backups = [] for candidate in os.listdir(os.path.dirname(self.filename)): @@ -162,8 +174,8 @@ class DataFile: os.umask(old_umask) # write and close the file - yaml.dump(self.data, allow_unicode=True, default_flow_style=False, - stream=file_descriptor) + yaml.safe_dump(self.data, allow_unicode=True, + default_flow_style=False, stream=file_descriptor) file_descriptor.close() # unset the modified flag @@ -252,7 +264,7 @@ def find_file( else: search_path = search_path[:] - # if there's no default path, use the last element of the search path + # if there's no default path, use the last component of the search path if not default_dir: default_dir = search_path[-1]