"""Miscellaneous functions for the mudpy engine."""
-# Copyright (c) 2004-2017 Jeremy Stanley <fungi@yuggoth.org>. Permission
+# Copyright (c) 2004-2018 Jeremy Stanley <fungi@yuggoth.org>. Permission
# to use, copy, modify, and distribute this software is granted under
# terms provided in the LICENSE file distributed with this software.
# updated data from files
raise PermissionError("Altering elements in read-only files is "
"disallowed")
+ # Coerce some values to appropriate data types
+ # TODO(fungi) Move these to a separate validation mechanism
if facet in ["loglevel"]:
value = int(value)
elif facet in ["administrator"]:
value = bool(value)
- if not self.has_facet(facet) or not self.get(facet) == value:
- node = ".".join((self.key, facet))
+
+ # The canonical node for this facet within its origin
+ node = ".".join((self.key, facet))
+
+ if node not in self.origin.data or self.origin.data[node] != value:
+ # Be careful to only update the origin's contents when required,
+ # since that affects whether the backing file gets written
self.origin.data[node] = value
- self.facethash[facet] = self.origin.data[node]
self.origin.modified = True
+ # Make sure this facet is included in the element's facets
+ self.facethash[facet] = self.origin.data[node]
+
def append(self, facet, value):
"""Append value to a list."""
newlist = self.get(facet)
self.startdir = os.getcwd()
self.terminate_flag = False
self.userlist = []
+ self.versions = None
if not filename:
possible_filenames = [
"etc/mudpy.yaml",
if self.output_queue:
try:
self.connection.send(self.output_queue[0])
- except BrokenPipeError:
+ except (BrokenPipeError, ConnectionResetError):
if self.account and self.account.get("name"):
account = self.account.get("name")
else:
account = "an unknown user"
self.state = "disconnecting"
- log("Broken pipe sending to %s." % account, 7)
+ log("Disconnected while sending to %s." % account, 7)
del self.output_queue[0]
def enqueue_input(self):
try:
line = line.decode("utf-8")
except UnicodeDecodeError:
- logline = "Non-UTF-8 characters from "
+ logline = "Non-UTF-8 sequence from "
if self.account and self.account.get("name"):
logline += self.account.get("name") + ": "
else:
arguments = parameters.split()
if not parameters:
message = "What do you want to show?"
+ elif arguments[0] == "version":
+ message = repr(universe.versions)
elif arguments[0] == "time":
message = universe.groups["internal"]["counters"].get(
"elapsed"
log(*logline)
universe.setup_loglines = []
- # log an initial message
- log("Started mudpy with command line: " + " ".join(sys.argv))
-
# fork and disassociate
daemonize(universe)
# make the pidfile
create_pidfile(universe)
+ # load and store diagnostic info
+ universe.versions = mudpy.version.Versions("mudpy")
+
+ # log startup diagnostic messages
+ log("On %s at %s" % (universe.versions.python_version, sys.executable), 1)
+ log("Import path: %s" % ", ".join(sys.path), 1)
+ log("Installed dependencies: %s" % universe.versions.dependencies_text, 1)
+ log("Other python packages: %s" % universe.versions.environment_text, 1)
+ log("Started %s with command line: %s" % (
+ universe.versions.version, " ".join(sys.argv)), 1)
+
# pass the initialized universe back
return universe