Tried some variations with reST conversion, but didn't find a satisfactory alternate solution.

This commit is contained in:
Griatch 2011-09-11 16:19:27 +02:00
parent eae89eabc0
commit 2200632739
2 changed files with 136 additions and 23 deletions

View file

@ -48,8 +48,6 @@ Evennia:
Obs- Python3.x is not supported yet.
- The default database system SQLite3 only comes as part of Python2.5
and later.
- Python is available in all modern operating systems (Linux, Mac,
etc).
- Windows users are recommended to use ActivePython
(http://www.activestate.com/activepython)
@ -102,7 +100,9 @@ Python itself is definitely available through all distributions. On
Debian-derived systems you can do something like this (as root) to get
all you need:
``apt-get install python python-django python-twisted mercurial``
::
apt-get install python python-django python-twisted mercurial
If some or all dependencies are not readily available (for example,
running some flavors of !RedHat/CentOS or an older Debian version) you
@ -112,7 +112,9 @@ or the alternative
`pip <http://www.pip-installer.org/en/latest/index.html>`_:
``easy_install django twisted pil mercurial``
``pip install django twisted pil mercurial``
::
pip install django twisted pil mercurial
**Windows** users may choose to install
`ActivePython <http://www.activestate.com/activepython>`_ instead of the
@ -121,10 +123,12 @@ usual Python. If ActivePython is installed, you can use
same manner as ``easy_install``/``pip`` above. This *greatly* simplifies
getting started on Windows:
``pypm install Django Twisted PIL Mercurial``
::
Another simple alternative (for all platforms) is to set up a *virtual
Python environment* and install to that. This is covered
pypm install Django Twisted PIL Mercurial
}} Another simple alternative (for all platforms) is to set up a
*virtual Python environment* and install to that. This is covered
`here <GettingStarted#Optional:%3Ci%3EA%3C/i%3Eseparate%3Ci%3Einstallation%3C/i%3Eenvironment%3Ci%3Ewith%3C/i%3Evirtualenv.html>`_.
Windows users not using ActivePython or virtual environments will have
@ -142,14 +146,18 @@ For command-line Mercurial client users, something like this will do the
trick (first place yourself in a directory where you want a new folder
``evennia`` to be created):
``hg clone https://code.google.com/p/evennia/ evennia``
::
hg clone https://code.google.com/p/evennia/ evennia
(``hg`` is the chemical abbreviation of mercury, hence the use of ``hg``
for ``mercurial``)
In the future, you just do
``hg pull``
::
hg pull
from your ``evennia/`` directory to obtain the latest updates.
@ -163,7 +171,9 @@ From within the Evennia ``game`` directory (``evennia/game/``, if you
followed the Subversion instructions above) type the following to
trigger the automatic creation of an empty ``settings.py`` file.
``python manage.py``
::
python manage.py
Your new ``settings.py`` file will just be an empty template initially.
In ``evennia/src/settings_default.py`` you will find the settings that
@ -190,7 +200,9 @@ Finally, enter the following command in a terminal or shell to create
the database file (in the case of SQLite) and populate the database with
the standard tables and values:
``python manage.py syncdb``
::
python manage.py syncdb
You should be asked for a superuser username, email, and password. Make
**sure** you create a superuser here when asked, this becomes your login
@ -202,7 +214,9 @@ double-check your ``settings.py`` file.
If you installed ``South`` for database schema migrations, you will then
need to do this:
``python manage.py migrate``
::
python manage.py migrate
This will migrate the server to the latest version. If you don't use
``South``, migrations will not be used and your server will already be
@ -215,7 +229,9 @@ Step 3: Starting and Stopping the Server
To start the server, make sure you're in the ``evennia/game`` directory
and execute ``evennia.py`` like this:
``python evennia.py -i start``
::
python evennia.py -i start
This starts the server and portal. The ``-i`` flag means that the server
starts in *interactive mode*, as a foreground process. You will see
@ -227,7 +243,9 @@ and debugging but is not recommended for production environments. For
the latter you'll want to run it as a *daemon* by skipping the ``-i``
flag:
``python evennia.py start``
::
python evennia.py start
This will start the server as a background process. Server messages will
be logged to a file you specify in your configuration file (default is a
@ -235,7 +253,9 @@ file in ``game/logs``).
To stop Evennia, do:
``python evennia.py stop``
::
python evennia.py stop
Step 4: Connecting to the server
--------------------------------
@ -269,7 +289,11 @@ or pypm (see above notes).
Whenever you see a commit or mailing list message instructing you to run
migrations to update your DB schema, simply do the following from within
the ``evennia/game`` directory: ``python manage.py migrate``
the ``evennia/game`` directory:
::
python manage.py migrate
You should see migrations being applied, and should be left with an
updated DB schema afterwards.

View file

@ -9,15 +9,15 @@
#
# svn co http://chrisroos.googlecode.com/svn/trunk/google-wiki-syntax wiki2html
#
# This is a ruby program! Sorry, it was the best match I could find to do this.
# So if you don't have ruby, you need that too.
# This is a Ruby program! Sorry, couldn't find a Python lib to do this. So if you
# don't have Ruby, you need to install that too.
#
# You also need to patch a bug in above program to make code snippets work. From the wiki2rest folder,
# apply the patch like this:
# You also need to patch a bug in above program to make multiline code snippets work.
# From the same folder as the patch file, apply the patch like this:
#
# patch -p0 -i wiki2html.patch
#
# 2) Install pandoc:
# 2) Install pandoc (converts from html to reST):
#
# apt-get install pandoc (debian)
# or download from
@ -31,7 +31,7 @@
# 4) Check so that you have the following file structure:
#
# wiki/ (containing google code wiki files)
# wiki2html/ (containing the wiki_converter.rb ruby program.)
# wiki2html/ (containing the wiki_converter.rb ruby program (patch applied).)
# html/ (empty)
# rest/ (empty)
# (this file)
@ -43,7 +43,7 @@
# of rest/ will automatically be copied over to docs/sphinx/source/wiki.
#
import sys, os, subprocess, re
import sys, os, subprocess, re, urllib
# Setup
@ -62,10 +62,96 @@ WIKI2HTML_DIR = os.path.join(CONVERT_DIR, "wiki2html")
PANDOC_EXE = "pandoc"
RUBY_EXE = "ruby"
WIKI_ROOT_URL = "http://code.google.com/p/evennia/wiki/"
WIKI_CRUMB_URL = "/p/evennia/wiki/"
# files to not convert (no file ending)
NO_CONVERT = ["SideBar", "Screenshot"]
#------------------------------------------------------------
# This is a version of the importer that imports Google html pages
# directly instead of going through the ruby converter. Alas, while
# being a lot cleaner in implementation, this seems to produce worse
# results in the end (both visually and with broken-link issues), so
# not using it at this time.
#
# See the wiki2html at the bottom for the ruby-version.
#------------------------------------------------------------
def fetch_google_wiki_html_files():
"""
Acquire wiki html pages from google code
"""
# use wiki repo to find html filenames
html_urls = dict([(re.sub(r"\.wiki", "", fn), WIKI_ROOT_URL + re.sub(r"\.wiki", "?show=content", fn))
for fn in os.listdir(WIKI_DIR) if fn.endswith(".wiki")])
#html_urls = {"Index":html_urls["Index"]} #SR!
html_pages = {}
for name, html_url in html_urls.items():
print "urllib: fetching %s ..." % html_url
f = urllib.urlopen(html_url)
s = f.read()
s = clean_html(s)
html_pages[name] = s #clean_html(f.read())
f.close()
# saving html file for debugging
f = open(os.path.join(HTML_DIR, "%s.html" % name), 'w')
f.write(s)
f.close()
return html_pages
def clean_html(htmlstring):
"""
Clean up html properties special to google code and not known by pandoc
"""
# remove wikiheader tag (searches over many lines). Unfortunately python <2.7 don't support
# DOTALL flag in re.sub ...
matches = re.findall(r'<div id="wikiheader">.*?</div>.*?</div>.*?</div>', htmlstring, re.DOTALL)
for match in matches:
htmlstring = htmlstring.replace(match, "")
#htmlstring = re.sub(r'<div id="wikiheader">.*?</div>.*?</div>.*?</div>', "", htmlstring, re.DOTALL)
# remove prefix from urls
htmlstring = re.sub('href="' + WIKI_CRUMB_URL, 'href="', htmlstring)
# remove #links from headers
htmlstring = re.sub(r'(<h[0-9]>.*?)(<a href="#.*?</a>)(.*?</h[0-9]>)', r"\1\3", htmlstring)
return htmlstring
def html2rest(name, htmlstring):
"""
Convert html data to reST with pandoc
"""
print "pandoc: Converting %s ..." % name
p = subprocess.Popen([PANDOC_EXE, '--from=html', '--to=rst', '--reference-links'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
return p.communicate(htmlstring)[0]
def wiki2rest_ver2():
"""
Convert Google wiki pages to reST.
"""
# obtain all html data from google code
html_pages = fetch_google_wiki_html_files()
# convert to output files
for name, htmldata in html_pages.items():
restfilename = os.path.join(REST_DIR, "%s.rst" % name)
f = open(restfilename, 'w')
f.write(html2rest(name, htmldata))
f.close()
#------------------------------------------------------------
# This converter uses the 3rd party ruby script to convert wiki pages
# to html, seems to produce a better final result than downloading html
# directly from google code.
#------------------------------------------------------------
def wiki2rest():
"""
Convert from wikifile to rst file, going through html
@ -82,6 +168,7 @@ def wiki2rest():
htmlfilename = os.path.join(HTML_DIR, filename)
# cleanup of code
string = "".join(open(htmlfilename, 'r').readlines())
string = re.sub(r'<p class="summary">[A-Za-z0-9 .-\:]*</p>', "", string)
string = re.sub(r"&lt;wiki:toc max_depth=&quot;[0-9]*&quot; /&gt;", "", string)
@ -99,6 +186,8 @@ def wiki2rest():
print "pandoc: converting %s -> %s" % (htmlfilename, rstfilename)
subprocess.call([PANDOC_EXE, "--from=html", "--to=rst", "-o", rstfilename, htmlfilename])
# main program
if __name__ == "__main__":
try: