Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 43ab7f8
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*~ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |