From 1ad7cb33abfac55a9be2f1d889c369fd1b43df2f Mon Sep 17 00:00:00 2001 From: bnewbold Date: Mon, 25 Oct 2010 19:40:32 +0000 Subject: changes for adelie --- bn_django/git_browse/__init__.py | 0 bn_django/git_browse/models.py | 262 --------------------- bn_django/git_browse/settings.py.example | 2 - .../git_browse/templates/git_browse/base.html | 37 --- .../git_browse/templates/git_browse/blob.html | 18 -- .../git_browse/templates/git_browse/commit.html | 36 --- .../git_browse/templates/git_browse/full_log.html | 17 -- .../git_browse/templates/git_browse/heads_table | 23 -- bn_django/git_browse/templates/git_browse/obj.html | 16 -- .../templates/git_browse/repository_info.html | 14 -- .../templates/git_browse/repository_list.html | 50 ---- .../git_browse/repository_raw_output.html | 8 - .../git_browse/templates/git_browse/shortlog_table | 29 --- .../git_browse/templates/git_browse/tags_table | 23 -- .../git_browse/templates/git_browse/tree.html | 11 - .../git_browse/templates/git_browse/tree_table | 32 --- bn_django/git_browse/urls.py | 48 ---- bn_django/git_browse/views.py | 167 ------------- 18 files changed, 793 deletions(-) delete mode 100644 bn_django/git_browse/__init__.py delete mode 100644 bn_django/git_browse/models.py delete mode 100644 bn_django/git_browse/settings.py.example delete mode 100644 bn_django/git_browse/templates/git_browse/base.html delete mode 100644 bn_django/git_browse/templates/git_browse/blob.html delete mode 100644 bn_django/git_browse/templates/git_browse/commit.html delete mode 100644 bn_django/git_browse/templates/git_browse/full_log.html delete mode 100644 bn_django/git_browse/templates/git_browse/heads_table delete mode 100644 bn_django/git_browse/templates/git_browse/obj.html delete mode 100644 bn_django/git_browse/templates/git_browse/repository_info.html delete mode 100644 bn_django/git_browse/templates/git_browse/repository_list.html delete mode 100644 bn_django/git_browse/templates/git_browse/repository_raw_output.html delete mode 100644 bn_django/git_browse/templates/git_browse/shortlog_table delete mode 100644 bn_django/git_browse/templates/git_browse/tags_table delete mode 100644 bn_django/git_browse/templates/git_browse/tree.html delete mode 100644 bn_django/git_browse/templates/git_browse/tree_table delete mode 100644 bn_django/git_browse/urls.py delete mode 100644 bn_django/git_browse/views.py (limited to 'bn_django/git_browse') diff --git a/bn_django/git_browse/__init__.py b/bn_django/git_browse/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/bn_django/git_browse/models.py b/bn_django/git_browse/models.py deleted file mode 100644 index 5241638..0000000 --- a/bn_django/git_browse/models.py +++ /dev/null @@ -1,262 +0,0 @@ -from django.db import models -from django.conf import settings -from django.utils.translation import ugettext as _ - -try: - GITCOMMAND = settings.GITCOMMAND -except AttributeError: - GITCOMMAND='git' - -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.CharField("path to git dir", max_length=386, unique=True,\ - blank=False, default="/srv/git/") - name = models.CharField(_("name"), max_length=80, unique=True) - slug = models.SlugField("short description of repo", unique=True,\ - blank=False) - git_version = models.CharField(_("git version"), max_length=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: - list_display = ['name', 'slug', 'path'] - ordering = ['name'] - 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) - - def getGITPREFIX(self): - """returns the glued together combination of GITCOMMAND and - GITBROWSE_BASE needed to call git commands on this repository""" - return 'cd ' + str(self.path) + '; ' + str(GITCOMMAND) + ' --git-dir='\ - + str(self.path) - - def scan(self): - import os - GITPREFIX = self.getGITPREFIX() - heads = dict() - for h in os.listdir(self.path + '/refs/heads/'): - f = open(self.path + '/refs/heads/' + h,'r') - heads[h.strip()] = f.readline().strip() - f.close() - tags = dict() - for t in os.listdir(self.path + '/refs/tags/'): - f = open(self.path + '/refs/tags/' + t,'r') - tags[t.strip()] = f.readline().strip() - f.close() - return (GITPREFIX, heads, tags) - - def shortlog(self): - import commands - GITPREFIX = self.getGITPREFIX() - logtxt = commands.getoutput(GITPREFIX \ - + ' log --relative-date --max-count=6 | 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:] - shortlog = list() - for li in log_items: - logobj = dict() - lines = li.splitlines() - if len(lines) < 3: continue - logobj['hash'] = lines[0].strip() - logobj['shorthash'] = lines[0].strip()[:5] - logobj['author'] = lines[1][8:] - logobj['date'] = lines[2][8:] - if len(lines) > 4: - logobj['description'] = lines[4][4:] - else: - logobj['description'] = '(none)' - # here we truncate commit comments for shortlogs - logobj['shortdescription'] = logobj['description'][:128] - shortlog.append(logobj) - return shortlog - -class Tree(models.Model): - repo = models.ForeignKey(Repository) - mode = models.CharField("file mode/permissions", blank=False,max_length=4) - path = models.CharField("relative path from repo base", max_length=512) - id = models.CharField("hash", max_length=40,blank=False,primary_key=True) - name = models.CharField("name of dir", max_length=128,blank=False) - type = 'tree' - - class Admin: - list_display = ['path','name','repo', 'id'] - ordering = ['repo','path'] - list_filter = ['repo','path'] - - def __str__(self): - return self.name - def get_absolute_url(self): - return "/code/%s/tree/%s/" % (self.repo.slug, self.hash) - def get_admin_url(self): - return "%s/code/tree/%s/" % (ADMIN_URL, self.id) - - def update(self): - import commands - if (not self.id): return - - GITPREFIX = self.repo.getGITPREFIX() - - self.id = self.id.strip() - tree_ls = commands.getoutput(GITPREFIX + ' ls-tree --full-name ' \ - + self.id) - tree_objs = list() - blob_objs = list() - for line in tree_ls.splitlines(): - l = line.split() - if len(l) < 4: - continue - if l[1] == 'tree': - t = Tree(id=l[2]) - t.path = ' '.join(l[3:]) - if self.path and self.path != '/': - t.path = self.path + '/' + t.path - t.name = t.path - tree_objs.append(t) - if l[1] == 'blob': - b = Blob(id=l[2]) - b.path = ' '.join(l[3:]) - if self.path and self.path != '/': - b.path = self.path + '/' + b.path - b.name=b.path - blob_objs.append(b) - self.tree_objs = tree_objs - self.blob_objs = blob_objs - self.all_objs = tree_objs + blob_objs - -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,max_length=4) - path = models.CharField("relative path from repo base", max_length=512) - id = models.CharField("hash", max_length=40,blank=False,primary_key=True) - name = models.CharField("name of dir", max_length=128,blank=False) - size = models.IntegerField("filesize in byte", max_length=128,blank=False) - contents = models.TextField("ASCII contents of the file") - type='blob' - - class Admin: - list_filter = ['repo','path'] - list_display = ['name','path','id','size','repo'] - search_fields = ['contents'] - ordering = ['repo','path','name'] - def __str__(self): - return self.name - def get_absolute_url(self): - return "/code/%s/blob/%s/" % (self.repo.slug, self.hash) - def get_admin_url(self): - return "%s/code/blob/%s/" % (ADMIN_URL, self.id) - - def update(self): - import commands - if (not self.id) or (not self.repo): return - - GITPREFIX = self.repo.getGITPREFIX() - - self.id = self.id.strip() - self.contents = commands.getoutput(GITPREFIX + ' cat-file -p ' \ - + self.id) - self.size = commands.getoutput(GITPREFIX + ' cat-file -s ' + self.id) - return - -def blob_from_str(s): - s = s.split(); - if len(s) != 4: return - return Blob(mode=s[0],id=s[2],name=s[3]) - -class Commit(models.Model): - repo = models.ForeignKey(Repository) - id = models.CharField("hash", max_length=40,blank=False,primary_key=True) - rawdiff = models.TextField("ASCII contents of full commit diff") - commit_date = models.DateField("Date of commit to repository") - author_date = models.DateField("Date commit was writen/created") - author = models.CharField("Name of commit author", max_length=96) - author_email = models.CharField("Email address of commit author", \ - max_length=196) - committer = models.CharField("Name of committer", max_length=96) - committer_email = models.CharField("Email address of committer", \ - max_length=196) - comment = models.TextField("Notes on the commit") - parenthash = models.CharField("parent's hash", max_length=40) - #TODO: parent = models.ForeignKey() - treehash = models.CharField("tree object's hash", max_length=40) - tree = models.ForeignKey(Tree) - type='commit' - - class Admin: - list_filter = ['repo'] - list_display = ['id', 'commit_date', 'author', 'repo'] - ordering = ['repo','commit_date','author_date','author'] - def __str__(self): - return self.id - def get_absolute_url(self): - return "/code/%s/commit/%s/" % (self.repo.slug, self.hash) - def get_admin_url(self): - return "%s/code/commit/%s/" % (ADMIN_URL, self.id) - - def update(self): - import commands,time - if (not self.id) or (not self.repo): return - - GITPREFIX = self.repo.getGITPREFIX() - - self.id = self.id.strip() - raw = commands.getoutput(GITPREFIX + ' cat-file -p ' + self.id) - - raw = raw.splitlines() - if len(raw) < 3: return - self.treehash = raw[0].split()[-1].strip() - if not raw[1].startswith('parent'): - raw.insert(1, 'parent ') - self.parenthash = raw[1][6:].strip() - if raw[2].startswith('author'): - self.author = raw[2].split()[1] - self.author_date = time.ctime(int(raw[2].split()[-2])) - elif raw[3].startswith('author'): - self.author = raw[3].split()[1] - self.author_date = time.ctime(int(raw[3].split()[-2])) - elif raw[4].startswith('author'): - self.author = raw[4].split()[1] - self.author_date = time.ctime(int(raw[4].split()[-2])) - else: return - self.committer = raw[3].split()[1] - self.committer_date = time.ctime(int(raw[3].split()[-2])) - self.rawdiff = commands.getoutput(GITPREFIX + ' diff ' \ - + self.parenthash + ' ' + self.id + ' | cat') - if len(raw) > 4: - for l in raw[4:]: - self.comment += str(l) + '\n' - else: - self.comment = '(none)' - return - -from django.contrib import admin - -admin.site.register(Repository) -admin.site.register(Tree) -admin.site.register(Blob) -admin.site.register(Commit) - diff --git a/bn_django/git_browse/settings.py.example b/bn_django/git_browse/settings.py.example deleted file mode 100644 index 87b957d..0000000 --- a/bn_django/git_browse/settings.py.example +++ /dev/null @@ -1,2 +0,0 @@ -# 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 deleted file mode 100644 index 611d11d..0000000 --- a/bn_django/git_browse/templates/git_browse/base.html +++ /dev/null @@ -1,37 +0,0 @@ -{% extends "base.html" %} - -{% block stylesheets %} -{{ block.super }} - -{% endblock %} - -{% block path %} -{{ block.super }} -code -{% if object %} - » {{ object.name }} - [browse, - log] -{% endif %} -{% endblock %} - -{% block title %} -{% if object %} -{{ object.name }} -{% endif %} -{% endblock %} - -{% block content %} -{% if object %} - {% block gitbrowse %} - {% endblock %} -
- - browse tree - full log - -
-{% else %} -

No such repository!

-{% endif %} - -{% endblock %} diff --git a/bn_django/git_browse/templates/git_browse/blob.html b/bn_django/git_browse/templates/git_browse/blob.html deleted file mode 100644 index 853c034..0000000 --- a/bn_django/git_browse/templates/git_browse/blob.html +++ /dev/null @@ -1,18 +0,0 @@ -{% extends "git_browse/base.html" %} - -{% block gitbrowse %} {% if contents %} -

Blob sha1 hash

- {{ hash }}
-

Size

- {{ size|filesizeformat }}
-

Raw contents

- {% if pretty_contents %} -
{{ pretty_diff }}
- {% else %} - {% if contents %} -
{{ contents|escape|wordwrap:80 }}
- {% else %}No contents{% endif %} - {% endif %} -{% else %} -

No such object: {{ hash }}

-{% endif %} {% endblock %} diff --git a/bn_django/git_browse/templates/git_browse/commit.html b/bn_django/git_browse/templates/git_browse/commit.html deleted file mode 100644 index b586eb8..0000000 --- a/bn_django/git_browse/templates/git_browse/commit.html +++ /dev/null @@ -1,36 +0,0 @@ -{% extends "git_browse/base.html" %} -{% block stylesheets %}{{ block.super }} - -{% endblock %} - -{% block gitbrowse %} {% if commit %} -

Commit sha1 hash

- {{ commit.id }}
-

Parent sha1 hash

- {% if commit.parenthash %} - - {{ commit.parenthash }} - {% else %}No parent... root commit?{% endif %} -

Tree sha1 hash

- {% if commit.treehash %} - - {{ commit.treehash }} - {% else %}No tree hash?{% endif %} -

Author

- {{ commit.author }}
-

Author Date

- {{ commit.author_date }}
-

Committer

- {{ commit.committer }}
-

Committer Date

- {{ commit.committer_date }}
- {% if commit.pretty_diff %} -
{{ commit.pretty_diff }}
- {% else %} - {% if commit.rawdiff %} -
{{ commit.rawdiff|escape|wordwrap:80 }}
- {% else %}No diff{% endif %} - {% endif %} -{% else %} -

No such object: {{ hash }}

-{% 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 deleted file mode 100644 index 913a3c4..0000000 --- a/bn_django/git_browse/templates/git_browse/full_log.html +++ /dev/null @@ -1,17 +0,0 @@ -{% 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|escape|wordwrap:80 }}
- {% endfor %} -{% endif %} -{% endblock %} diff --git a/bn_django/git_browse/templates/git_browse/heads_table b/bn_django/git_browse/templates/git_browse/heads_table deleted file mode 100644 index 5840db0..0000000 --- a/bn_django/git_browse/templates/git_browse/heads_table +++ /dev/null @@ -1,23 +0,0 @@ -{% if heads %} - -{% for h in heads.iteritems %} - - - - -{% endfor %} -
- - {{ h.0 }} - {% if tags %}{% for t in tags.iteritems %} - {% ifequal h.1 t.1 %} - - [{{ t.0 }}] - {% endifequal %}{% endfor %}{% endif %} - - {{ h.1 }} -
-{% else %}No heads!{% endif %} - diff --git a/bn_django/git_browse/templates/git_browse/obj.html b/bn_django/git_browse/templates/git_browse/obj.html deleted file mode 100644 index 669091b..0000000 --- a/bn_django/git_browse/templates/git_browse/obj.html +++ /dev/null @@ -1,16 +0,0 @@ -{% extends "git_browse/base.html" %} - -{% block gitbrowse %} - {% if contents %} -

Object sha1 hash

- {{ hash }}
-

Size

- {{ size|filesizeformat }}
-

Type

- "{{ type }}" -

Raw Description

-
{{ 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 deleted file mode 100644 index f529c84..0000000 --- a/bn_django/git_browse/templates/git_browse/repository_info.html +++ /dev/null @@ -1,14 +0,0 @@ -{% extends "git_browse/base.html" %} - -{% block gitbrowse %} -{{ object.description }} -

Shortlog (full log) (last commit)

-{% include "git_browse/shortlog_table" %} -

Heads (browse)

-{% include "git_browse/heads_table" %} -

Tags (browse)

-{% include "git_browse/tags_table" %} -

Filelist (browse tree)

-{% if filelist %}
{{ filelist }}
-{% else %}No files!{% endif %} -{% endblock %} diff --git a/bn_django/git_browse/templates/git_browse/repository_list.html b/bn_django/git_browse/templates/git_browse/repository_list.html deleted file mode 100644 index e409c74..0000000 --- a/bn_django/git_browse/templates/git_browse/repository_list.html +++ /dev/null @@ -1,50 +0,0 @@ -{% extends "git_browse/base.html" %} -{# {% load markup %} #} - -{% block path %}code{% endblock %} -{% block title %}Code Repositories{% endblock %} - -{% block content %} -
-Until this is better developed I would recommend trying gitweb. -
-
-If you aren't familiar with git these repositories won't make much sense and will be frustrating! -
-{% if object_list %} -{% for item in object_list %} -

- browse - - changelog -
-

{{ item.name }} (aka {{ item.slug }})

- {{ item.description }} -{% endfor %} -{% else %} -

No repositories have been set up yet.

-{% endif %} - - -{% if is_paginated %} -{% if has_previous %} -« previous | -{% endif %} -{% if has_next %} -next » -{% endif %} -{% 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 deleted file mode 100644 index ee1c8e0..0000000 --- a/bn_django/git_browse/templates/git_browse/repository_raw_output.html +++ /dev/null @@ -1,8 +0,0 @@ -{% extends "git_browse/base.html" %} - -{% block content %} - {% if raw_content %} -
-
 {{ raw_content }} 
- {% endif %} -{% endblock %} diff --git a/bn_django/git_browse/templates/git_browse/shortlog_table b/bn_django/git_browse/templates/git_browse/shortlog_table deleted file mode 100644 index 8a223ec..0000000 --- a/bn_django/git_browse/templates/git_browse/shortlog_table +++ /dev/null @@ -1,29 +0,0 @@ -{% if shortlog %} - -{% for l in shortlog %} - - - - - -{% endfor %} -
- {{ l.date }} - {{ l.author }} - - {{ l.description|truncatewords:10 }} - {% if heads %}{% for h in heads.iteritems %} - {% ifequal h.1 l.hash %} - - [{{ h.0 }}] - {% endifequal %} - {% endfor %}{% endif %} - {% if tags %}{% for t in tags.iteritems %} - {% ifequal l.hash t.1 %} - - [{{ t.0 }}] - {% endifequal %}{% endfor %}{% endif %} - - - {{ l.shorthash }}...
-{% else %}No shortlog!{% endif %} diff --git a/bn_django/git_browse/templates/git_browse/tags_table b/bn_django/git_browse/templates/git_browse/tags_table deleted file mode 100644 index 7df504a..0000000 --- a/bn_django/git_browse/templates/git_browse/tags_table +++ /dev/null @@ -1,23 +0,0 @@ -{% if tags %} - -{% for t in tags.iteritems %} - - - - -{% endfor %} -
- - {{ t.0 }} - {% for h in heads.iteritems %} - {% ifequal h.1 t.1 %} - - [{{ h.0 }}] - {% endifequal %} - {% endfor %} - - {{ t.1 }}
-{% else %}No tags!{% endif %} diff --git a/bn_django/git_browse/templates/git_browse/tree.html b/bn_django/git_browse/templates/git_browse/tree.html deleted file mode 100644 index b177af8..0000000 --- a/bn_django/git_browse/templates/git_browse/tree.html +++ /dev/null @@ -1,11 +0,0 @@ -{% extends "git_browse/base.html" %} - -{% block gitbrowse %} - -

Tree sha1 hash:

- {{ hash }} -

Shortlog:

- {% include "git_browse/shortlog_table" %} -

Directory listing:

- {% include "git_browse/tree_table" %} -{% endblock %} diff --git a/bn_django/git_browse/templates/git_browse/tree_table b/bn_django/git_browse/templates/git_browse/tree_table deleted file mode 100644 index ce10c10..0000000 --- a/bn_django/git_browse/templates/git_browse/tree_table +++ /dev/null @@ -1,32 +0,0 @@ -{% if all_objs %} - - {% for o in all_objs %} - - - - {% else %} {% ifequal o.type 'tree' %} - - {{o.name}}/ - - {% else %} - - {{o.name}} - - {% endifequal %}{% endifequal %} - - {% endfor %} -
- {{o.type}} - {{ o.mode }} - {% ifequal o.type 'blob' %} - - {{o.name}} - - log - - browse | - zip - -
-{% else %}No contents! -{% endif %} diff --git a/bn_django/git_browse/urls.py b/bn_django/git_browse/urls.py deleted file mode 100644 index b608027..0000000 --- a/bn_django/git_browse/urls.py +++ /dev/null @@ -1,48 +0,0 @@ -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] - -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\d+)/$', 'object_detail', -# dict(info_dict, queryset=Gallery.objects.all())), -# (r'^detail/(?P\d+)/$', 'object_detail', -# dict(info_dict, queryset=Photo.objects.all())), -) - -urlpatterns += patterns('bn_django.git_browse.views', - (r'^(?P[\w\-\_]*)/$', 'repo_info',), - (r'^(?P[\w\-\_]*)/branches/$', 'view_branches',), - (r'^(?P[\w\-\_]*)/log/$', 'view_log',), - (r'^(?P[\w\-\_]*)/obj/(?P[0-9a-z]{40})/$', 'view_obj',), - (r'^(?P[\w\-\_]*)/commit/(?P[0-9a-z]{40})/$', 'view_commit',), - #(r'^(?P[\w\-\_]*)/commit/$', 'view_commit',), - (r'^(?P[\w\-\_]*)/commit/(?P[0-9a-z]{40})/zip/$', 'zip',), - #TODO: head and tag views - (r'^(?P[\w\-\_]*)/tag/(?P[\w\-\_]+)/$', 'view_commit',), - (r'^(?P[\w\-\_]*)/tag/(?P[0-9a-z]{40})/zip/$', 'zip',), - (r'^(?P[\w\-\_]*)/head/(?P[\w\-\_]+)/$', 'view_commit',), - (r'^(?P[\w\-\_]*)/head/(?P[0-9a-z]{40})/zip/$', 'zip',), - (r'^(?P[\w\-\_]*)/blob/(?P[0-9a-z]{40})/$', '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})/zip/$', 'zip',), -) diff --git a/bn_django/git_browse/views.py b/bn_django/git_browse/views.py deleted file mode 100644 index 23b0191..0000000 --- a/bn_django/git_browse/views.py +++ /dev/null @@ -1,167 +0,0 @@ -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: - GITCOMMAND = settings.GITCOMMAND -except AttributeError: - GITCOMMAND='git' - - -# Create your views here. - -def repo_info(request, repo,branch=None): - therepo = get_object_or_404(Repository, slug=repo) - (GITPREFIX, heads, tags) = therepo.scan() - - branches = commands.getoutput(GITPREFIX + ' branch') - filelist = commands.getoutput(GITPREFIX + ' ls-files') - shortlog = therepo.shortlog() - - 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() - - if(hash == None): - head_ref = commands.getoutput('cd ' + therepo.path + '; cat HEAD') - head_ref = head_ref.split()[1] - hash = commands.getoutput('cd ' + therepo.path + '; cat ' + head_ref) - - tree_ls = commands.getoutput(GITPREFIX + ' ls-tree ' + hash) - tree_objs = list() - blob_objs = list() - for line in tree_ls.splitlines(): - l = line.split() - if len(l) < 4: - continue - if l[1] == 'tree': - t = Tree(id=l[2]) - t.path = ' '.join(l[3:]) - #if self.path and self.path != '/': - # t.path = self.path + '/' + t.path - t.name = t.path - t.type = 'tree' - tree_objs.append(t) - if l[1] == 'blob': - i = Blob(id=l[2]) - i.path = ' '.join(l[3:]) - #if self.path and self.path != '/': - # i.path = self.path + '/' + i.path - i.name=i.path - i.type = 'blob' - blob_objs.append(i) - - return render_to_response('git_browse/tree.html', - dict(object=therepo, - blob_objs=blob_objs, - tree_objs=tree_objs, - hash=hash, - all_objs=tree_objs+blob_objs,)) - -def view_log(request, repo, hash=None): - therepo = get_object_or_404(Repository, slug=repo) - (GITPREFIX, heads, tags) = therepo.scan() - - 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_blob(request, repo, hash): - therepo = get_object_or_404(Repository, slug=repo) - (GITPREFIX, heads, tags) = therepo.scan() - b = Blob(id=hash,repo=therepo) - b.update() - try: - from pygments import highlight - from pygments.lexers import guess_lexer - from pygments.formatters import HtmlFormatter - b.pretty_contents = highlight(b.contents, guess_lexer(b.contents), HtmlFormatter()) - except: - b.pretty_contents = None - - return render_to_response('git_browse/blob.html', - dict(object=therepo, - heads=heads, - tags=tags, - hash=b.id, - size=b.size, - contents=b.contents, - pretty_contents=b.pretty_contents)) - -def view_commit(request, repo, hash): - therepo = get_object_or_404(Repository, slug=repo) - (GITPREFIX, heads, tags) = therepo.scan() - c = Commit(id=hash,repo=therepo) - c.update() - - try: - from pygments import highlight - from pygments.lexers import DiffLexer - from pygments.formatters import HtmlFormatter - c.pretty_diff = highlight(c.rawdiff, DiffLexer(), HtmlFormatter()) - except: pass - - return render_to_response('git_browse/commit.html', - dict(object=therepo, heads=heads, tags=tags, - commit=c)) - -def view_obj(request, repo, hash, branch=None): - therepo = get_object_or_404(Repository, slug=repo) - (GITPREFIX, heads, tags) = therepo.scan() - - obj_type = commands.getoutput(GITPREFIX + ' cat-file -t ' + hash) - 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), - contents=obj_contents)) - -def zip(request, repo, hash): - therepo = get_object_or_404(Repository, slug=repo) - (GITPREFIX, heads, tags) = therepo.scan() - t = Tree(id=hash,repo=therepo) - t.update() - - hr = HttpResponse(mimetype="application/zip") - hr['Content-Disposition'] = 'filename=%s.zip' % t.id - archive = commands.getoutput(GITPREFIX + \ - ' archive --format=zip ' + hash + ' | cat') - hr.write(archive) - return hr -- cgit v1.2.3