[ScryMUD] SVN Commit Info r836 - in trunk/tools: . python python/html_help_includes python/scrymud
scrymud at wanfear.com
scrymud at wanfear.com
Fri Jun 30 23:40:28 PDT 2006
Author: eroper
Date: 2006-06-30 23:40:27 -0700 (Fri, 30 Jun 2006)
New Revision: 836
Added:
trunk/tools/python/
trunk/tools/python/html_help.py
trunk/tools/python/html_help_includes/
trunk/tools/python/html_help_includes/foot.html
trunk/tools/python/html_help_includes/head.html
trunk/tools/python/scrymud/
trunk/tools/python/scrymud/__init__.py
trunk/tools/python/scrymud/help.py
trunk/tools/python/scrymud/util.py
Log:
html_help.py creates css tagged html from ScryMUD user/imm docs.
Added: trunk/tools/python/html_help.py
===================================================================
--- trunk/tools/python/html_help.py 2006-06-25 08:59:25 UTC (rev 835)
+++ trunk/tools/python/html_help.py 2006-07-01 06:40:27 UTC (rev 836)
@@ -0,0 +1,183 @@
+#!/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
+
+#
+# At some point I'd really like to clean up the HTML output code. it's pretty
+# nasty. --eroper
+#
+
+""" Converts ScryMUD help files to html """
+
+import sys, os, re, getopt
+import scrymud.help as help
+import 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 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
+
+def toHtml(doc):
+
+ def para(m): return "<p>%s</p>"%(m.group(1))
+
+ ret_val = ""
+ ret_val += '<div class="help_name">'
+ ret_val += doc.name
+ ret_val += '</div><div class="help_syntax">'
+ ret_val += doc.syntax
+ ret_val += '</div><div class="help_example">'
+ ret_val += doc.example
+ ret_val += '</div><div class="help_content">'
+
+
+ for p in scrymud.util.paragraphs(doc.body):
+ ret_val += "<p>%s</p>" %(p)
+ ret_val += '</div><div id="see_also"'
+
+ for link in doc.see_also:
+ ret_val += "<a href=\"%s.html\">%s</a> " %(link, link)
+
+ ret_val += '</div>'
+
+ return(ret_val)
+
+
+def idxHtml(idx):
+ ret_val = ""
+ keys = idx.keys()
+ keys.sort()
+ ret_val += ("<div class=\"help_index_quicklinks\">")
+ for letter in scrymud.util.alphabet:
+ if ( idx.has_key(letter) ): ret_val += ("<a href=\"#%s\">%s</a> " %(letter,letter))
+ else: ret_val += ("%s " %(letter))
+ for k in keys:
+ ret_val += ("<div class=\"help_index_section\">\n<a name=\"%s\" /><div class=\"help_index_sortkey\">%s</div>\n" %(k,k))
+ ret_val += ("<ul class=\"help_index\">\n")
+ for entry in idx[k]:
+ ret_val += ("<li><a href=\"%s.html\">%s</a></li>\n" %(entry,entry))
+ ret_val += ("</ul></div>\n")
+ return(ret_val)
+
+if ( __name__ == '__main__' ):
+ try:
+ config = cfg(sys.argv[1:])
+ except cfg.cfgError, e:
+ sys.stderr.write("Configuration error: %s\n" %(e))
+ usage()
+
+ try:
+ os.mkdir("%s/imm" %(config.output_dir))
+ except OSError, e:
+ # errno 17 == E_EXISTS, at some point I should figure out if there is a
+ # constant definition for this.
+ if ( e.errno == 17 ): pass
+ else: raise
+
+ f = open(config.html_head, 'r')
+ hh = f.read()
+ f.close
+ f = open(config.html_foot, 'r')
+ hf = f.read()
+ f.close
+
+ idx = dict()
+ imm_idx = dict()
+
+ lib = help.helpLibrary(config.source_dir)
+ for doc in lib.all(sort=True):
+
+ if ( doc.imm ):
+ f = open("%s/imm/%s.html" %(config.output_dir, doc.name), 'w')
+ try: imm_idx[doc.name[:1].upper()].append(doc.name)
+ except KeyError, e: imm_idx[doc.name[:1].upper()] = [doc.name]
+
+ else:
+ f = open("%s/%s.html" %(config.output_dir, doc.name), 'w')
+ try: idx[doc.name[:1].upper()].append(doc.name)
+ except KeyError, e: idx[doc.name[:1].upper()] = [doc.name]
+
+ f.write(hh)
+ f.write(toHtml(doc))
+ f.write(hf)
+ f.close()
+
+ f = open("%s/index.html" %(config.output_dir),"w")
+ f.write(hh)
+ f.write(idxHtml(idx))
+ f.write(hf)
+ f.close()
+
+ f = open("%s/imm/index.html" %(config.output_dir),"w")
+ f.write(hh)
+ f.write(idxHtml(imm_idx))
+ f.write(hf)
+ f.close()
+
+
Property changes on: trunk/tools/python/html_help.py
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/tools/python/html_help_includes/foot.html
===================================================================
--- trunk/tools/python/html_help_includes/foot.html 2006-06-25 08:59:25 UTC (rev 835)
+++ trunk/tools/python/html_help_includes/foot.html 2006-07-01 06:40:27 UTC (rev 836)
@@ -0,0 +1,12 @@
+</div><!-- content -->
+<div id="footer">
+<p>The ScryMUD development team would like to thank our sponsors:</p>
+<a href="http://www.candelatech.com"><img src="images/candela_swirl_small.png" width="71" height="33"></a>
+<a href="http://cenqua.com/"><img src="images/cenquad.gif" width="89" height="33"></a>
+</div>
+
+<p id="copyright">Copyright © 2006, Edward Roper. All rights reserved.</p>
+
+</div><!-- container -->
+</body>
+</html>
Added: trunk/tools/python/html_help_includes/head.html
===================================================================
--- trunk/tools/python/html_help_includes/head.html 2006-06-25 08:59:25 UTC (rev 835)
+++ trunk/tools/python/html_help_includes/head.html 2006-07-01 06:40:27 UTC (rev 836)
@@ -0,0 +1,47 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+
+ <head>
+ <title>ScryMUD documentation</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <link rel="stylesheet" type="text/css" href="/css/common.css">
+ </head>
+ <body>
+
+
+ <div id="container">
+
+ <img id="logo" src="/images/scry_helm-logo.jpg" alt="ScryMUD" width="800" height="100">
+
+ <div id="content">
+
+ <div id="nav">
+
+ <span class="nav-header">ScryMUD</span>
+ <ul class="nav">
+ <li><a href="/">Home</a></li>
+ <li><a href="/status.html">Game status</a></li>
+ <li><a href="/forums/">The forums</a></li>
+ <li><a href="http://www.wanfear.com/mailman/listinfo/scrymud/">The mailing-list</a></li>
+ <li><a href="/setting.html">Setting</a></li>
+ <li><a href="/races.html">Races</a></li>
+ </ul>
+
+ <span class="nav-header">Players</span>
+ <ul class="nav">
+ <li><a href="/playerguide.html">New player guide</a></li>
+ <li><a href="/cartography.html">Cartography</a></li>
+ <li><a href="/commands.html">Commands</a></li>
+ <li><a href="/ss.html">Skills/Spells</a></li>
+
+ </ul>
+
+ <span class="nav-header">Developers</span>
+ <ul class="nav">
+ <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>
+ <li><a href="/features.html">Features</a></li>
+ <li><a href="/download.html">Downloads</a></li>
+ </ul>
+ </div><!-- nav -->
Added: trunk/tools/python/scrymud/__init__.py
===================================================================
Added: trunk/tools/python/scrymud/help.py
===================================================================
--- trunk/tools/python/scrymud/help.py 2006-06-25 08:59:25 UTC (rev 835)
+++ trunk/tools/python/scrymud/help.py 2006-07-01 06:40:27 UTC (rev 836)
@@ -0,0 +1,130 @@
+#!/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
+
+"""
+Part of the ScryMUD collection. Parses and processes help files.
+"""
+
+import sys, os, errno, re
+
+class helpLibrary(object):
+ """
+ This class reads all ScryMUD help files in and parses them.
+ """
+
+ def __init__(self, help_path):
+ """
+ help_path should contain the path to the ScryMUD help files
+ """
+ self.path = help_path
+ tmp = os.listdir(help_path)
+ self.docs = []
+ for f in tmp:
+ if ( os.path.isfile(self.path+"/"+f) ):
+ newDoc = helpDoc(self.path+"/"+f)
+ self.docs.append(newDoc)
+
+ def all(self, sort=False):
+ """
+ Returns an optionally sorted list of all help documents
+ """
+ if ( sort ):
+ self.docs.sort()
+ return self.docs
+
+ def imm(self, sort=False):
+ """
+ Returns an optionally sorted list of all IMM help documents
+ """
+ ret_val = []
+ for doc in self.docs:
+ if ( doc.imm ): ret_val.append(doc)
+ if ( sort ): ret_val.sort()
+ return ret_val
+
+ def player(self, sort=False):
+ """
+ Returns an optionally sorted list of all player help documents
+ """
+ ret_val = []
+ for doc in self.docs:
+ if ( not doc.imm ): ret_val.append(doc)
+ if ( sort ): ret_val.sort()
+ return ret_val
+
+
+class helpDoc(object):
+ """
+ This class is used to store a broken-out parsed copy of help documents
+ """
+
+ _re_imm = re.compile(r'IMM_(.*?)_1$')
+ _re_user = re.compile(r'([^/]*)_1$')
+ _re_tags = re.compile(r'<.*?>', re.MULTILINE|re.DOTALL)
+ _re_special = re.compile(r'(^syntax:|^example:|^see also:)(.*)', re.IGNORECASE)
+
+ def __cmp__(self, other):
+ if self.name < other.name: return -1
+ elif self.name == other.name: return 0
+ else: return 1
+
+ def __init__(self, filename):
+ self.imm = False
+ self.name = ""
+ self.syntax = ""
+ self.example = ""
+ self.body = ""
+ self.see_also = []
+
+ if ( helpDoc._re_imm.search(filename) ):
+ self.imm = True
+ m = helpDoc._re_imm.search(filename)
+ self.name = m.group(1)
+ elif ( helpDoc._re_user.search(filename) ):
+ m = helpDoc._re_user.search(filename)
+ self.imm = False
+ self.name = m.group(1)
+
+ self._readFile(filename)
+ self.see_also.sort()
+
+ def _readFile(self, filename):
+ f = open(filename, "r")
+ buf = f.read()
+ f.close()
+ buf = helpDoc._re_tags.sub('', buf)
+ lines = buf.splitlines()
+ for line in lines:
+ m = helpDoc._re_special.match(line)
+ if ( m ):
+ type = m.group(1).lower()
+ if ( type == 'syntax:' ):
+ self.syntax += m.group(2).lstrip()
+ elif ( type == 'example:' ):
+ self.example += m.group(2).lstrip()
+ elif ( type == 'see also:' ):
+ new_refs = m.group(2).strip().split(',')
+ for new_ref in new_refs:
+ self.see_also.append(new_ref.strip())
+ else:
+ raise(ValueError, "found an unexpected special-type")
+ else:
+ self.body += line + "\n"
+
+if ( __name__ == '__main__'):
+ sys.exit(0)
Property changes on: trunk/tools/python/scrymud/help.py
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/tools/python/scrymud/util.py
===================================================================
--- trunk/tools/python/scrymud/util.py 2006-06-25 08:59:25 UTC (rev 835)
+++ trunk/tools/python/scrymud/util.py 2006-07-01 06:40:27 UTC (rev 836)
@@ -0,0 +1,40 @@
+#!/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
+"""Various small utility functions"""
+
+def paragraphs(str, seperator=None):
+ """Can be used as an iterator, returning one paragraph at a time from a body
+ of text.
+ """
+ if not callable(seperator):
+ if ( seperator != None ): raise TypeError, "seperator must return bool"
+ def seperator(line): return line == '\n'
+ paragraph = []
+ for line in str.splitlines(True):
+ if seperator(line):
+ if paragraph:
+ yield "".join(paragraph)
+ paragraph = [];
+ else:
+ paragraph.append(line)
+ if paragraph: yield "".join(paragraph)
+
+# 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",
+ "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ]
More information about the ScryMUD
mailing list