diff --git a/klaus/__init__.py b/klaus/__init__.py index 6a07e407..755ced29 100644 --- a/klaus/__init__.py +++ b/klaus/__init__.py @@ -1,3 +1,4 @@ +import os import jinja2 import flask import httpauth @@ -5,7 +6,6 @@ from klaus import views, utils from klaus.repo import FancyRepo - KLAUS_VERSION = utils.guess_git_revision() or '1.2.2' @@ -17,7 +17,12 @@ class Klaus(flask.Flask): def __init__(self, repo_paths, site_name, use_smarthttp, ctags_policy='none'): """(See `make_app` for parameter descriptions.)""" - repo_objs = [FancyRepo(path) for path in repo_paths] + + user_dirs = repo_paths + repo_objs = [] + for user_dir in user_dirs: + user_repo_paths = [os.path.join(user_dir, x) for x in os.listdir(user_dir)] + repo_objs += [FancyRepo(path) for path in user_repo_paths] self.repos = dict((repo.name, repo) for repo in repo_objs) self.site_name = site_name self.use_smarthttp = use_smarthttp @@ -48,24 +53,24 @@ def create_jinja_environment(self): def setup_routes(self): for endpoint, rule in [ - ('repo_list', '/'), - ('robots_txt', '/robots.txt/'), - ('blob', '//blob/'), - ('blob', '//blob//'), - ('blame', '//blame/'), - ('blame', '//blame//'), - ('raw', '//raw//'), - ('raw', '//raw//'), - ('submodule', '//submodule//'), - ('submodule', '//submodule//'), - ('commit', '//commit//'), - ('patch', '//commit/.diff'), - ('patch', '//commit/.patch'), - ('index', '//'), - ('index', '//'), - ('history', '//tree//'), - ('history', '//tree//'), - ('download', '//tarball//'), + ('repo_list', '/'), + ('robots_txt', '/robots.txt/'), + ('blob', '//blob/'), + ('blob', '//blob//'), + ('blame', '//blame/'), + ('blame', '//blame//'), + ('raw', '//raw//'), + ('raw', '//raw//'), + ('submodule', '//submodule//'), + ('submodule', '//submodule//'), + ('commit', '//commit//'), + ('patch', '//commit/.diff'), + ('patch', '//commit/.patch'), + ('index', '//'), + ('index', '//'), + ('history', '//tree//'), + ('history', '//tree//'), + ('download', '//tarball//'), ]: self.add_url_rule(rule, view_func=getattr(views, endpoint)) @@ -80,7 +85,6 @@ def should_use_ctags(self, git_repo, git_commit): raise ValueError("Unknown ctags policy %r" % self.ctags_policy) - def make_app(repo_paths, site_name, use_smarthttp=False, htdigest_file=None, require_browser_auth=False, disable_push=False, unauthenticated_push=False, ctags_policy='none'): @@ -128,7 +132,7 @@ def make_app(repo_paths, site_name, use_smarthttp=False, htdigest_file=None, if use_smarthttp: # `path -> Repo` mapping for Dulwich's web support dulwich_backend = dulwich.server.DictBackend( - dict(('/'+name, repo) for name, repo in app.repos.items()) + dict(('/' + name, repo) for name, repo in app.repos.items()) ) # Dulwich takes care of all Git related requests/URLs # and passes through everything else to klaus diff --git a/klaus/markup.py b/klaus/markup.py index f49c6023..36f43350 100644 --- a/klaus/markup.py +++ b/klaus/markup.py @@ -51,5 +51,20 @@ def render_rest(content): LANGUAGES.append((['.rst', '.rest'], render_rest)) -for loader in [_load_markdown, _load_restructured_text]: +def _load_notebook(): + try: + import nbformat + import nbconvert + except ImportError: + return + + def render_notebook(content): + nb = nbformat.reads(content, nbformat.NO_CONVERT) + (output, resources) = nbconvert.HTMLExporter(template_file='./klaus/templates/my_full.tpl').from_notebook_node(nb) + return output + + LANGUAGES.append((['.ipynb'], render_notebook)) + + +for loader in [_load_markdown, _load_restructured_text, _load_notebook]: loader() diff --git a/klaus/repo.py b/klaus/repo.py index fb5eb6e7..924fce71 100644 --- a/klaus/repo.py +++ b/klaus/repo.py @@ -24,7 +24,9 @@ def name(self): 2. /x/y/ -> /x/y 3. /x/y -> y """ - return self.path.replace(".git", "").rstrip(os.sep).split(os.sep)[-1] + path_arr = self.path.replace(".git", "").rstrip(os.sep).split(os.sep) + # join user_ID and repo name by '\', to distinguish repo belong to different user + return path_arr[-2] + '\\' + path_arr[-1] def get_last_updated_at(self): """Get datetime of last commit to this repository.""" diff --git a/klaus/templates/my_full.tpl b/klaus/templates/my_full.tpl new file mode 100644 index 00000000..1fcc9fae --- /dev/null +++ b/klaus/templates/my_full.tpl @@ -0,0 +1,98 @@ +{%- extends 'basic.tpl' -%} +{% from 'mathjax.tpl' import mathjax %} + + +{%- block header -%} + + + +{%- block html_head -%} + +{{resources['metadata']['name']}} + +{%- if "widgets" in nb.metadata -%} + +{%- endif-%} + + + + +{% for css in resources.inlining.css -%} + +{% endfor %} + + + + + + + +{{ mathjax() }} +{%- endblock html_head -%} + +{%- endblock header -%} + +{% block body %} + +
+
+{{ super() }} +
+
+ +{%- endblock body %} + +{% block footer %} +{{ super() }} + +{% endblock footer %} diff --git a/klaus/templates/skeleton.html b/klaus/templates/skeleton.html index 1768733c..47eac9ae 100644 --- a/klaus/templates/skeleton.html +++ b/klaus/templates/skeleton.html @@ -12,9 +12,9 @@
- - {{ SITE_NAME }} - +{# #} +{# {{ SITE_NAME }}#} +{# #} {% block breadcrumbs %}{% endblock %} {% block extra_header %}{% endblock %}
diff --git a/test_requirements.txt b/test_requirements.txt index da43373b..59c943bf 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,4 +1,9 @@ +klaus pytest requests +markdown +docutils +nbformat +nbconvert python-ctags3>=1.2.1 mock; python_version < '3'