From 3d203c153301d4dd9c3285e7dea86ee09eb3b0c5 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Tue, 20 Feb 2007 02:21:25 -0800 Subject: mid-progress, work on git-browser fan is dying, more work to do though! TODO: seperate style for git_browser, use "block.super" --- bn_django/git_browse/models.py | 25 +++++++++++ bn_django/git_browse/templates/git_browse/obj.html | 2 +- .../templates/git_browse/repository_info.html | 52 +++++++++++++++++++++- bn_django/git_browse/urls.py | 11 ++++- bn_django/git_browse/views.py | 33 ++++++++------ bn_django/settings.py | 1 + bn_django/templates/base.html | 2 +- bn_django/templates/frontpage.html | 3 +- static/style/default.css | 33 +++++++++++++- 9 files changed, 140 insertions(+), 22 deletions(-) diff --git a/bn_django/git_browse/models.py b/bn_django/git_browse/models.py index 765fe02..be097f8 100644 --- a/bn_django/git_browse/models.py +++ b/bn_django/git_browse/models.py @@ -5,6 +5,13 @@ try: GITBROWSE_BASE = settings.GITBROWSE_BASE except AttributeError: GITBROWSE_BASE='/home' +if GITBROWSE_BASE[-1] != '/': + GITBROWSE_BASE += '/' + +try: + GITCOMMAND = settings.GITCOMMAND +except AttributeError: + GITCOMMAND='git' try: ADMIN_URL = settings.ADMIN_URL @@ -34,6 +41,24 @@ class Repository(models.Model): def get_admin_url(self): return "%s/code/repository/%s/" % (ADMIN_URL, self.slug) + def scan(self): + import os + + GITPREFIX = 'cd ' + GITBROWSE_BASE + self.slug + '; ' + GITCOMMAND \ + + ' --git-dir=' + GITBROWSE_BASE + self.slug + '/.git ' + heads = dict() + for h in os.listdir(GITBROWSE_BASE + self.slug + '/.git/refs/heads/'): + f = open(GITBROWSE_BASE + self.slug + '/.git/refs/heads/' + h,'r') + heads[h] = f.readline() + f.close + tags = dict() + for t in os.listdir(GITBROWSE_BASE + self.slug + '/.git/refs/tags/'): + f = open(GITBROWSE_BASE + self.slug + '/.git/refs/tags/' + t,'r') + tags[t] = f.readline() + f.close + + return (GITPREFIX, heads, tags) + class Tree(models.Model): repo = models.ForeignKey(Repository) mode = models.CharField("file mode/permissions", blank=False,maxlength=4) diff --git a/bn_django/git_browse/templates/git_browse/obj.html b/bn_django/git_browse/templates/git_browse/obj.html index be0b556..0170eab 100644 --- a/bn_django/git_browse/templates/git_browse/obj.html +++ b/bn_django/git_browse/templates/git_browse/obj.html @@ -3,7 +3,7 @@ {% block gitbrowse %} {% if contents %}

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

{{ contents }}
{% else %} diff --git a/bn_django/git_browse/templates/git_browse/repository_info.html b/bn_django/git_browse/templates/git_browse/repository_info.html index 72f30b1..b3028a2 100644 --- a/bn_django/git_browse/templates/git_browse/repository_info.html +++ b/bn_django/git_browse/templates/git_browse/repository_info.html @@ -5,7 +5,55 @@ {% if shortlog %}

Shortlog (full log)

{{ shortlog }}
-

Filelist (browse)

-
{{ filelist }}
+

Heads (browse)

+{% if heads %} + +{% for h in heads.iteritems %} + + + + +{% endfor %} +
+ + {{ h.0 }} + + {{ h.1 }} + {% for t in tags.iteritems %} + {% ifequal h.1 t.1 %} + + [{{ t.0 }}] + {% endifequal %}{% endfor %} +
+{% else %}No heads!{% endif %} +

Tags (browse)

+{% if tags %} + +{% for t in tags.iteritems %} + + + + + {% endfor %} +{% endfor %} +
+ + {{ t.0 }} + + {{ t.1 }} + {% for t in tags.iteritems %} + {% ifequal h.1 t.1 %} + + [{{ t.0 }}] + {% endifequal %}
+{% else %}No tags!{% endif %} +

Filelist (browse tree)

+{% if filelist %}
{{ filelist }}
+{% else %}No files!{% endif %} {% endif %} {% endblock %} diff --git a/bn_django/git_browse/urls.py b/bn_django/git_browse/urls.py index 909bfcd..77fabd3 100644 --- a/bn_django/git_browse/urls.py +++ b/bn_django/git_browse/urls.py @@ -32,10 +32,17 @@ urlpatterns = patterns('django.views.generic.list_detail', urlpatterns += patterns('bn_django.git_browse.views', (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]{40})/$', 'view_obj',), + (r'^(?P[\w\-\_]*)/obj/(?P[0-9a-z]{40})/log/$', 'view_log',), + (r'^(?P[\w\-\_]*)/commit/(?P[0-9a-z]{40})/$', 'view_commit',), + (r'^(?P[\w\-\_]*)/commit/$', 'view_commit',), + (r'^(?P[\w\-\_]*)/tag/(?P[0-9a-z]{40})/$', 'view_tag',), + (r'^(?P[\w\-\_]*)/blob/(?P[0-9a-z]{40})/$', 'view_blob',), + (r'^(?P[\w\-\_]*)/blob/(?P[0-9a-z]{40})/raw/$', 'view_blob',), + (r'^(?P[\w\-\_]*)/tree/$', 'view_tree',), (r'^(?P[\w\-\_]*)/tree/(?P[0-9a-z]{40})/$', 'view_tree',), + (r'^(?P[\w\-\_]*)/tree/(?P[0-9a-z]{40})/gz/$', 'view_tree',), + (r'^(?P[\w\-\_]*)/tree/(?P[0-9a-z]{40})/tar/$', 'view_tree',), ) diff --git a/bn_django/git_browse/views.py b/bn_django/git_browse/views.py index c8a7a40..d8e01d7 100644 --- a/bn_django/git_browse/views.py +++ b/bn_django/git_browse/views.py @@ -23,26 +23,29 @@ except AttributeError: def repo_info(request, repo,branch=None): therepo = get_object_or_404(Repository, slug=repo) + (GITPREFIX, heads, tags) = therepo.scan() - GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git ' - - shortlog = commands.getoutput(GITPREFIX + ' log | ' + GITCOMMAND + '-shortlog') + shortlog = commands.getoutput(GITPREFIX + ' log | ' + GITCOMMAND \ + + '-shortlog') + branches = commands.getoutput(GITPREFIX + ' branch') filelist = commands.getoutput(GITPREFIX + ' ls-files') - - return render_to_response('git_browse/repository_info.html', - dict(object=therepo, - filelist=filelist, + return render_to_response('git_browse/repository_info.html', \ + dict(object=therepo, \ + filelist=filelist, \ + tags=tags, \ + heads=heads, \ shortlog=shortlog,)) def view_tree(request, repo, hash=None,branch=None): therepo = get_object_or_404(Repository, slug=repo) + (GITPREFIX, heads, tags) = therepo.scan() - GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git ' - if(hash == None): - head_ref = commands.getoutput('cd ' + GITBROWSE_BASE + therepo.slug +'/.git; cat HEAD') + head_ref = commands.getoutput('cd ' + GITBROWSE_BASE \ + + therepo.slug +'/.git; cat HEAD') head_ref = head_ref.split()[1] - hash = commands.getoutput('cd ' + GITBROWSE_BASE + therepo.slug +'/.git; cat ' + head_ref) + hash = commands.getoutput('cd ' + GITBROWSE_BASE + therepo.slug \ + +'/.git; cat ' + head_ref) tree_ls = commands.getoutput(GITPREFIX + ' ls-tree ' + hash) tree_objs = list() @@ -65,8 +68,10 @@ def view_tree(request, repo, hash=None,branch=None): def view_log(request, repo, tree_hash=None, branch=None): therepo = get_object_or_404(Repository, slug=repo) + (GITPREFIX, heads, tags) = therepo.scan() - GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git ' + 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 ') @@ -94,8 +99,8 @@ def view_log(request, repo, tree_hash=None, branch=None): def view_obj(request, repo, hash, branch=None): therepo = get_object_or_404(Repository, slug=repo) + (GITPREFIX, heads, tags) = therepo.scan() - 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); @@ -109,5 +114,5 @@ def view_obj(request, repo, hash, branch=None): dict(object=therepo, hash=hash, type=obj_type, - size=float(obj_size)/1024.0, + size=float(obj_size), contents=obj_contents)) diff --git a/bn_django/settings.py b/bn_django/settings.py index 9c26c1a..4e6c1b0 100644 --- a/bn_django/settings.py +++ b/bn_django/settings.py @@ -60,6 +60,7 @@ MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', + 'django.contrib.csrf.middleware.CsrfMiddleware', 'django.middleware.doc.XViewMiddleware', ) diff --git a/bn_django/templates/base.html b/bn_django/templates/base.html index 9416150..9375027 100644 --- a/bn_django/templates/base.html +++ b/bn_django/templates/base.html @@ -4,7 +4,7 @@ - + bryannewbold.com diff --git a/bn_django/templates/frontpage.html b/bn_django/templates/frontpage.html index 9dacccd..057d0c8 100644 --- a/bn_django/templates/frontpage.html +++ b/bn_django/templates/frontpage.html @@ -27,7 +27,8 @@ For 2007 i'm taking a year break from MIT... --> as of February i'm living in Seattle working at Azalea Software doing tech work. Starting in mid-May i'll be working at the Moss Landing Marine Labs in California, followed in October by field work in Antartica. I will be back at MIT for the spring 2008 semester. -
+
+
diff --git a/static/style/default.css b/static/style/default.css index 585b54d..27915a9 100644 --- a/static/style/default.css +++ b/static/style/default.css @@ -8,6 +8,9 @@ body { background-color: #E3E3E3; } a { text-decoration: none; } +a.subtle { + color: black; + text-decoration: none; } h1 { font-size: 16pt; font-weight: bold; @@ -34,7 +37,7 @@ hr { border-right: 55px solid #FFFFFF; } dt { font-weight: bold; } -pre { +pre.large { font-family: courier; margin: 10px; padding: 6px; @@ -182,6 +185,34 @@ pre { width: 160px; height: 180px; } +table.gitbrowser { + width: 100%; + border-spacing: 0px; +} +table.gitbrowser tr { + width: 100%; + margin-bottom: 2px; +} +table.gitbrowser td { + margin: 0px; + border: 1px solid black; + margin: 0px; +} +td.head { + font-weight: bold; + width: 130px; + overflow: hidden; +} + +td.hash { + width: 100px; + overflow: hidden; + text-align: right; +} +span.hash { + font-family: courier; +} + #top_bar { height: 22px; background-color: #993333; -- cgit v1.2.3