50 lines
1.0 KiB
Python
50 lines
1.0 KiB
Python
import os
|
|
import sys
|
|
from os.path import dirname, abspath, basename, splitext, join as pathjoin
|
|
|
|
import pygit2
|
|
from bottle import route, run, static_file, redirect
|
|
|
|
HERE = dirname(abspath(__file__))
|
|
ROOT = dirname(HERE)
|
|
STATIC = pathjoin(HERE, 'static')
|
|
REPOS = {}
|
|
|
|
def populate_repos(repos_root):
|
|
for dirpath, dirnames, filenames in os.walk(repos_root):
|
|
|
|
def add_entry():
|
|
REPOS[splitext(basename(dirpath))[0]] = \
|
|
pygit2.Repository(pathjoin(dirpath, dirname))
|
|
|
|
if dirpath == '.git':
|
|
add_entry()
|
|
dirnames[:] = []
|
|
for dirname in dirnames[:]:
|
|
if dirname == '.git':
|
|
add_entry()
|
|
|
|
|
|
populate_repos(sys.argv[1] if sys.argv[1:] else ROOT)
|
|
|
|
|
|
@route('/')
|
|
def root_index():
|
|
return {}
|
|
|
|
|
|
@route('/repos')
|
|
def repos():
|
|
return dict((
|
|
(key, value.workdir) for key, value in REPOS.copy().items()
|
|
))
|
|
|
|
|
|
@route('/repos/<name>')
|
|
def repo(name):
|
|
return {'path': REPOS.get(name, '???').workdir}
|
|
|
|
|
|
if __name__ == '__main__':
|
|
run(host='0.0.0.0', port=5757)
|