Skip to content
This repository has been archived by the owner on Jan 14, 2019. It is now read-only.

Commit

Permalink
(hopefully) fixed weird behaviour of setuptools' easy_install.
Browse files Browse the repository at this point in the history
added option to specify an own version of gitweb.cgi
added option to listen only locally (not on hostname)
made resource handling (media files) more robust using pkg_resources
  • Loading branch information
jezdez committed Apr 28, 2008
1 parent 0f1e2c0 commit bb250f9
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 29 deletions.
9 changes: 7 additions & 2 deletions README.txt
Expand Up @@ -31,10 +31,12 @@ Usage pretty easy::
-q, --quiet don't print anything to stdout
-p PORT, --port=PORT port to listen on (default: 8000)
-a ADDRESS, --address=ADDRESS
address to listen on (default: all interfaces)
address to listen on (default: hostname)
-l, --local only listen on 127.0.0.1
-b, --browser open default browser automatically
-d, --daemon detach from terminal and become a daemon
--pid-file=PIDFILE write the spawned process-id to this file
--gitweb=GITWEB use this gitweb cgi file instead of the included

As the only argument you can specify a directory that contains your git
projects. If you leave this argument blank ``git-serve`` will automatically uses
Expand All @@ -52,7 +54,8 @@ port 8000, for example: http://127.0.0.1:8000/

If you provide a ``--port`` or ``--address`` option while starting ``git-serve``
you can have ``git-serve`` listen on your choices. You need to be root to run it
on port 80 or any other port below 1024.
on port 80 or any other port below 1024. The ``--local`` option tells
``git-serve`` to listen only on ``127.0.0.1``.

The ``--browser`` option tells ``git-serve`` to automatically start your system's
default web browser with the URL of the ``git-serve`` server while starting it.
Expand All @@ -62,3 +65,5 @@ current shell session, becoming a daemon process that runs in background. This
is very useful in combination with the ``--pid-file`` option that write the
process id in the given file.

You can specify the location of the gitweb.cgi file that ``git-serve`` uses
with the ``--gitweb`` option (e.g. /home/jannis/lib/git/gitweb.cgi).
32 changes: 25 additions & 7 deletions setup.py
@@ -1,14 +1,33 @@
#!/usr/bin/env python

import os, sys, stat
from setuptools import setup, find_packages
import os, sys
try:
from setuptools import find_packages, setup
from setuptools.command.easy_install import easy_install
except ImportError:
sys.exit("Please install a recent version of setuptools")

easy_install.real_process_distribution = easy_install.process_distribution
def process_distribution(self, *args, **kwargs):
"""Brutally ugly hack to have post_install functionality. oh. my. god."""
easy_install.real_process_distribution(self, *args, **kwargs)

import pkg_resources
try:
pkg_resources.require("gitserve")
gitweb_cgi = pkg_resources.resource_filename("gitserve", "gitweb.cgi")
os.chmod(gitweb_cgi, 0755)
except:
print "Chmodding failed. Try 'chmod +x /path/to/gitserve/gitweb.cgi'"
easy_install.process_distribution = process_distribution

setup(
name='gitserve',
version='0.1.1',
license='GPL2',
version='0.2.0',
license='GPL-2',
description="A helper tool for git that mimics mercurial\'s serve command",
long_description=open(os.path.join(os.path.dirname(__file__), 'README.txt')).read(),
long_description=open('README.txt', 'r').read(),
maintainer='Jannis Leidel',
author='Jannis Leidel',
author_email='jannis@leidel.info',
url='http://github.com/jezdez/git-serve/',
Expand All @@ -26,10 +45,9 @@
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Internet :: WWW/HTTP :: HTTP Servers',
],
install_requires=["setuptools"],
packages=find_packages('src'),
package_dir={'':'src'},
package_data={'': ['media/*.*', '*.so', '*.conf'],},
package_data={'': ['media/*.*', '*.cgi', '*.conf'],},
entry_points={'console_scripts': ['git-serve = gitserve:main',],},
zip_safe=False,
include_package_data = True,
Expand Down
56 changes: 36 additions & 20 deletions src/gitserve/__init__.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
# encoding: utf-8

__version__ = '0.1.1'
__version__ = '0.2.0'

