summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@manus.(none)>2007-02-08 00:40:46 -0800
committerbnewbold <bnewbold@manus.(none)>2007-02-08 00:40:46 -0800
commit9077a48cf9aeb06ddd751cfa7497fd636ed489a6 (patch)
treed2e946818d743c9c5b72883d60a208b07c9f7710
parentb88372f0327976c31e6b508b26729bab60743f82 (diff)
downloadbnewnet-9077a48cf9aeb06ddd751cfa7497fd636ed489a6.tar.gz
bnewnet-9077a48cf9aeb06ddd751cfa7497fd636ed489a6.zip
first work on git_browser app
for now just returns raw text from shell commands also tries to track repositories... but UI for selecting FilePathFields sucks so have to chose slugs manually for now... i think django support for this will come soon so i'm not bothering.
-rw-r--r--.gitignore1
-rw-r--r--bn_django/git_browse/__init__.py0
-rw-r--r--bn_django/git_browse/models.py35
-rw-r--r--bn_django/git_browse/templates/git_browse/base.html1
-rw-r--r--bn_django/git_browse/templates/git_browse/repository_list.html44
-rw-r--r--bn_django/git_browse/templates/git_browse/repository_raw_output.html29
-rw-r--r--bn_django/git_browse/urls.py37
-rw-r--r--bn_django/git_browse/views.py28
-rw-r--r--bn_django/settings.py3
9 files changed, 178 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index d4d8848..15243e5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ code
bn_django/bn_django.db
*.pyc
*.pyo
+*.swp
diff --git a/bn_django/git_browse/__init__.py b/bn_django/git_browse/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bn_django/git_browse/__init__.py
diff --git a/bn_django/git_browse/models.py b/bn_django/git_browse/models.py
new file mode 100644
index 0000000..93a22b3
--- /dev/null
+++ b/bn_django/git_browse/models.py
@@ -0,0 +1,35 @@
+from django.db import models
+from django.conf import settings
+
+try:
+ GITBROWSE_BASE = settings.GITBROWSE_BASE
+except AttributeError:
+ GITBROWSE_BASE='/home'
+
+try:
+ ADMIN_URL = settings.ADMIN_URL
+except AttributeError:
+ ADMIN_URL='/admin'
+if ADMIN_URL[-1] == '/':
+ ADMIN_URL=ADMIN_URL[:-1]
+
+
+# Create your models here.
+class Repository(models.Model):
+ path = models.FilePathField("relative path to repository", path=GITBROWSE_BASE,recursive=True,match="^.*\.git$",unique=True,blank=False)
+ #path = models.FilePathField("relative path to repository", path='/home/bnewbold/code/',recursive=True,match=".*\.git$",unique=True,blank=False)
+ name = models.CharField(_("name"), maxlength=80)
+ slug = models.SlugField(prepopulate_from=("path",),unique=True)
+ git_version = models.CharField(_("git version"), maxlength=100,default="git version 1.4.4", blank=True, help_text="Output of \'git --version\'")
+
+ description = models.TextField("description of repo",blank=True)
+
+ class Admin:
+ ordering = ['slug']
+
+ def __str__(self):
+ return self.name
+ def get_absolute_url(self):
+ return "/code/%s/" % self.slug
+ def get_admin_url(self):
+ return "%s/code/repository/%s/" % (ADMIN_URL, self.slug)
diff --git a/bn_django/git_browse/templates/git_browse/base.html b/bn_django/git_browse/templates/git_browse/base.html
new file mode 100644
index 0000000..94d9808
--- /dev/null
+++ b/bn_django/git_browse/templates/git_browse/base.html
@@ -0,0 +1 @@
+{% extends "base.html" %}
diff --git a/bn_django/git_browse/templates/git_browse/repository_list.html b/bn_django/git_browse/templates/git_browse/repository_list.html
new file mode 100644
index 0000000..a089fec
--- /dev/null
+++ b/bn_django/git_browse/templates/git_browse/repository_list.html
@@ -0,0 +1,44 @@
+{% extends "git_browse/base.html" %}
+{# {% load markup %} #}
+
+{% block path %}code{% endblock %}
+{% block title %}Code Repositories{% endblock %}
+
+{% block content %}
+{% if object_list %}
+{% for item in object_list %}
+ <div class="righty"><br />
+ <a href="{{ item.slug }}/tree/">tree</a> -
+ <a href="{{ item.slug }}/changelog/">changelog</a>
+ </div>
+ <h3><a href="{{ item.slug }}/">{{ item.name }}</a> (aka {{ item.slug }})</h3>
+ {{ item.description }}
+{% endfor %}
+{% else %}
+<p>No repositories have been set up yet.</p>
+{% endif %}
+
+
+{% if is_paginated %}
+{% if has_previous %}
+<a href="./?page={{ previous }}">&laquo; previous</a> |
+{% endif %}
+{% if has_next %}
+<a href="./?page={{ next }}">next &raquo;</a>
+{% endif %}
+{% endif %}
+
+<!--
+{% if not user.is_anonymous %}
+<p>
+ <a href="{{admin_url}}/photos/gallery/add/">Create a new gallery.</a>
+</p>
+{% else %}
+<p>
+ <a href="/accounts/login/?next={{ request.path }}">
+ Login</a> to create a new gallery.
+</p>
+{% 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
new file mode 100644
index 0000000..3ce6894
--- /dev/null
+++ b/bn_django/git_browse/templates/git_browse/repository_raw_output.html
@@ -0,0 +1,29 @@
+{% extends "git_browse/base.html" %}
+
+{% block path %}
+ <a href="../">code</a> &raquo;
+{% if object %}
+ <a href="/code/{{ object.slug }}/">{{ object.name }}</a>
+{% endif %}
+{% endblock %}
+
+{% block title %}
+{% if object %}
+Repository: {{ object.name }}
+{% endif %}
+{% endblock %}
+
+{% block content %}
+{% if object %}
+ {% if raw_content %}
+ <br />
+ <pre>
+
+{{ raw_content }}
+ </pre>
+ {% endif %}
+{% else %}
+<p>No such repository!</p>
+{% endif %}
+
+{% endblock %}
diff --git a/bn_django/git_browse/urls.py b/bn_django/git_browse/urls.py
new file mode 100644
index 0000000..3d26e4f
--- /dev/null
+++ b/bn_django/git_browse/urls.py
@@ -0,0 +1,37 @@
+from django.conf.urls.defaults import *
+from django.conf import settings
+
+from models import *
+
+try:
+ GITBROWSE_BASE = settings.GITBROWSE_BASE.strip('/')
+except AttributeError:
+ GITBROWSE_BASE='/home'
+
+try:
+ ADMIN_URL = settings.ADMIN_URL
+except AttributeError:
+ ADMIN_URL='/admin'
+if ADMIN_URL[-1] == '/':
+ ADMIN_URL=ADMIN_URL[:-1]
+
+#from models import Gallery, Photo, ADMIN_URL, STOCKPHOTO_URL
+
+info_dict = { 'extra_context': { 'admin_url': ADMIN_URL,
+ } }
+
+urlpatterns = patterns('django.views.generic.list_detail',
+ (r'^$', 'object_list',
+ dict(info_dict, queryset=Repository.objects.all(),
+ allow_empty= True)),
+# (r'^(?P<object_id>\d+)/$', 'object_detail',
+# dict(info_dict, queryset=Gallery.objects.all())),
+# (r'^detail/(?P<object_id>\d+)/$', 'object_detail',
+# dict(info_dict, queryset=Photo.objects.all())),
+)
+
+urlpatterns += patterns('bn_django.git_browse.views',
+ (r'^(?P<repo>[\w\-\_]*)/$', 'repo_view',),
+ (r'^(?P<repo>[\w\-\_]*)/tree/(?P<path>.?)$', 'view_tree',),
+ (r'^(?P<repo>[\w\-\_]*)/obj/(?P<obj_hash>.?)$', 'view_obj',),
+)
diff --git a/bn_django/git_browse/views.py b/bn_django/git_browse/views.py
new file mode 100644
index 0000000..c0966b0
--- /dev/null
+++ b/bn_django/git_browse/views.py
@@ -0,0 +1,28 @@
+from django.conf 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
+from django.http import HttpResponse
+
+import os, commands
+
+from models import *
+
+try:
+ GITBROWSE_BASE = settings.GITBROWSE_BASE+'/'
+except AttributeError:
+ GITBROWSE_BASE='/home/'
+
+
+# Create your views here.
+
+def repo_view(request, repo):
+ 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')
+
+ return render_to_response('git_browse/repository_raw_output.html',
+ dict(object=therepo,raw_content=out_content))
+
diff --git a/bn_django/settings.py b/bn_django/settings.py
index e8ee891..9c26c1a 100644
--- a/bn_django/settings.py
+++ b/bn_django/settings.py
@@ -81,4 +81,7 @@ INSTALLED_APPS = (
'django.contrib.flatpages',
'bn_django.photos',
'bn_django.git_wiki',
+ 'bn_django.git_browse',
)
+
+GITBROWSE_BASE = '/home/bnewbold/bn-project/code'