Differences between revisions 3 and 11 (spanning 8 versions)
Revision 3 as of 2008-07-31 05:33:54
Size: 1757
Editor: khelben
Comment:
Revision 11 as of 2012-11-11 11:37:41
Size: 7096
Editor: abuehl
Comment: de-link ConfigParser
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
Line 4: Line 3:
~-Written by a newbie, for newbies.-~<<BR>> ~-Versions specified are the versions used when writing this tutorial and may not reflect current versions available.-~
Line 7: Line 7:
[http://wampserver.com/en/ WAMP 2.0c] Special thanks to djc for all the help in IRC.
Line 9: Line 9:
[http://www.python.org/ Python 2.5.2 (32 bit)] [[http://wampserver.com/en/|WAMP 2.0c]]
Line 11: Line 11:
[http://apache.ziply.com/httpd/modpython/win/3.3.1/ mod_python v3.3.1 (win32) (py2.5) (Apache2.2)] [[http://www.python.org/|Python 2.5.2 (32 bit)]]
Line 13: Line 13:
[http://sourceforge.net/project/showfiles.php?group_id=78018&package_id=79063 Python Win32 API (py2.5)] mod_python v3.3.1 (win32) (py2.5) (Apache2.2)
Line 15: Line 15:
[http://www.selenic.com/mercurial/wiki/index.cgi/BinaryPackages Mercurial v1.01] [[http://sourceforge.net/project/showfiles.php?group_id=78018&package_id=79063|Python Win32 API (py2.5)]]

[
[http://www.selenic.com/mercurial/wiki/index.cgi/BinaryPackages|Mercurial v1.01]]
Line 18: Line 20:
'''1.''' Install WAMP if not already installed.
Line 19: Line 22:
Extract c:\wamp\mercurial\library.zip to C:\wamp\mercurial\lib  * Your installation directory will be referred to as `<WAMPPath>`
 * Be sure to enable mod_rewrite.
Line 21: Line 25:
Create 'hg' dir in c:\wamp\www '''2.''' Install Python 2.5 if not installed.
Line 23: Line 27:
Download [http://svn.aminus.net/misc/modpython_gateway.py modpython_gateway.py] and install to <Python Path>Lib\site-packages  * Your installation directory will be referred to as `<PythonPath>`
Line 25: Line 29:
Download [http://www.selenic.com/repo/hg-stable/raw-file/tip/hgwebdir.cgi hgwebdir.cgi] and place in c:\wamp\mercurial\ (One doesn't come in the binary package unless I missed it) '''3.''' Install mod_python.
Line 27: Line 31:
Rename hgwebdir.cgi to hgwebdir.py  * When installing mod_python you will be asked for your Apache directory. This will depend on the version of apache you are using, in 2.0c it is 2.2.8 so in this example it is: `<WAMPPath>\bin\apache\apache2.2.8`<<BR>><<BR>>
 * Additionally you will need to add the appropriate line to httpd.conf to add the module. This can easily be done by clicking the WAMP system tray, going to the Apache folder, and clicking httpd.conf.
  . Search for `LoadModule proxy_http_module modules/mod_proxy_http.so` and add the following line afterward: `LoadModule python_mod modules/mod_python.so`
Line 29: Line 35:
Edit hgwebdir.py to the following: '''4.''' Install Python Win32 API
Line 31: Line 37:
  ...blah... '''5.''' Install Mercurial Binaries
Line 33: Line 39:
 * I suggest installing Mercurial to the location where you are going to house your repository(ies)
 * You should know that due to limitations of Python's !ConfigParser class, repositories on Windows have a tough time with drive letters. Keep that in mind when choosing your installation home. (I chose to install to (D:) because it's raided and has more space on my system)
 * Your install path will be `<MercurialPath>`
Line 34: Line 43:
Create c:\wamp\alias\hg.conf with the following contents: '''6.''' Extract `<MercurialPath>`\library.zip to `<MercurialPath>`\lib
Line 36: Line 45:
'''7.''' Create 'hg' dir in `<WAMPPath>`\www

'''8.''' Download [[http://svn.aminus.net/misc/modpython_gateway.py|modpython_gateway.py]] and install to <Python Path>\Lib\site-packages

'''9.''' Download [[http://www.selenic.com/repo/hg-stable/raw-file/tip/hgwebdir.cgi|hgwebdir.cgi]] and place in `<MercurialPath>` (One doesn't come in the binary package unless I missed it)

 * Rename hgwebdir.cgi to hgwebdir.py
 * Edit hgwebdir.py to the following replacing '''''any''' previously defined path variable with their '''fully qualified paths''''':

'''hgwebdir.py'''

{{{#!python numbers=disable
#!<PythonPath>\python.exe
#
# An example Python script to export multiple hgweb repos, edit as necessary

# Add a python path if mercurial is not a system-wide install:
#import sys
#sys.path.insert(0, "<MercurialPath>\lib")

# Changes Python Working path to support collections in windows with mod_python
#import os
#os.chdir("<MercurialPath>")

# enable importing on demand to reduce startup time
from mercurial import demandimport; demandimport.enable()

# Uncomment to send python tracebacks to the browser if an error occurs:
#import cgitb
#cgitb.enable()

# If you'd like to serve pages with UTF-8 instead of your default
# locale charset, you can do so by uncommenting the following lines.
# Note that this will cause your .hgrc files to be interpreted in
# UTF-8 and all your repo files to be displayed using UTF-8.
#
#import os
#os.environ["HGENCODING"] = "UTF-8"

from mercurial.hgweb.hgwebdir_mod import hgwebdir
#import mercurial.hgweb.wsgicgi as wsgicgi

# The config file looks like this. You can have paths to individual
# repos, collections of repos in a directory tree, or both.
#
# [paths]
# virtual/path = /real/path
# virtual/path = /real/path
#
# [collections]
# /prefix/to/strip/off = /root/of/tree/full/of/repos
#
# collections example: say directory tree /foo contains repos /foo/bar,
# /foo/quux/baz. Give this config section:
# [collections]
# /foo = /foo
# Then repos will list as bar and quux/baz.
#
# Alternatively you can pass a list of ('virtual/path', '/real/path') tuples
# or use a dictionary with entries like 'virtual/path': '/real/path'

application = hgwebdir('hgweb.config')
#wsgicgi.launch(application)
}}}
'''10.''' Create `<WAMPPath>`\alias\hg.conf with the following contents:

 * Be sure to replace `<MercurialPath>` with the proper value (i.e. D:\Mercurial)
 * Don't forget the single quotes

'''hg.conf''' {{{
Line 38: Line 117:
  PythonPath "sys.path + [ 'c:\\wamp\\mercurial' ]" PythonPath "sys.path + [ '<MercurialPath>' ]"
#PythonDebug On
#Uncomment this line if you got a problem and need debug information
SetHandler mod_python
PythonHandler modpython_gateway::handler
PythonOption SCRIPT_NAME /hg
PythonOption wsgi.application hgwebdir::application
Line 40: Line 125:
  #PythonDebug On #Uncomment this line if you got a problem and need debug information </Location>}}}
Line 42: Line 127:
  SetHandler mod_python '''11.''' Create `<MercurialPath>`\hgweb.conf
Line 44: Line 129:
  PythonHandler modpython_gateway::handler  * This file will be your config file for HGWEBDIR.
 * It must contain the '''RELATIVE''' path to your repositories from your Python Working Directory.
 * The path structure is WINDOWS_FORMAT\ = UNIX_FORMAT/ '''the slash direction is VERY IMPORTANT!'''
 * If hgweb.conf is incorrectly configured you may experience the following:
  * %5C URL Errors.
  * No repositories displayed.
Line 46: Line 136:
  PythonOption SCRIPT_NAME /hg Here is an example for a configuration containing collections in a directory called 'repos' which is a subdirectory of my Mercurial install (Which I set to be my Python Working Directory in hgwebdir.py).
Line 48: Line 138:
  PythonOption wsgi.application hgwebdir::application '''hgweb.conf''' {{{
[collections] repos\ = repos/
}}}
Line 50: Line 142:
</Location> '''12.''' Restart Apache
Line 52: Line 144:
== Installation Notes ==
=== hgwebdir.py ===
{{{#!python numbers=disable
# Add a python path if mercurial is not a system-wide install:
#import sys
#sys.path.insert(0, "<MercurialPath>\lib")
}}}
Line 53: Line 152:
Restart Apache Uncommenting the last 2 lines here will add another path that Python will search.<<BR>> Necessary for this install.<<BR>> Not necessary if you compiled from source and did a global install.<<BR>>
Line 55: Line 154:
{{{#!python numbers=disable
# Changes Python Working path to support collections in windows with mod_python
#import os
#os.chdir("<MercurialPath>")
}}}

Uncommenting the last two lines here will forcibly change the Python working directory.<<BR>> This is probably necessary for any Mercurial install on windows that uses mod_python, unless your repositories are located in a sub dir of `<PythonPath>\Lib\site-installs` which I don't think anyone in their right mind would do.

{{{#!python numbers=disable
#wsgicgi.launch(application)
}}}
Make sure this is commented out or deleted, in the raw file it is not and will error you out.

Caveats:

Some errors will appear in appache error log, they can be ignored:

 . ..Errors...
Line 60: Line 177:
http://slucas.wikidot.com/en:hgweb-mod-python http://blog.slucas.fr/en/oss/hgweb-mod_python
Line 63: Line 180:


Caveats:

Some errors will appear in appache error log, they can be ignored:

 ...Errors...

WAMP Installation notes

Binaries and requirements used in setup:

Written by a newbie, for newbies.
Versions specified are the versions used when writing this tutorial and may not reflect current versions available.

INCOMPLETE - Need to finish.

Special thanks to djc for all the help in IRC.

WAMP 2.0c

Python 2.5.2 (32 bit)

mod_python v3.3.1 (win32) (py2.5) (Apache2.2)

Python Win32 API (py2.5)

Mercurial v1.01

Installation Steps

1. Install WAMP if not already installed.

  • Your installation directory will be referred to as <WAMPPath>

  • Be sure to enable mod_rewrite.

2. Install Python 2.5 if not installed.

  • Your installation directory will be referred to as <PythonPath>

3. Install mod_python.

  • When installing mod_python you will be asked for your Apache directory. This will depend on the version of apache you are using, in 2.0c it is 2.2.8 so in this example it is: <WAMPPath>\bin\apache\apache2.2.8

  • Additionally you will need to add the appropriate line to httpd.conf to add the module. This can easily be done by clicking the WAMP system tray, going to the Apache folder, and clicking httpd.conf.
    • Search for LoadModule proxy_http_module modules/mod_proxy_http.so and add the following line afterward: LoadModule python_mod modules/mod_python.so

4. Install Python Win32 API

5. Install Mercurial Binaries

  • I suggest installing Mercurial to the location where you are going to house your repository(ies)
  • You should know that due to limitations of Python's ConfigParser class, repositories on Windows have a tough time with drive letters. Keep that in mind when choosing your installation home. (I chose to install to (D:) because it's raided and has more space on my system)

  • Your install path will be <MercurialPath>

6. Extract <MercurialPath>\library.zip to <MercurialPath>\lib

7. Create 'hg' dir in <WAMPPath>\www

8. Download modpython_gateway.py and install to <Python Path>\Lib\site-packages

9. Download hgwebdir.cgi and place in <MercurialPath> (One doesn't come in the binary package unless I missed it)

  • Rename hgwebdir.cgi to hgwebdir.py
  • Edit hgwebdir.py to the following replacing any previously defined path variable with their fully qualified paths:

hgwebdir.py

#!<PythonPath>\python.exe
#
# An example Python script to export multiple hgweb repos, edit as necessary

# Add a python path if mercurial is not a system-wide install:
#import sys
#sys.path.insert(0, "<MercurialPath>\lib")

# Changes Python Working path to support collections in windows with mod_python
#import os
#os.chdir("<MercurialPath>")

# enable importing on demand to reduce startup time
from mercurial import demandimport; demandimport.enable()

# Uncomment to send python tracebacks to the browser if an error occurs:
#import cgitb
#cgitb.enable()

# If you'd like to serve pages with UTF-8 instead of your default
# locale charset, you can do so by uncommenting the following lines.
# Note that this will cause your .hgrc files to be interpreted in
# UTF-8 and all your repo files to be displayed using UTF-8.
#
#import os
#os.environ["HGENCODING"] = "UTF-8"

from mercurial.hgweb.hgwebdir_mod import hgwebdir
#import mercurial.hgweb.wsgicgi as wsgicgi

# The config file looks like this.  You can have paths to individual
# repos, collections of repos in a directory tree, or both.
#
# [paths]
# virtual/path = /real/path
# virtual/path = /real/path
#
# [collections]
# /prefix/to/strip/off = /root/of/tree/full/of/repos
#
# collections example: say directory tree /foo contains repos /foo/bar,
# /foo/quux/baz.  Give this config section:
#   [collections]
#   /foo = /foo
# Then repos will list as bar and quux/baz.
#
# Alternatively you can pass a list of ('virtual/path', '/real/path') tuples
# or use a dictionary with entries like 'virtual/path': '/real/path'

application = hgwebdir('hgweb.config')
#wsgicgi.launch(application)

10. Create <WAMPPath>\alias\hg.conf with the following contents:

  • Be sure to replace <MercurialPath> with the proper value (i.e. D:\Mercurial)

  • Don't forget the single quotes

hg.conf

<Location /hg>

PythonPath "sys.path + [ '<MercurialPath>' ]"
#PythonDebug On
#Uncomment this line if you got a problem and need debug information
SetHandler mod_python
PythonHandler modpython_gateway::handler
PythonOption SCRIPT_NAME /hg
PythonOption wsgi.application hgwebdir::application

</Location>

11. Create <MercurialPath>\hgweb.conf

  • This file will be your config file for HGWEBDIR.
  • It must contain the RELATIVE path to your repositories from your Python Working Directory.

  • The path structure is WINDOWS_FORMAT\ = UNIX_FORMAT/ the slash direction is VERY IMPORTANT!

  • If hgweb.conf is incorrectly configured you may experience the following:
    • %5C URL Errors.
    • No repositories displayed.

Here is an example for a configuration containing collections in a directory called 'repos' which is a subdirectory of my Mercurial install (Which I set to be my Python Working Directory in hgwebdir.py).

hgweb.conf

[collections] repos\ = repos/

12. Restart Apache

Installation Notes

hgwebdir.py

# Add a python path if mercurial is not a system-wide install:
#import sys
#sys.path.insert(0, "<MercurialPath>\lib")

Uncommenting the last 2 lines here will add another path that Python will search.
Necessary for this install.
Not necessary if you compiled from source and did a global install.

# Changes Python Working path to support collections in windows with mod_python
#import os
#os.chdir("<MercurialPath>")

Uncommenting the last two lines here will forcibly change the Python working directory.
This is probably necessary for any Mercurial install on windows that uses mod_python, unless your repositories are located in a sub dir of <PythonPath>\Lib\site-installs which I don't think anyone in their right mind would do.

#wsgicgi.launch(application)

Make sure this is commented out or deleted, in the raw file it is not and will error you out.

Caveats:

Some errors will appear in appache error log, they can be ignored:

  • ..Errors...

References:

http://www.selenic.com/mercurial/wiki/index.cgi/HgWebDirStepByStep

http://blog.slucas.fr/en/oss/hgweb-mod_python

http://www.modpython.org/FAQ/faqw.py?req=show&file=faq03.029.htp

WAMPInstall (last edited 2012-11-11 11:37:41 by abuehl)