Make helpentry topic names unique. Add a description to the cross-platform startup script. Added a util directory and a MUX/MUSH help file importer script.

This commit is contained in:
Greg Taylor 2009-01-22 16:56:00 +00:00
parent cbd5fd9faa
commit 6715f76847
3 changed files with 134 additions and 2 deletions

View file

@ -91,7 +91,7 @@ def main():
Beginning of the program logic.
"""
parser = OptionParser(usage="%prog [options] <start|stop>",
description="")
description="This command starts or stops the Evennia game server.")
parser.add_option('-i', '--interactive', action='store_true',
dest='interactive', default=False,
help='Start in interactive mode')

View file

@ -10,7 +10,7 @@ class HelpEntry(models.Model):
"""
A generic help entry.
"""
topicname = models.CharField(max_length=255)
topicname = models.CharField(max_length=255, unique=True)
entrytext = models.TextField(blank=True, null=True)
staff_only = models.BooleanField(default=0)

132
util/mux_help_importer.py Executable file
View file

@ -0,0 +1,132 @@
#!/usr/bin/env python
"""
MUX HELP FILE IMPORTER
Imports MUX/MUSH-style help files.
"""
from optparse import OptionParser
from subprocess import Popen, call
import os
import sys
import signal
# Set the Python path up so we can get to settings.py from here.
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
os.environ['DJANGO_SETTINGS_MODULE'] = 'game.settings'
from django.conf import settings
from src.helpsys.models import HelpEntry
# If true, when found, duplicate entries are replaced.
replace_duplicates = False
topic_name = ''
entry_text = ''
def _is_function_entry(topic_name):
"""
Returns True if this appears to be a MUX/MUSH function entry. We are not
generally interested in these.
"""
try:
# If the topic name ends in '()', it's a function
if topic_name[-2:] == "()":
return True
except IndexError:
# Let the following return handle this
pass
return False
def _create_db_entry():
"""
Creates a HelpFile object in the database from the currently stored values.
"""
global topic_name, entry_text
existing_matches = HelpEntry.objects.filter(topicname__iexact=topic_name)
save_entry = True
if existing_matches and not replace_duplicates:
print "IGNORING DUPLICATE:", topic_name
save_entry = False
elif existing_matches and replace_duplicates:
print "REPLACING:", topic_name
help = existing_matches[0]
else:
print "CREATING:", topic_name
help = HelpEntry()
if save_entry:
help.topicname = topic_name
help.entrytext = entry_text
if not _is_function_entry(topic_name):
help.save()
else:
print "IGNORING FUNCTION:", topic_name
topic_name = ''
entry_text = ''
def _start_new_helpentry(first_line):
"""
Given a line, start storing stuff in a new help entry.
"""
global topic_name
if topic_name.strip() != '' and entry_text.strip() != '':
_create_db_entry()
topic_name = first_line[1:].strip()
if topic_name == '' or topic_name.lower() == 'help':
topic_name = 'Help Index'
def import_helpfiles(file):
"""
Given a file-like object, imports the help files within.
"""
global topic_name, entry_text
line_list = file.readlines()
for line in line_list:
if line[0] == '&':
_start_new_helpentry(line)
else:
#print "+%s" % line
entry_text += line
def main():
"""
Beginning of the program logic.
"""
global replace_duplicates
parser = OptionParser(usage="%prog [options] <helpfile.txt>",
description="This command imports MUX and MUSH-style help files. By " \
"default, if a duplicate entry is found, the existing entry is " \
"preserved. With the -r flag, the existing entry is replaced with " \
"the imported entry.")
parser.add_option('-r', '--replace', action='store_true',
dest='replace_duplicates', default=False,
help='Replace duplicate entries')
(options, args) = parser.parse_args()
# A filename must be provided
filename = " ".join(args)
if filename.strip() == "":
parser.print_help()
return
try:
file = open(filename, 'r')
except IOError:
print "Specified file cannot be found."
return
# Make this globally available for lazyness
replace_duplicates = options.replace_duplicates
# Import the help files
import_helpfiles(file)
if __name__ == '__main__':
main()