[ScryMUD] SVN Commit Info r843 - in trunk/tools/python: . html_help_includes scrymud
scrymud at wanfear.com
scrymud at wanfear.com
Mon Jul 10 21:42:53 PDT 2006
Author: eroper
Date: 2006-07-10 21:42:52 -0700 (Mon, 10 Jul 2006)
New Revision: 843
Added:
trunk/tools/python/html_ss.py
trunk/tools/python/html_util.py
trunk/tools/python/scrymud/skills_spells.py
Modified:
trunk/tools/python/html_help_includes/head.html
trunk/tools/python/scrymud/util.py
Log:
Added html_ss.py to produce skill/spell html documentation.
Modified: trunk/tools/python/html_help_includes/head.html
===================================================================
--- trunk/tools/python/html_help_includes/head.html 2006-07-10 21:36:27 UTC (rev 842)
+++ trunk/tools/python/html_help_includes/head.html 2006-07-11 04:42:52 UTC (rev 843)
@@ -32,12 +32,13 @@
<li><a href="/playerguide.html">New player guide</a></li>
<li><a href="/cartography.html">Cartography</a></li>
<li><a href="/help/">Commands</a></li>
- <li><a href="/ss.html">Skills/Spells</a></li>
+ <li><a href="/skills_spells/">Skills/Spells</a></li>
</ul>
<span class="nav-header">Developers</span>
<ul class="nav">
+ <li><a href="/help/imm/">Immortal commands</a></li>
<li><a href="/builders/">Builder docs.</a></li>
<li><a href="http://source.scrymud.net/">The code</a></li>
<li><a href="http://bugs.scrymud.net/">Bugs</a></li>
Added: trunk/tools/python/html_ss.py
===================================================================
--- trunk/tools/python/html_ss.py 2006-07-10 21:36:27 UTC (rev 842)
+++ trunk/tools/python/html_ss.py 2006-07-11 04:42:52 UTC (rev 843)
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+# $Id$
+# Copyright (C) 2006, Edward Roper <edro+scrymud at wanfear.net>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+# I'm feeling lazy right now, so this is hard-coded.
+source_dir = "/home/eroper/devel/ScryMUD/mud/grrmud/World"
+dest_dir = "/home/eroper/devel/ScryMUD/tools/python/ss_help"
+
+
+import sys, html_util
+from scrymud import skills_spells, util
+def mkContent(skill, skillcollection):
+ ret_val = ""
+ ret_val += "<div class=\"help_name\">%s</div>\n" %(skill.name)
+ ret_val += "<p>Requires level: %d Mana cost: %d</p>\n" %(skill.min_level, skill.mana_cost)
+ ret_val += "<div class=\"help_content\">"
+ for p in util.paragraphs(skill.description):
+ ret_val += "<p>%s</p>" %(p)
+ ret_val += "</div>"
+ ret_val += "<h3>Prerequisites</h3><div id=\"skill_prereqs\">"
+ for id in skill.prereqs:
+ name = skillcollection.getNum(int(id)).name.lower().replace(" ","_")
+ ret_val += "<a href=\"/skills_spells/%s.html\">%s</a> " %(name,name)
+ ret_val += "</div>"
+ ret_val += "<h3>Enables</h3><div id=\"skill_enables\">"
+ for id in skill.enables:
+ name = skillcollection.getNum(int(id)).name.lower().replace(" ","_")
+ ret_val += "<a href=\"/skills_spells/%s.html\">%s</a> " %(name,name)
+ ret_val += "</div>"
+ return(ret_val)
+
+if ( __name__ == '__main__' ):
+ try:
+ config = html_util.cfg(sys.argv[1:])
+ except html_util.cfg.cfgError, e:
+ sys.stderr.write("Configuration error: %s\n" %(e))
+ html_util.usage()
+ Skills = skills_spells.SSCollection(config.source_dir)
+ Skills.read()
+ Pages = html_util.PageCollection(config.html_head,config.html_foot,config.output_dir)
+
+ for skill in Skills:
+ page = Pages.newPage()
+ page.title = skill.name
+ page.doc = mkContent(skill,Skills)
+ Pages.writeIndex("index.html")
+ Pages.writePages()
Property changes on: trunk/tools/python/html_ss.py
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id Author Date Revision
Added: trunk/tools/python/html_util.py
===================================================================
--- trunk/tools/python/html_util.py 2006-07-10 21:36:27 UTC (rev 842)
+++ trunk/tools/python/html_util.py 2006-07-11 04:42:52 UTC (rev 843)
@@ -0,0 +1,146 @@
+#!/usr/bin/env python
+# $Id$
+# Copyright (C) 2006, Edward Roper <edro+scrymud at wanfear.net>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import sys, os, getopt, scrymud.util
+
+def usage():
+ sys.stderr.write(
+ "Usage: %s --output-dir= --source-dir= --html-head= --html-foot=\n" %(
+ sys.argv[1:1]) )
+ sys.exit(-1)
+
+class PageCollection(object):
+ def __init__(self, header, footer, output_directory):
+ reader = open(header,"r")
+ self.header = reader.read()
+ reader.close()
+ reader = open(footer,"r")
+ self.footer = reader.read()
+ reader.close
+ self.output_directory = output_directory
+ self.__pagelist__ = []
+ self.__pages__ = None
+ def newPage(self):
+ page = Page()
+ self.__pagelist__.append(page)
+ return(page)
+ def writeIndex(self, filename):
+ if ( self.__pages__ == None ): self.__mkIndex__()
+ filename = self.output_directory + "/" + filename
+ writer = open(filename,"w")
+ writer.write(self.header)
+ keys = self.__pages__.keys()
+ keys.sort()
+ writer.write("<div class=\"help_index_quicklinks\">")
+ for letter in scrymud.util.alphabet:
+ letter = letter.lower()
+ if ( self.__pages__.has_key(letter) ):
+ writer.write("<a href=\"#%s\">%s</a> " %(letter, letter))
+ else:
+ writer.write("%s " %(letter))
+ for k in keys:
+ writer.write("<div class=\"help_index_section\">\n<a name=\"%s\" /><div class=\"help_index_sortkey\">%s</div>\n" %(k,k))
+ writer.write("<ul class=\"help_index\">\n")
+ for page in self.__pages__[k]:
+ writer.write("<li><a href=\"%s.html\">%s</a></li>\n" %(page.__filename__, page.title))
+ writer.write("</ul></div>\n")
+ writer.write(self.footer)
+ writer.close()
+ def writePages(self):
+ for page in self.__pagelist__:
+ filename = self.output_directory + "/" + page.__filename__ + ".html"
+ writer = open(filename,"w")
+ writer.write(self.header)
+ writer.write(page.doc)
+ writer.write(self.footer)
+ writer.close()
+ def __mkIndex__(self):
+ if self.__pages__ == None: self.__pages__ = dict()
+ self.__pagelist__.sort()
+ for page in self.__pagelist__:
+ if ( not self.__pages__.has_key(page.title[:1])): self.__pages__[page.title[:1]] = []
+ self.__pages__[page.title[:1]].append(page)
+
+
+class Page(object):
+ def __init__(self):
+ self.__title__="<no title>"
+ self.__filename__ = "<no filename>"
+ self.doc="<no document>"
+ def __cmp__(self, other):
+ if self.__title__ < other.__title__: return -1
+ elif self.__title__ == other.__title__: return 0
+ else: return 1
+ def __getTitle__(self):
+ return self.__title__
+ def __setTitle__(self, val):
+ self.__title__ = val.lower()
+ self.__filename__ = self.__title__.replace(" ","_")
+ title = property(__getTitle__, __setTitle__)
+
+
+
+class cfg(object):
+
+ _valid_long_args = [ "output-dir=",
+ "source-dir=",
+ "html-head=",
+ "html-foot=",
+ ]
+
+ class cfgError(Exception):
+ def __init__(self, value):
+ self.value = value
+ def __str__(self):
+ return self.value
+
+ def __init__(self, argv):
+ self.output_dir=None
+ self.source_dir=None
+ self.html_head=None
+ self.html_foot=None
+
+ (found, extra) = getopt.getopt(argv, "", cfg._valid_long_args)
+ for (name, value) in found:
+ if ( name == '--source-dir' ):
+ self.source_dir = value
+ elif ( name == '--output-dir' ):
+ self.output_dir = value
+ elif ( name == '--html-head' ):
+ self.html_head = value
+ elif ( name == '--html-foot' ):
+ self.html_foot = value
+
+ self._validate()
+
+ def _validate(self):
+ if ( not self.output_dir ): raise cfg.cfgError, "output-dir is not set."
+ if ( not self.source_dir ): raise cfg.cfgError, "source-dir is not set."
+ if ( not self.html_head ): raise cfg.cfgError, "html-head is not set."
+ if ( not self.html_foot ): raise cfg.cfgError, "html-foot is not set."
+
+ for path in [ self.output_dir, self.source_dir ]:
+ if ( not os.path.isdir(path) ): raise cfg.cfgError, "%s is not a directory." %(path)
+ if ( not os.access(self.output_dir, os.W_OK) ): raise cfg.cfgError, "%s is not writeable." %(path)
+ if ( not os.access(self.source_dir, os.R_OK) ): raise cfg.cfgError, "%s is not readable." %(path)
+
+ for path in [ self.html_head, self.html_foot ]:
+ if ( not os.path.isfile(path) ): raise cfg.cfgError, "%s is not a file." %(path)
+ if ( not os.access(path, os.R_OK) ): raise cfg.cfgError, "%s is not readable." %(path)
+
+ return
Property changes on: trunk/tools/python/html_util.py
___________________________________________________________________
Name: svn:keywords
+ Id Author Date Revision
Added: trunk/tools/python/scrymud/skills_spells.py
===================================================================
--- trunk/tools/python/scrymud/skills_spells.py 2006-07-10 21:36:27 UTC (rev 842)
+++ trunk/tools/python/scrymud/skills_spells.py 2006-07-11 04:42:52 UTC (rev 843)
@@ -0,0 +1,109 @@
+#!/usr/bin/env python
+# $Id$
+# Copyright (C) 2006, Edward Roper <edro+scrymud at wanfear.net>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+from util import nilListParse, termedRead
+import re
+
+class SkillSpell(object):
+ __re_comment = re.compile(r'#.*$')
+ def __init__(self):
+ self.ss_num = -1
+ self.name = "<no name>"
+ self.min_level = -1
+ self.difficulty = -1
+ self.mana_cost = -1
+ self.scroll_num = -1
+ self.prereqs = None
+ self.enables = None
+ self.restrictions = None
+ self.description = "<no description>"
+
+ def read(self, f):
+ self.ss_num = int(f.readline().rstrip())
+ self.name = f.readline().rstrip()
+ buf = SkillSpell.__re_comment.sub('',f.readline().rstrip())
+
+ [ self.min_level,
+ self.difficulty,
+ self.mana_cost,
+ self.scroll_num ] = [ int(x) for x in buf.split() ]
+
+ self.prereqs = nilListParse(f.readline().rstrip())
+ self.enables = nilListParse(f.readline().rstrip())
+ self.restrictions = nilListParse(f.readline().rstrip())
+ f.readline()
+
+class SSCollection(object):
+ def __init__(self, ss_path):
+ '''SSCollection(ss_path)
+ ss_path should point to the directory containing the SKILLS_SPELLS
+ and SS_DESC files.'''
+ self.__sslist__ = []
+ self.__ssfile__ = "%s/%s" %(ss_path, "SKILLS_SPELLS")
+ self.__ssdesc__ = "%s/%s" %(ss_path, "SS_DESCS")
+ self.__sorted__ = False
+
+ def __iter__(self):
+ if ( not self.__sorted__ ):
+ self.__sslist__.sort()
+ self.__sorted__ = True
+ for s in self.__sslist__: yield s
+
+ def read(self):
+ ssfile = open(self.__ssfile__,"r")
+ while ( True ):
+ k = ssfile.readline().rstrip()
+ if ( k[:2] == "-1" ): break
+ s = SkillSpell()
+ s.read(ssfile)
+ self.__sslist__.append(s)
+ ssfile.close()
+
+ ssfile = open(self.__ssdesc__,"r")
+ while ( True ):
+ name = ssfile.readline()
+ if ( name == '\n' ): continue
+ if ( name == '' ): break
+ name = name.rstrip()
+ desc = termedRead(ssfile)
+ s = self.getName(name)
+ s.description = desc
+ ssfile.close()
+
+ def getNum(self, skill_num):
+ '''Fetches a skill object by number'''
+ for s in self.__sslist__:
+ if ( s.ss_num == skill_num ): return(s)
+ return(None)
+
+ def getName(self, skill_name):
+ '''Fetches a skill object by name'''
+ for s in self.__sslist__:
+ if ( s.name.lower() == skill_name.lower() ): return(s)
+ return(None)
+
+if ( __name__ == '__main__' ):
+ mySS = SSCollection("/home/eroper/devel/ScryMUD/mud/grrmud/World")
+ mySS.read()
+ S = mySS.getNum(2)
+ if ( S.name.lower() != "block" ):
+ print "SSCollection.getNum failed."
+
+ S = mySS.getName("Block")
+ if ( S.ss_num != 2 ):
+ print "SSCollection.getName failed."
Property changes on: trunk/tools/python/scrymud/skills_spells.py
___________________________________________________________________
Name: svn:keywords
+ Id Author Date Revision
Modified: trunk/tools/python/scrymud/util.py
===================================================================
--- trunk/tools/python/scrymud/util.py 2006-07-10 21:36:27 UTC (rev 842)
+++ trunk/tools/python/scrymud/util.py 2006-07-11 04:42:52 UTC (rev 843)
@@ -17,6 +17,8 @@
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Various small utility functions"""
+import re
+
def paragraphs(str, seperator=None):
"""Can be used as an iterator, returning one paragraph at a time from a body
of text.
@@ -50,6 +52,16 @@
buf += tmp
return(buf[:-1]) # we have an extra newline
+def nilListParse(str):
+ '''Returns a list from "-1" terminated strings.'''
+ re_strip = re.compile(r'(^[\-\d ]+).*$')
+ m = re_strip.search(str)
+ str = m.group(1).rstrip()
+ if (str[-2:] != "-1"):
+ raise ValueError, "Expected a -1 terminated list."
+ ret_val = str[:-2].rstrip().split()
+ return(ret_val)
+
# This exists because I am too brain dead to come up with a better way
# to build help indexes. --eroper
alphabet = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
More information about the ScryMUD
mailing list