The Ming Server

The Ming Server generates web pages statically or dynamically. As a local executable, it generates a static site from a directory tree of simple text files. Installed in cgi-bin, it creates those same pages on demand from the same source files, in response to browser requests. Parsing of different source types and the writing of pages are separated, making it easy to extend The Ming Server to new data types or delivery methods.

This document describes both usages: static and dynamic.


STATIC USAGE

ming.cgi --debug --force local/src/dir local/dest/dir

DESCRIPTION

The first time ming.cgi is run, it creates the entire site and writes a time-stamp. Subsequent runs only update files newer than the stamp. See force option.

In order to run ming.cgi, you will need:

  • The Ming Server installed as described in the INSTALL file; and
  • local/src/dir tree ready with its source files (see below).

The site.html plate (see data/site.html in the distribution) uses HTML comment and comment-end tags in column 0 to determine where data goes. The tags "content", "title", and "menu" are automatically generated but need not be in the plate. The Ming Server will use any comment tags in the data and plate. The "content" tag is used extensively as a default. Only "title" does not have an end tag and the formatting of its use as title element cannot be changed. This has to do with how browsers parse titles.

COMMAND-LINE OPTIONS

--debug
Prints a verbose output for developer analysis. Note that ming.cgi normally exits with an exception in debug mode because ming.cgi normally ignores what does not matter to it, such as unused directories, etc.
--force
Forces creation of entire site regardless of file modification times.

EXAMPLES

Source Files

The following are expected. Anything else is ignored. Examples are in the distribution's user/data dir tree.

  • key file
  • data files
  • site.html

key file Key files take the following form, beginning with the first line of the file.

file name (no extension)
page title
(optional descriptive line)
(blank line)
file name (no extension)
page title
(optional descriptive line)
(blank line)
.
.
.
.
file name (no extension)
page title
(optional descriptive line)
(blank line)

The order of the files in key determine the ordering of the menu, the file used as directory index (first file in key), the page titles, and the text of a "desc" comment tag.

data file

These have the type on the first line and all following lines are treated as data. The following types are available:

html

Data is treated as pure HTML. You can break the data into pieces for comment tags by separating the pieces with comment tags. If no comment tags are found, all data is marked as "content"

plain

The entire data chunk is marked as "content" and dropped in as-is.

pre

The entire data chunk is marked as "content" and inserted between HTML pre-tags.

3tml

Data is first parsed for a simple markup language and then treated as html above. The language is line based, parsing line by line and expecting markup in column 0. The markup is:

 !text - produces an h3 element with text
 @url some words - produces a link to url with "some words" as visible link
 | - by itself on a line, starts and stops blockquotes
 + - by itself on a line, starts and stops unordered lists (no nesting)
 \text - forces a line break before text
 [blank line] - a blank line forces a paragraph tag

All types are exampled in the user/data tree.

site.html

The boiler plate for the site is simply an HTML file in the top of the source tree. There is an example site.html in the user/data tree.

NOTES

  • Architecture is object-based and simple.
  • Data is parsed by parsers, built into pages by makers, written out by writers.
  • A new parser would go in TheMingServer/parsers, entered in the parser subpackage __init__.py,
  • and entered in PageMaker.PARSERS.

RETURN VALUES

0 good, 1 bad.


DYNAMIC USAGE

If you request this URL,
http://your.dot.com/cgi-bin/ming.cgi?page=path/to/page
The Ming Server will generate page at self.DATA/path/to/page

CGI INSTALLATION

The same python and data files used for static generation can be used to create a dynamically-generated web site. You will need a site with access to Python in the cgi-bin.

These simple steps should get you up and running:

  • Put the executable "ming.cgi" in cgi-bin and give it world read-write-execute perms (unix 755)
  • Put the "TheMingServer" directory with the other Python scripts in cgi-bin, i.e.
    site/cgi-bin/TheMingServer
    and make sure they are world-readable (unix 644). They should already be -- but check.
  • Put the example "data" directory at the same level as cgi-bin and make all world-readable.
  • Take the "refresh.index.page", put your URL in there everywhere mine occurs, and install as your new "index.html" in your "htdocs" or "public_html" or whatever-it's-called directory.

WEB LOG

The Ming Server can keep its own log of page requests. Logging is done by the Logger and controlled by PageMaker. The following USER CONSTS should be set in Consts.py:

LOGGING
1 turns it on - 0 turns it off
DIR
Directory where "ming.log" lives. This must be placed where the CGI can write files. DIR = "." puts it in your cgi-bin.
DEMO
1 makes log public - 0 requires password
PASSWD
Used in the calls to view log

You can then make the following calls to the log:

http://your.dot.com/cgi-bin/ming.cgi?log=log
Web log With Logger.DEMO set to 1. Web log is public
http://your.dot.com/cgi-bin/ming.cgi?log=log&view=passwd
Web log displayed privately. PASSWD set in Logger.
http://your.dot.com/cgi-bin/ming.cgi?remove=passwd&item=title
Web log is a Python dictionary and dict[title] will be removed.

NOTES

  • Add the param "debug=1" to the request and you will initialize Python's cgitb for debugging.
  • The Ming Server can execute Python scripts and use the output of the script as the content of your page.
    See Python Data Type page.
  • The Ming Server can receive and record incoming data from forms which are then handled by your Python pages.
    See Incoming Form Data Handler page.