"""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]
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."""
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]
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"):
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):
+ '"):$(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":
' 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."