import os
import sys
Expand All @@ -11,10 +11,10 @@
from urlparse import urljoin
from optparse import OptionParser
from BaseHTTPServer import HTTPServer
from socket import gethostname, gethostbyaddr
from pkg_resources import resource_filename
from CGIHTTPServer import CGIHTTPRequestHandler

gitserve_dir = os.path.dirname(os.path.abspath(__file__))
from socket import error as SocketError
from socket import gethostname, gethostbyaddr

def become_daemon(home='.', out_log='/dev/null', err_log='/dev/null'):
"Robustly turn into a UNIX daemon, running in our_home_dir."
Expand Down Expand Up @@ -48,9 +48,8 @@ def become_daemon(home='.', out_log='/dev/null', err_log='/dev/null'):

class GitWebRequestHandler(CGIHTTPRequestHandler):
cgi_directories = []
aliases = [
('/media', os.path.join(gitserve_dir, "media")),
]
gitserve_media = resource_filename("gitserve", "media")
aliases = [('/media', gitserve_media),]
verbose = False

def log_message(self, format, *args):
Expand Down Expand Up @@ -119,7 +118,10 @@ def main():
help="port to listen on (default: 8000)", default=8000)
parser.add_option("-a", "--address",
dest="address", default="",
help="address to listen on (default: all interfaces)")
help="address to listen on (default: hostname)")
parser.add_option("-l", "--local",
action="store_true", dest="local", default=False,
help="only listen on 127.0.0.1")
parser.add_option("-b", "--browser",
action="store_true", dest="browser", default=False,
help="open default browser automatically")
Expand All @@ -129,8 +131,18 @@ def main():
parser.add_option("--pid-file",
dest="pidfile", default="",
help="write the spawned process-id to this file")
parser.add_option("--gitweb",
dest="gitweb", default="",
help="use this gitweb cgi file instead of the included version")
(options, args) = parser.parse_args()

# get path to gitweb.cgi file
gitweb_cgi = options.gitweb
if not gitweb_cgi:
gitweb_cgi = resource_filename('gitserve', 'gitweb.cgi')
if not os.access(gitweb_cgi, os.X_OK):
parser.error("Your gitweb.cgi is not executable. Try 'chmod +x %s'" % gitweb_cgi)

if len(args) > 1:
parser.error("incorrect number of arguments")
if args:
Expand All @@ -155,19 +167,21 @@ def main():
if os.path.exists(os.path.expanduser('~/.gitwebconfig')):
gitweb_conf = os.path.expanduser('~/.gitwebconfig')
else:
gitweb_conf = os.path.join(gitserve_dir, 'gitweb.conf')
gitweb_conf = resource_filename('gitserve', 'gitweb.conf')
os.environ['GITWEB_CONFIG'] = gitweb_conf

# get hostname from the system and build urls and path to cgi
if not options.address:
options.address = gethostname()
else:
options.address = gethostbyaddr(options.address)[0]

listen = options.address, options.port
# get hostname from the system and build url
try:
if options.local:
options.address = '127.0.0.1'
elif not options.address:
options.address = gethostname()
else:
options.address = gethostbyaddr(options.address)[0]
except SocketError, e:
parser.error(e)
gitweb_url = "http://%s:%d/%s/" % (options.address, options.port, repo_name)
gitweb_cgi = os.path.join(gitserve_dir, 'gitweb.cgi.so')


# start daemon mode
if options.daemon:
options.verbose = False
Expand All @@ -183,8 +197,7 @@ def main():
GitWebRequestHandler.verbose = options.verbose
GitWebRequestHandler.cgi_directories.append('/%s' % repo_name)
GitWebRequestHandler.aliases.append(('/%s' % repo_name, gitweb_cgi))

httpd = HTTPServer(listen, GitWebRequestHandler)
httpd = HTTPServer((options.address, options.port), GitWebRequestHandler)

if options.verbose:
print "starting gitweb at: %s" % gitweb_url
Expand All @@ -197,6 +210,9 @@ def main():
httpd.serve_forever()
except KeyboardInterrupt:
pass
except SocketError:
if options.verbose:
raise

if __name__ == "__main__":
main()
File renamed without changes.

0 comments on commit bb250f9

Please sign in to comment.