Differences between revisions 3 and 6 (spanning 3 versions)
Revision 3 as of 2008-08-07 11:36:31
Size: 3800
Editor: TerryBoz
Comment:
Revision 6 as of 2008-08-07 11:47:54
Size: 3805
Editor: TerryBoz
Comment:
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
  !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 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.
Line 7: Line 9:
Line 64: Line 65:
Use this if you don't want the fancy Browser front-end. Use this if you don't want the fancy browser front-end.
Line 109: Line 110:
Change tuples in lRepos list to suit, must have leading forward slash on first element of each tuple. Change tuples in lRepos list to suit, first element of each tuple must have a leading forward slash.
Line 118: Line 119:
----

Publishing Repositories Using CherryPy

Introduction

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 these to suit your repositories:
   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 suit, 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.


CategoryHowTo

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