Skip to content

Commit f8aa734

Browse files
committed
By default don't exit singleuser immediately on critical.
1 parent 63fb682 commit f8aa734

6 files changed

+24
-10
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ To run a multi-player server, you can run `server.py`, which will start a websoc
2222
Windows Releases
2323
================
2424

25-
The Windows releases contain binaries which already contain all of the requirements for running the server and cli. You shouldn't need to install anything. You also don't need to copy or rename the config files if you download a windows release.
25+
The Windows releases contain binaries which already contain all of the requirements for running the server and cli. You shouldn't need to install anything. You also don't need to copy or rename the config files if you download a Windows release.

database.py

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def _startup(self):
8787
# Check if a lockfile exists for this database. If so, then fail.
8888
if os.path.exists(self._filename + ".lock"):
8989
self._log.critical("Lockfile exists for database: {filename}", filename=self._filename)
90+
self._log.critical(
91+
"If you are sure the database isn't in use, delete this file: {filename}.lock", filename=self._filename)
9092
return None
9193

9294
# See if we can access the database file. If not, then fail.

docs/index.rst

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
Dennis MUD User Manual
77
======================
88

9+
This documentation is unfinished.
10+
911
.. toctree::
1012
:maxdepth: 2
1113
:caption: Contents:

server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
textFileLogObserver, FilteringLogObserver, globalLogBeginner
5050

5151

52-
VERSION = "Alpha-0.0.1"
52+
VERSION = "Alpha-0.0.1a"
5353

5454

5555
class Router:

singleuser.config.example.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
},
55
"log": {
66
"file": "dennis.singleuser.log",
7-
"level": "debug"
7+
"level": "debug",
8+
"wait_on_critical": true
89
},
910
"prompt": {
1011
"history": "singleuser.history.txt"

singleuser.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from prompt_toolkit.history import FileHistory
4646

4747

48-
VERSION = "Alpha-0.0.1"
48+
VERSION = "Alpha-0.0.1a"
4949

5050

5151
class Router:
@@ -77,14 +77,16 @@ class Log:
7777
Logs to STDOUT, and optionally to a file.
7878
Filters out unwanted messages using a log level setting.
7979
"""
80-
def __init__(self, loglevel, logfile):
80+
def __init__(self, loglevel, logfile, waitoncritical):
8181
"""Single User Mode Log Initializer
8282
83-
:param loglevel: The log level to use. One of "debug", "info", "warn", "error", "critical", in descending verbosity.
83+
:param loglevel: The log level to use. One of: debug, info, warn, error, critical, in descending verbosity.
8484
:param logfile: The open file to log to.
85+
:param waitoncritical: Whether to wait for the enter key before exiting on a critical error. Nice for Windows.
8586
"""
8687
self._loglevel = loglevel
8788
self._logfile = logfile
89+
self._waitoncritical = waitoncritical
8890

8991
def debug(self, msg, **kwargs):
9092
"""Write a debug level message to the console and/or the log file.
@@ -127,6 +129,10 @@ def critical(self, msg, **kwargs):
127129
if self._logfile:
128130
self._logfile.write("[singleuser#critical] " + msg.format(**kwargs) + "\n")
129131

132+
# Be nice to Windows users who ran the program by double-clicking. :)
133+
if self._waitoncritical:
134+
input("Press Enter Key to Continue...")
135+
130136
def write(self, msg):
131137
"""Write an untagged message to the console and/or the log file, regardless of log level.
132138
"""
@@ -146,26 +152,29 @@ def main():
146152
with open("singleuser.config.json") as f:
147153
config = json.load(f)
148154
except:
149-
print("[singleuser#critical] could not open singleuser.config.json")
155+
print("[singleuser#critical] Could not open singleuser config file: singleuser.config.json")
150156
return 2
151157

152158
# Try to open the log file for writing, if one is set.
153159
# Otherwise don't use one.
160+
if config["log"]["level"] in ["debug", "info"]:
161+
print("[singleuser#info] Initializing logger...")
154162
logfile = None
155163
if config["log"]["file"]:
156164
try:
157165
logfile = open(config["log"]["file"], 'a')
158166
except:
159167
if config["log"]["level"] in ["debug", "info", "warn"]:
160168
print("[singleuser#warn] Could not open singleuser log file: {0}".format(config["log"]["file"]))
161-
log = Log(config["log"]["level"], logfile)
169+
log = Log(config["log"]["level"], logfile, config["log"]["wait_on_critical"])
170+
log.info("Finished initializing logger.")
162171

163172
# Initialize the database manager, and create the "database" alias for use in Debug Mode.
164-
log.info("initializing database manager")
173+
log.info("Initializing database manager...")
165174
dbman = _database.DatabaseManager(config["database"]["filename"], log)
166175
if not dbman._startup():
167176
return 3
168-
log.info("finished initializing database manager")
177+
log.info("Finished initializing database manager.")
169178
database = dbman
170179

171180
# Initialize the router.

0 commit comments

Comments
 (0)