Differences between revisions 5 and 10 (spanning 5 versions)
Revision 5 as of 2008-08-07 11:42:58
Size: 3801
Editor: TerryBoz
Comment:
Revision 10 as of 2008-08-07 12:27:08
Size: 4081
Editor: TerryBoz
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
For a really really simple way of publishing your Mercurial repositories on the Web without the need for Apache or IIS.
Line 9: Line 11:
!CherryPy can run WSGI compliant applications like hgweb and hgwebdir. !CherryPy can run WSGI compliant applications like `hgweb` and `hgwebdir`.
Line 16: Line 18:
Read PublishingRepositories and HgWebDirStepByStep first to get an understanding of hgweb, hgwebdir, the hgweb.config file and Mercurial Lib folder setup. Read PublishingRepositories and HgWebDirStepByStep first to get an understanding of `hgweb`, `hgwebdir`, the `hgweb.config` file and Mercurial `Lib` folder setup.
Line 19: Line 21:
Here is my sample code that utilizes the hgwebdir module. Edit this code to suit your needs: Here is my sample code that utilizes the `hgwebdir` module. Edit this code to suit your needs:
Line 52: Line 54:
sUrlHost can be IP number or domain name (usually, depending on how your network is set up). `sUrlHost` can be IP number or domain name (usually, depending on how your network is set up).
Line 54: Line 56:
Save this code into the same folder as hgweb.config. Unless you have added a path, then save to the root of that path. Save this code into the same folder as `hgweb.config`. Unless you have added a path, then save to the root of that path.
Line 56: Line 58:
Suggested filename is cphgwebdir.py Suggested filename is `cphgwebdir.py`
Line 67: Line 69:
Here is my sample code that utilizes the hgweb module. Edit this code to suit your needs: Here is my sample code that utilizes the `hgweb` module. Edit this code to suit your needs:
Line 76: Line 78:
# Change these to suit your repositories: # Change this to represent your repository/ies:
Line 108: Line 110:
sUrlHost can be IP number or domain name (usually, depending on how your network is set up). `sUrlHost` can be IP number or domain name (usually, depending on how your network is set up).
Line 110: Line 112:
Change tuples in lRepos list to suit, first element of each tuple must have a leading forward slash. Change tuples in `lRepos` list to show the repositories that you want published, first element of each tuple must have a leading forward slash.
Line 112: Line 114:
Suggested filename is cphgweb.py Suggested filename is `cphgweb.py`
Line 118: Line 120:
You can make changes to the lRepos list while it is running, saving changes will initiate a restart. You can make changes to the `lRepos` list while it is running, saving changes will initiate a restart.
Line 120: Line 122:
Example command:
{{{
hg clone "http://192.168.0.10:8080/project2"
}}}
----

Publishing Repositories Using CherryPy

Introduction

For a really really simple way of publishing your Mercurial repositories on the Web without the need for Apache or IIS.

Some quotes from the CherryPy Web site:

  • CherryPy is a pythonic, object-oriented HTTP framework.

    CherryPy powered web applications are in fact stand-alone Python applications embedding their own multi-threaded web server.

    CherryPy applications run on Windows, Linux, Mac OS X and any other platform supporting Python.

CherryPy can run WSGI compliant applications like hgweb and hgwebdir.

Pre-requisties

Python 2.4 or newer (http://www.python.org/download/)

CherryPy 3.1 or newer (http://www.cherrypy.org/)

Read PublishingRepositories and HgWebDirStepByStep first to get an understanding of hgweb, hgwebdir, the hgweb.config file and Mercurial Lib folder setup.

Using HgWebDir

Here is my sample code that utilizes the hgwebdir module. Edit this code to suit your needs:

   1 # cphgwebdir.py
   2 
   3 # Adjust host and port to suit your Web presence:
   4 sUrlHost='0.0.0.0'
   5 iUrlPort=8080
   6 
   7 # Adjust encoding to suit or comment out:
   8 import os
   9 os.environ['HGENCODING']='UTF-8'
  10 
  11 import sys
  12 # Adjust path to your Mercurial Lib folder:
  13 sys.path.append(r'C:\Program Files\Mercurial\Lib')
  14 from mercurial.hgweb.hgwebdir_mod import hgwebdir
  15 
  16 import cherrypy
  17 cherrypy.config.update({
  18     # Default is development environment, uncomment below when in production
  19     #'environment':'production',
  20     'server.socket_host':sUrlHost,
  21     'server.socket_port':iUrlPort,
  22     'log.error_file':'error.log',
  23     'log.screen':True
  24 })
  25 # Use same hgweb.config file as for hgwebdir.cgi
  26 cherrypy.tree.graft(hgwebdir('hgweb.config'),script_name='/')
  27 cherrypy.engine.start()
  28 cherrypy.engine.block()

sUrlHost can be IP number or domain name (usually, depending on how your network is set up).

Save this code into the same folder as hgweb.config. Unless you have added a path, then save to the root of that path.

Suggested filename is cphgwebdir.py

From a command line just execute the file, like this from its folder:

/path/to/python cphgwebdir.py

That's it.

Using HgWeb

Use this if you don't want the fancy browser front-end.

Here is my sample code that utilizes the hgweb module. Edit this code to suit your needs:

   1 # cphgweb.py
   2 
   3 # Adjust host and port to suit your Web presence:
   4 sUrlHost='0.0.0.0'
   5 iUrlPort=8080
   6 
   7 # Change this to represent your repository/ies:
   8 lRepos=[
   9     ('/project1',r'C:\Program Files\DemoRepos\project1'),
  10     ('/project2',r'C:\Program Files\DemoRepos\project2'),
  11     ('/project3',r'C:\Program Files\DemoRepos\project3')
  12 ]
  13 
  14 # Adjust encoding to suit or comment out:
  15 import os
  16 os.environ['HGENCODING']='UTF-8'
  17 
  18 import sys
  19 # Adjust path to your Mercurial Lib folder:
  20 sys.path.append(r'C:\Program Files\Mercurial\Lib')
  21 from mercurial.hgweb.hgweb_mod import hgweb
  22 
  23 import cherrypy
  24 cherrypy.config.update({
  25     # Default is development environment, uncomment below when in production
  26     #'environment':'production',
  27     'engine.autoreload.on':True,
  28     'server.socket_host':sUrlHost,
  29     'server.socket_port':iUrlPort,
  30     'log.error_file':'error.log',
  31     'log.screen':True
  32 })
  33 for (sName,sPath) in lRepos:
  34     cherrypy.tree.graft(hgweb(sPath),script_name=sName)
  35 cherrypy.engine.start()
  36 cherrypy.engine.block()

sUrlHost can be IP number or domain name (usually, depending on how your network is set up).

Change tuples in lRepos list to show the repositories that you want published, first element of each tuple must have a leading forward slash.

Suggested filename is cphgweb.py

From a command line just execute the file, like this from its folder:

/path/to/python cphgweb.py

You can make changes to the lRepos list while it is running, saving changes will initiate a restart.

Example command:

hg clone "http://192.168.0.10:8080/project2"


CategoryHowTo

PublishingRepositoriesUsingCherryPy (last edited 2009-08-15 05:53:51 by TerryBoz)