From 0c7c01d4ff1635cb7f04bed3d099b30b967f44bd Mon Sep 17 00:00:00 2001 From: bnewbold Date: Sun, 18 Feb 2007 13:53:30 -0800 Subject: renamed a few templates, further work on git_browse --- bn_django/git_browse/models.py | 46 +++++++++++ bn_django/git_browse/settings.py | 7 ++ .../git_browse/templates/git_browse/base.html | 31 +++++++ .../git_browse/templates/git_browse/full_log.html | 14 ++++ bn_django/git_browse/templates/git_browse/obj.html | 12 +++ .../templates/git_browse/repository_info.html | 8 ++ .../git_browse/repository_raw_output.html | 23 +----- .../git_browse/templates/git_browse/tree.html | 10 +++ bn_django/git_browse/urls.py | 9 ++- bn_django/git_browse/views.py | 94 ++++++++++++++++++++-- bn_django/templates/base.html | 2 +- bn_django/templates/frontpage.html | 1 - static/style/default.css | 7 ++ 13 files changed, 230 insertions(+), 34 deletions(-) create mode 100644 bn_django/git_browse/settings.py create mode 100644 bn_django/git_browse/templates/git_browse/full_log.html create mode 100644 bn_django/git_browse/templates/git_browse/obj.html create mode 100644 bn_django/git_browse/templates/git_browse/repository_info.html create mode 100644 bn_django/git_browse/templates/git_browse/tree.html diff --git a/bn_django/git_browse/models.py b/bn_django/git_browse/models.py index 93a22b3..765fe02 100644 --- a/bn_django/git_browse/models.py +++ b/bn_django/git_browse/models.py @@ -33,3 +33,49 @@ class Repository(models.Model): return "/code/%s/" % self.slug def get_admin_url(self): return "%s/code/repository/%s/" % (ADMIN_URL, self.slug) + +class Tree(models.Model): + repo = models.ForeignKey(Repository) + mode = models.CharField("file mode/permissions", blank=False,maxlength=4) + path = models.CharField("relative path from repo base", maxlength=512) + id = models.CharField("hash", maxlength=40,blank=False,primary_key=True) + name = models.CharField("name of dir", maxlength=128,blank=False) + type = 'tree' + + class Admin: + ordering = ['repo','path'] + + def __str__(self): + return self.name + def get_absolute_url(self): + return "/code/%s/%s" % (self.repo.slug, self.hash) + def get_admin_url(self): + return "%s/code/tree/%s/" % (ADMIN_URL, self.id) + +def tree_from_str(s): + s = s.split(); + if len(s) != 4: return + return Tree(mode=s[0],id=s[2],name=s[3]) + +class Blob(models.Model): + repo = models.ForeignKey(Repository) + mode = models.CharField("file mode/permissions", blank=False,maxlength=4) + path = models.CharField("relative path from repo base", maxlength=512) + id = models.CharField("hash", maxlength=40,blank=False,primary_key=True) + name = models.CharField("name of dir", maxlength=128,blank=False) + type='blob' + + class Admin: + ordering = ['repo','path'] + + def __str__(self): + return self.name + def get_absolute_url(self): + return "/code/%s/%s" % (self.repo.slug, self.hash) + def get_admin_url(self): + return "%s/code/tree/%s/" % (ADMIN_URL, self.id) + +def blob_from_str(s): + s = s.split(); + if len(s) != 4: return + return Blob(mode=s[0],id=s[2],name=s[3]) diff --git a/bn_django/git_browse/settings.py b/bn_django/git_browse/settings.py new file mode 100644 index 0000000..a18018b --- /dev/null +++ b/bn_django/git_browse/settings.py @@ -0,0 +1,7 @@ + +# full path to directory holding all the git repositories (or sys links to +# the repositories) +GITBROWSE_BASE = '/home/bnewbold/bn-project/' + +# fill path to the git command +GITCOMMAND = '/usr/local/bin/git' diff --git a/bn_django/git_browse/templates/git_browse/base.html b/bn_django/git_browse/templates/git_browse/base.html index 94d9808..0edb5a7 100644 --- a/bn_django/git_browse/templates/git_browse/base.html +++ b/bn_django/git_browse/templates/git_browse/base.html @@ -1 +1,32 @@ {% extends "base.html" %} + +{% block path %} + code » +{% if object %} + {{ object.name }} +{% endif %} +{% endblock %} + +{% block title %} +{% if object %} +{{ object.name }} +{% endif %} +{% endblock %} + +{% block content %} +{% if object %} + {% block gitbrowse %} + {% endblock %} +
+ + browse tree - full log + +
+ {% if raw %} +
{{raw}}
+ {% endif %} +{% else %} +

No such repository!

