From: Jeremy Stanley Date: Sun, 12 Nov 2017 01:48:28 +0000 (+0000) Subject: Drop old-style Element support X-Git-Tag: 0.0.1~117 X-Git-Url: https://mudpy.org/gitweb?a=commitdiff_plain;h=80783fa11b631d77ff47c85080be65c4bce3f7f6;p=mudpy.git Drop old-style Element support The transition to the new data model is complete, and support for the old model is now removed. --- diff --git a/mudpy/data.py b/mudpy/data.py index 4c85915..3dc71d0 100644 --- a/mudpy/data.py +++ b/mudpy/data.py @@ -64,18 +64,15 @@ class Data: if node.startswith("_"): continue facet_pos = node.rfind(".") + 1 - if not facet_pos: - mudpy.misc.Element(node, self.universe, self, 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) - element.set(node[facet_pos:], self.data[node]) - if prefix.startswith("mudpy.movement."): - self.universe.directions.add( - prefix[prefix.rfind(".") + 1:]) + prefix = node[:facet_pos].strip(".") + try: + element = self.universe.contents[prefix] + except KeyError: + element = mudpy.misc.Element(prefix, self.universe, self) + 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( diff --git a/mudpy/misc.py b/mudpy/misc.py index b322afc..a596eb5 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -23,56 +23,37 @@ class Element: """An element of the universe.""" - def __init__(self, key, universe, origin=None, old_style=False): + def __init__(self, key, universe, origin=None): """Set up a new element.""" - # TODO(fungi): This can be removed after the transition is complete - self.old_style = old_style - # keep track of our key name self.key = key # keep track of what universe it's loading into self.universe = universe - # clone attributes if this is replacing another element - if self.old_style and self.key in self.universe.contents: - old_element = self.universe.contents[self.key] - for attribute in vars(old_element).keys(): - exec("self." + attribute + " = old_element." + attribute) - if self.owner: - self.owner.avatar = self - - # i guess this is a new element then - else: - - # set of facet keys from the universe - self.facethash = dict() + # set of facet keys from the universe + self.facethash = dict() - # not owned by a user by default (used for avatars) - self.owner = None + # not owned by a user by default (used for avatars) + self.owner = None - # no contents in here by default - self.contents = {} + # no contents in here by default + self.contents = {} - # parse out appropriate category and subkey names, add to list - if self.key.find(":") > 0: - # TODO(fungi) this can be removed once old_style Elements - # are no longer needed - self.category, self.subkey = self.key.split(":", 1) - elif self.key.find(".") > 0: - self.category, self.subkey = self.key.split(".", 1)[-2:] - else: - self.category = "other" - self.subkey = self.key - if self.category not in self.universe.categories: - self.universe.categories[self.category] = {} + if self.key.find(".") > 0: + self.category, self.subkey = self.key.split(".")[-2:] + else: + self.category = "other" + self.subkey = self.key + if self.category not in self.universe.categories: + self.universe.categories[self.category] = {} - # get an appropriate origin - if not origin: - self.universe.add_category(self.category) - origin = self.universe.files[ - self.universe.origins[self.category]["fallback"]] + # get an appropriate origin + if not origin: + self.universe.add_category(self.category) + origin = self.universe.files[ + self.universe.origins[self.category]["fallback"]] # record or reset a pointer to the origin file self.origin = self.universe.files[origin.source] @@ -83,29 +64,20 @@ class Element: def reload(self): """Create a new element and replace this one.""" - Element(self.key, self.universe, self.origin, old_style=self.old_style) + Element(self.key, self.universe, self.origin) del(self) def destroy(self): """Remove an element from the universe and destroy it.""" - if self.old_style: - del self.origin.data[self.key] - else: - for facet in dict(self.facethash): - self.remove_facet(facet) + for facet in dict(self.facethash): + self.remove_facet(facet) del self.universe.categories[self.category][self.subkey] del self.universe.contents[self.key] del self def facets(self): """Return a list of non-inherited facets for this element.""" - if self.old_style: - try: - return self.origin.data[self.key].keys() - except (AttributeError, KeyError): - return [] - else: - return self.facethash + return self.facethash def has_facet(self, facet): """Return whether the non-inherited facet exists.""" @@ -113,9 +85,7 @@ class Element: def remove_facet(self, facet): """Remove a facet from the element.""" - if self.old_style and self.has_facet(facet): - del self.origin.data[self.key][facet] - elif ".".join((self.key, facet)) in self.origin.data: + if ".".join((self.key, facet)) in self.origin.data: del self.origin.data[".".join((self.key, facet))] if facet in self.facethash: del self.facethash[facet] @@ -141,10 +111,7 @@ class Element: if default is None: default = "" try: - if self.old_style: - return self.origin.data[self.key][facet] - else: - return self.origin.data[".".join((self.key, facet))] + return self.origin.data[".".join((self.key, facet))] except (KeyError, TypeError): pass if self.has_facet("inherit"): @@ -167,14 +134,9 @@ class Element: elif facet in ["administrator"]: value = bool(value) if not self.has_facet(facet) or not self.get(facet) == value: - if self.old_style: - if self.key not in self.origin.data: - self.origin.data[self.key] = {} - self.origin.data[self.key][facet] = value - else: - node = ".".join((self.key, facet)) - self.origin.data[node] = value - self.facethash[facet] = self.origin.data[node] + node = ".".join((self.key, facet)) + self.origin.data[node] = value + self.facethash[facet] = self.origin.data[node] self.origin.modified = True def append(self, facet, value): @@ -2191,12 +2153,8 @@ def command_show(actor, parameters): + '"):$(eol)') facets = element.facets() for facet in sorted(facets): - if element.old_style: - message += ("$(eol) $(grn)%s: $(red)%s$(nrm)" % - (facet, escape_macros(element.get(facet)))) - else: - message += ("$(eol) $(grn)%s: $(red)%s$(nrm)" % - (facet, str(facets[facet]))) + message += ("$(eol) $(grn)%s: $(red)%s$(nrm)" % + (facet, str(facets[facet]))) else: message = 'Element "' + arguments[1] + '" does not exist.' elif arguments[0] == "result": @@ -2270,7 +2228,7 @@ def command_create(actor, parameters): ' Warning: "' + filename + '" is not yet ' "included in any other file and will not be read " "on startup unless this is remedied.") - Element(element, universe, filename, old_style=True) + Element(element, universe, filename) log(logline, 6) elif len(arguments) > 2: message = "You can only specify an element and a filename."