Differences between revisions 4 and 11 (spanning 7 versions)
Revision 4 as of 2008-08-07 11:38:51
Size: 3798
Editor: TerryBoz
Comment:
Revision 11 as of 2008-08-08 07:54:03
Size: 4189
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 5: Line 7:
Line 6: Line 9:
Line 7: Line 11:
!CherryPy can run WSGI compliant applications like hgweb and hgwebdir. !CherryPy can run WSGI compliant applications like ~+`hgweb`+~ and ~+`hgwebdir`+~.
Line 14: 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 17: 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 50: 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 52: 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 54: Line 58:
Suggested filename is cphgwebdir.py Suggested filename is ~+`cphgwebdir.py`+~
Line 65: 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 74: Line 78:
# Change these to suit your repositories: # Change this to represent your repository/ies:
Line 76: Line 80:
    #('<virtual path>','<absolute path>'),
Line 106: Line 111:
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 108: Line 113:
Change tuples in lRepos list to suit, must have leading forward slash on first element of each tuple. Change tuples in ~+`lRepos`+~ list to indicate the repositories that you want published, first element of each tuple must have a leading forward slash.
Line 110: Line 115:
Suggested filename is cphgweb.py Suggested filename is ~+`cphgweb.py`+~
Line 116: Line 121:
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 118: Line 123:
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     #('<virtual path>','<absolute path>'),
  10     ('/project1',r'C:\Program Files\DemoRepos\project1'),
  11     ('/project2',r'C:\Program Files\DemoRepos\project2'),
  12     ('/project3',r'C:\Program Files\DemoRepos\project3')
  13 ]
  14 
  15 # Adjust encoding to suit or comment out:
  16 import os
  17 os.environ['HGENCODING']='UTF-8'
  18 
  19 import sys
  20 # Adjust path to your Mercurial Lib folder:
  21 sys.path.append(r'C:\Program Files\Mercurial\Lib')
  22 from mercurial.hgweb.hgweb_mod import hgweb
  23 
  24 import cherrypy
  25 cherrypy.config.update({
  26     # Default is development environment, uncomment below when in production
  27     #'environment':'production',
  28     'engine.autoreload.on':True,
  29     'server.socket_host':sUrlHost,
  30     'server.socket_port':iUrlPort,
  31     'log.error_file':'error.log',
  32     'log.screen':True
  33 })
  34 for (sName,sPath) in lRepos:
  35     cherrypy.tree.graft(hgweb(sPath),script_name=sName)
  36 cherrypy.engine.start()
  37 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 indicate 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)