+{% endif %} + +{% endblock %} diff --git a/bn_django/git_browse/templates/git_browse/full_log.html b/bn_django/git_browse/templates/git_browse/full_log.html new file mode 100644 index 0000000..a467ae8 --- /dev/null +++ b/bn_django/git_browse/templates/git_browse/full_log.html @@ -0,0 +1,14 @@ +{% extends "git_browse/base.html" %} + +{% block gitbrowse %} +{% if log_objs %} +

Full Log


+ {% for item in log_objs %} +
+ Hash: {{ item.hash }} +
Author: {{ item.author }} +
Date: {{ item.date }} +
Comment:
{{ item.comment }}
+ {% endfor %} +{% endif %} +{% endblock %} diff --git a/bn_django/git_browse/templates/git_browse/obj.html b/bn_django/git_browse/templates/git_browse/obj.html new file mode 100644 index 0000000..be0b556 --- /dev/null +++ b/bn_django/git_browse/templates/git_browse/obj.html @@ -0,0 +1,12 @@ +{% extends "git_browse/base.html" %} + +{% block gitbrowse %} + {% if contents %} +

Object sha1 hash: {{ hash }}
+ Size: {{ size }} kB
+ Type: "{{ type }}"

+
{{ contents }}
+ {% else %} +

No such object: {{ hash }}

+ {% endif %} +{% endblock %} diff --git a/bn_django/git_browse/templates/git_browse/repository_info.html b/bn_django/git_browse/templates/git_browse/repository_info.html new file mode 100644 index 0000000..bec150c --- /dev/null +++ b/bn_django/git_browse/templates/git_browse/repository_info.html @@ -0,0 +1,8 @@ +{% extends "git_browse/base.html" %} + +{% block gitbrowse %} +{% if shortlog %} +

Shortlog

+
{{ shortlog }}
+{% endif %} +{% endblock %} diff --git a/bn_django/git_browse/templates/git_browse/repository_raw_output.html b/bn_django/git_browse/templates/git_browse/repository_raw_output.html index 3ce6894..ee1c8e0 100644 --- a/bn_django/git_browse/templates/git_browse/repository_raw_output.html +++ b/bn_django/git_browse/templates/git_browse/repository_raw_output.html @@ -1,29 +1,8 @@ {% extends "git_browse/base.html" %} -{% block path %} - code » -{% if object %} - {{ object.name }} -{% endif %} -{% endblock %} - -{% block title %} -{% if object %} -Repository: {{ object.name }} -{% endif %} -{% endblock %} - {% block content %} -{% if object %} {% if raw_content %}
-
-
-{{ raw_content }}
-    
+
 {{ raw_content }} 
{% endif %} -{% else %} -

No such repository!

-{% endif %} - {% endblock %} diff --git a/bn_django/git_browse/templates/git_browse/tree.html b/bn_django/git_browse/templates/git_browse/tree.html new file mode 100644 index 0000000..22162da --- /dev/null +++ b/bn_django/git_browse/templates/git_browse/tree.html @@ -0,0 +1,10 @@ +{% extends "git_browse/base.html" %} + +{% block gitbrowse %} + {% if all_objs %} +

Directory listing:

