diff --git a/pygit/chart.py b/pygit/chart.py
index 310e277..8abff8a 100644
--- a/pygit/chart.py
+++ b/pygit/chart.py
@@ -2,13 +2,10 @@
from os.path import exists
import cairo
+from django.conf import settings
+
width,height = 900,150
pl,pr,py = 10,30,17
-root = "/home/portnov/www/projects/"
-
-COLORS = [(0.9,0.9,0.5),
- (0.2,0.2,0.9),
- (0.2,0.9,0.2)]
def chart_path(data):
return "/media/charts/chart_%s.png" % hash(data)
@@ -58,6 +55,6 @@ def make_chart(labels,dataset,colors,out_path):
def chart(labels,dataset):
path = chart_path((tuple(labels),tuple(map(tuple,dataset))))
- if not exists(root+path):
- make_chart(labels,dataset,COLORS,root+path)
+ if not exists(settings.ROOT+path):
+ make_chart(labels,dataset,settings.COLORS,settings.ROOT+path)
return "<img src='%s'/>" % path
diff --git a/pygit/pygit.py b/pygit/pygit.py
index 4db66f7..3a35958 100644
--- a/pygit/pygit.py
+++ b/pygit/pygit.py
@@ -1,5 +1,6 @@
from os.path import basename,dirname,exists
+import gzip
from git import *
# sys.path.append(dirname(dirname(__file__)))
@@ -45,13 +46,15 @@ def date(tp):
y,m,d,h,M,s,_,_,_ = tp
return "%d.%d.%d %d:%d:%d" % (d,m,y,h,M,s)
-def tarball(rid,tid):
+def tarball(rid,branch):
r = open_repo(rid)
- path = "/media/tarballs/archive-%s-%s.tar.gz" % (rid,tid)
- if not exists(path):
- f = open(path,'w')
- targz = r.archive_tar_gz(tid)
- f.write(targz)
+ cid = r.commits(branch)[0].id_abbrev
+ name = basename(settings.REPOS[int(rid)])
+ path = "/media/tarballs/%s-%s-%s.tar.gz" % (name,branch,cid)
+ if not exists(settings.ROOT+path):
+ f = gzip.open(settings.ROOT+path,'w')
+ tar = r.archive_tar(branch,name+'/')
+ f.write(tar)
f.close()
return path
diff --git a/pygit/urls.py b/pygit/urls.py
index 566d3e1..00deabd 100644
--- a/pygit/urls.py
+++ b/pygit/urls.py
@@ -8,5 +8,6 @@ urlpatterns = patterns('',
(r'^blame/(\d+)/(\w+)/(.*)/$','pygit.views.blame'),
(r'^diff/(\d+)/(\w+)/(\w+)/$', 'pygit.views.diff_all'),
(r'^diff/(\d+)/(\w+)/(\w+)/(.*)/$', 'pygit.views.diff_file'),
+ (r'^targz/(\d+)/(\w+)/$', 'pygit.views.tarball'),
)
diff --git a/pygit/views.py b/pygit/views.py
index 9fb3abd..00dcf3b 100644
--- a/pygit/views.py
+++ b/pygit/views.py
@@ -3,7 +3,8 @@
import sys
from os.path import dirname,join
-# from django.template.defaultfilters import escape
+from django.http import HttpResponseRedirect
+from django.core.urlresolvers import reverse
import pygit
from chart import chart
@@ -35,7 +36,6 @@ def one_repo(request,rid,branch='master'):
dirs,files = pygit.root_tree(rid,branch)
dates,n_commits,files_s,lines = pygit.commits_stats(rid,branch)
cht = chart(dates,[n_commits,files_s,lines])
-# cht = chart(pygit.commits_stats(rid,branch))
return render_it('repo.html',
{'description': dsc,
'rid': rid,
@@ -69,6 +69,10 @@ def blame(request,rid,branch,path):
'blame': bl},
request)
+def tarball(request,rid,tid):
+ file = pygit.tarball(rid,tid)
+ return HttpResponseRedirect(file)
+
def escape(s):
s1 = s.replace('<','<')
return s1.replace('>','>')
diff --git a/settings.py b/settings.py
index cb5d872..ebf5f67 100644
--- a/settings.py
+++ b/settings.py
@@ -112,3 +112,8 @@ REPOS = ['/home/portnov/www/projects',
'/home/portnov/www/projects/mgmt/hms',
'/home/portnov/git/pylambda']
+ROOT = "/home/portnov/www/projects/"
+
+COLORS = [(0.9,0.9,0.5),
+ (0.2,0.2,0.9),
+ (0.2,0.9,0.2)]
diff --git a/templates/git_diff.html b/templates/git_diff.html
index 4df4822..b6728f2 100644
--- a/templates/git_diff.html
+++ b/templates/git_diff.html
@@ -5,6 +5,9 @@
{% block git %}
<h2>Diff: #{{cid}}{% if path %} {{path}}{% endif %}</h2>
+<div class='links'>
+ <a href='{% url pygit.views.tarball repo.rid,cid %}'>Скачать в tar.gz</a>
+</div>
<p><a href='{% url pygit.views.diff_all repo.rid,branch,cid %}'>Коммит: {{message}}</a></p>
<p>Автор: {{author}}, дата: {{date}}</p>
<p>Всего файлов: {{total_stats.files}}, всего строк: {{total_stats.lines}},
diff --git a/templates/repo.html b/templates/repo.html
index f79f90f..e888993 100644
--- a/templates/repo.html
+++ b/templates/repo.html
@@ -4,6 +4,10 @@
{% block main %}
+<div class='links'>
+ <a href='{% url pygit.views.tarball rid,current_branch %}'>Скачать в tar.gz</a>
+</div>
+
<h2>Репозиторий: {{description}}</h2>
<div class='links'>