Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmn committed Mar 16, 2012
0 parents commit 43ab7f8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
*~
*.pyc
10 changes: 10 additions & 0 deletions README.md
@@ -0,0 +1,10 @@
Git-backed web server
=====================

This allows you to serve websites directly from the git repository,
without having to worry about deployment.

Specially useful if your gh-pages branch needs a web server, because
it relies heavily on javascript to work and you have better things
than switching to that branch or don't want to publish the branch yet
(testing docurium, for example)
40 changes: 40 additions & 0 deletions git-httpd.py
@@ -0,0 +1,40 @@
#!/usr/bin/env python

from flask import Flask, render_template, url_for, abort
import os, os.path, md5
import pygit2 as git
from time import gmtime, strftime
from urllib import urlencode

REPO_NAME = os.getenv('HOME') + "/git/libgit2/"

app = Flask(__name__)

@app.route('/')
def serve_index():
return serve('index.html')

@app.route('/<path:filename>')
def serve(filename):
print("opening " + REPO_NAME)
repo = git.Repository(REPO_NAME)
oid = repo.lookup_reference('refs/heads/gh-pages').resolve().oid
tree = repo[oid].tree
parts = filename.split('/')
while len(parts) > 1:
dirname = parts.pop(0)
print("dirname " + dirname)
tree = tree[dirname].to_object()

last = parts.pop(0)
if last == '':
last = 'index.html'

try:
return tree[last].to_object().data
except KeyError:
abort(404)

if __name__ == "__main__":
app.debug = True
app.run()

0 comments on commit 43ab7f8

Please sign in to comment.