+ {% for obj in all_objs %} +[{{obj.type}}] {{obj.name}}
+ {% endfor %} + {% endif %} +{% endblock %} diff --git a/bn_django/git_browse/urls.py b/bn_django/git_browse/urls.py index 3d26e4f..91e9baa 100644 --- a/bn_django/git_browse/urls.py +++ b/bn_django/git_browse/urls.py @@ -31,7 +31,10 @@ urlpatterns = patterns('django.views.generic.list_detail', ) urlpatterns += patterns('bn_django.git_browse.views', - (r'^(?P[\w\-\_]*)/$', 'repo_view',), - (r'^(?P[\w\-\_]*)/tree/(?P.?)$', 'view_tree',), - (r'^(?P[\w\-\_]*)/obj/(?P.?)$', 'view_obj',), + (r'^(?P[\w\-\_]*)/$', 'repo_info',), + (r'^(?P[\w\-\_]*)/tree/$', 'view_tree',), + (r'^(?P[\w\-\_]*)/branches/$', 'view_branches',), + (r'^(?P[\w\-\_]*)/history/$', 'view_history',), + (r'^(?P[\w\-\_]*)/log/$', 'view_log',), + (r'^(?P[\w\-\_]*)/obj/(?P[0-9a-z]*)/$', 'view_obj',), ) diff --git a/bn_django/git_browse/views.py b/bn_django/git_browse/views.py index c0966b0..9e3ba90 100644 --- a/bn_django/git_browse/views.py +++ b/bn_django/git_browse/views.py @@ -1,4 +1,4 @@ -from django.conf import settings +import settings from django import forms, http, template from django.contrib.auth.decorators import login_required from django.shortcuts import get_object_or_404, render_to_response @@ -13,16 +13,96 @@ try: except AttributeError: GITBROWSE_BASE='/home/' +try: + GITCOMMAND = settings.GITCOMMAND +except AttributeError: + GITCOMMAND='git' + # Create your views here. -def repo_view(request, repo): +def repo_info(request, repo,branch=None): + therepo = get_object_or_404(Repository, slug=repo) + + GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git ' + + shortlog = commands.getoutput(GITPREFIX + ' log | ' + GITCOMMAND + '-shortlog') + + return render_to_response('git_browse/repository_info.html', + dict(object=therepo, + shortlog=shortlog,)) + +def view_tree(request, repo, tree_hash=None,branch=None): + therepo = get_object_or_404(Repository, slug=repo) + + GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git ' + + head_ref = commands.getoutput('cd ' + GITBROWSE_BASE + therepo.slug +'/.git; cat HEAD') + head_ref = head_ref.split()[1] + head = commands.getoutput('cd ' + GITBROWSE_BASE + therepo.slug +'/.git; cat ' + head_ref) + tree_ls = commands.getoutput(GITPREFIX + ' ls-tree ' + head) + tree_objs = list() + blob_objs = list() + for line in tree_ls.splitlines(): + l = line.split() + if len(l) < 4: + continue + if l[1] == 'tree': + tree_objs.append(tree_from_str(line)) + if l[1] == 'blob': + blob_objs.append(blob_from_str(line)) + + return render_to_response('git_browse/tree.html', + dict(object=therepo, + blob_objs=blob_objs, + tree_objs=tree_objs, + all_objs=tree_objs+blob_objs,)) + +def view_log(request, repo, tree_hash=None, branch=None): + therepo = get_object_or_404(Repository, slug=repo) + + GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git ' + + logtxt = commands.getoutput(GITPREFIX + ' log | cat') + log_items = logtxt.split('\ncommit ') + if (log_items[0] == ''): + log_items.pop(0) + if (log_items[0].startswith('commit ')): + log_items[0] = log_items[0][7:] + log_objs = list() + for li in log_items: + logobj = dict() + lines = li.splitlines() + if len(lines) < 3: continue + logobj['hash'] = lines[0] + logobj['author'] = lines[1][8:] + logobj['date'] = lines[2][8:] + logobj['comment'] = '' + for l in lines[4:]: + if l.startswith(' '): + logobj['comment'] += l[4:] + '\n' + log_objs.append(logobj) + + return render_to_response('git_browse/full_log.html', + dict(object=therepo, + log_objs=log_objs,)) + +def view_obj(request, repo, hash, branch=None): therepo = get_object_or_404(Repository, slug=repo) - out_content = 'Repo path: ' + therepo.path + '\n' - out_content += 'Repo slug: ' + therepo.slug + '\n\n\n\n\n' - out_content += commands.getoutput('cd '+GITBROWSE_BASE+therepo.slug+'; /usr/local/bin/git --git-dir='+GITBROWSE_BASE+therepo.slug+'/.git ls-files') + GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git ' + obj_type = commands.getoutput(GITPREFIX + ' cat-file -t ' + hash) + #if(obj_type == 'tree'): + # redirect_to('../tree/' + hash); + #if(obj_type == 'blob'): + # redirect_to('../blob/' + hash); - return render_to_response('git_browse/repository_raw_output.html', - dict(object=therepo,raw_content=out_content)) + obj_contents = commands.getoutput(GITPREFIX + ' cat-file -p ' + hash) + obj_size = commands.getoutput(GITPREFIX + ' cat-file -s ' + hash) + return render_to_response('git_browse/obj.html', + dict(object=therepo, + hash=hash, + type=obj_type, + size=float(obj_size)/1024.0, + contents=obj_contents)) diff --git a/bn_django/templates/base.html b/bn_django/templates/base.html index 84f7ffb..cee3641 100644 --- a/bn_django/templates/base.html +++ b/bn_django/templates/base.html @@ -20,7 +20,7 @@

- +
diff --git a/bn_django/templates/frontpage.html b/bn_django/templates/frontpage.html index ac9323c..d73070e 100644 --- a/bn_django/templates/frontpage.html +++ b/bn_django/templates/frontpage.html @@ -7,7 +7,6 @@ {% block right_stuff %} Other sites:
  - athena locker
-   - facebook?
  - git repository {% endblock %} diff --git a/static/style/default.css b/static/style/default.css index 7c9402e..5edddc7 100644 --- a/static/style/default.css +++ b/static/style/default.css @@ -34,6 +34,13 @@ hr { border-right: 55px solid #FFFFFF; } dt { font-weight: bold; } +pre { + font-family: courier; + margin: 10px; + padding: 6px; + border: 1px solid black; + background-color: #F2D1D1; + overflow: auto; } .search_box { border: 1px solid black; -- cgit v1.2.3