Changeset - f905f45c457e
[Not reviewed]
default
1 5 0
Marcin Kuzminski - 16 years ago 2010-05-17 01:51:47
marcin@python-works.com
moved diff libs to vcs. updated htmls and css for diff and source
6 files changed with 21 insertions and 251 deletions:
0 comments (0 inline, 0 general)
pylons_app/controllers/files.py
Show inline comments
 
import logging
 

	
 
from pylons import request, response, session, tmpl_context as c, url, config, app_globals as g
 
from pylons.controllers.util import abort, redirect
 

	
 
from pylons_app.lib.base import BaseController, render
 
from pylons_app.lib.utils import get_repo_slug
 
from pylons_app.model.hg_model import HgModel
 
from difflib import unified_diff
 
from pylons_app.lib.differ import render_udiff
 
from vcs.utils import diffs as differ
 
from vcs.exceptions import RepositoryError, ChangesetError
 
        
 
log = logging.getLogger(__name__)
 

	
 
class FilesController(BaseController):
 
    def __before__(self):
 
        c.repos_prefix = config['repos_name']
 
        c.repo_name = get_repo_slug(request)
 

	
 
    def index(self, repo_name, revision, f_path):
 
        hg_model = HgModel()
 
        c.repo = repo = hg_model.get_repo(c.repo_name)
 
        revision = request.POST.get('at_rev', None) or revision
 
        
 
        def get_next_rev(cur):
 
            max_rev = len(c.repo.revisions) - 1
 
            r = cur + 1
 
            if r > max_rev:
 
                r = max_rev
 
            return r
 
            
 
        def get_prev_rev(cur):
 
            r = cur - 1
 
            return r
 

	
 
        c.f_path = f_path
 
     
 
        
 
        try:
 
            cur_rev = repo.get_changeset(revision).revision
 
            prev_rev = repo.get_changeset(get_prev_rev(cur_rev)).raw_id
 
            next_rev = repo.get_changeset(get_next_rev(cur_rev)).raw_id
 
                    
 
            c.url_prev = url('files_home', repo_name=c.repo_name,
 
                             revision=prev_rev, f_path=f_path) 
 
            c.url_next = url('files_home', repo_name=c.repo_name,
 
                             revision=next_rev, f_path=f_path)   
 
                    
 
            c.changeset = repo.get_changeset(revision)
 
            try:
 
                c.file_msg = c.changeset.get_file_message(f_path)
 
            except:
 
                c.file_msg = None
 
                        
 
            c.cur_rev = c.changeset.raw_id
 
            c.rev_nr = c.changeset.revision
 
            c.files_list = c.changeset.get_node(f_path)
 
            c.file_history = self._get_history(repo, c.files_list, f_path)
 
            
 
        except (RepositoryError, ChangesetError):
 
            c.files_list = None
 
        
 
        return render('files/files.html')
 

	
 
    def rawfile(self, repo_name, revision, f_path):
 
        hg_model = HgModel()
 
        c.repo = hg_model.get_repo(c.repo_name)
 
        file_node = c.repo.get_changeset(revision).get_node(f_path)
 
        response.headers['Content-type'] = file_node.mimetype
 
        response.headers['Content-disposition'] = 'attachment; filename=%s' \
 
                                                    % f_path.split('/')[-1] 
 
        return file_node.content
 
    
 
    def archivefile(self, repo_name, revision, fileformat):
 
        return '%s %s %s' % (repo_name, revision, fileformat)
 
    
 
    def diff(self, repo_name, f_path):
 
        hg_model = HgModel()
 
        diff1 = request.GET.get('diff1')
 
        diff2 = request.GET.get('diff2')
 
        c.no_changes = diff1 == diff2
 
        c.f_path = f_path
 
        c.repo = hg_model.get_repo(c.repo_name)
 
        c.changeset_1 = c.repo.get_changeset(diff1)
 
        c.changeset_2 = c.repo.get_changeset(diff2)
 
        f1 = c.changeset_1.get_node(f_path)
 
        f2 = c.changeset_2.get_node(f_path)
 

	
 
        c.diff1 = 'r%s:%s' % (c.changeset_1.revision, c.changeset_1._short)
 
        c.diff2 = 'r%s:%s' % (c.changeset_2.revision, c.changeset_2._short)
 

	
 
        f_udiff = unified_diff(f1.content.splitlines(True),
 
                               f2.content.splitlines(True),
 
                               f1.name,
 
                               f2.name)
 
        
 
        
 
        c.diff_files = render_udiff(udiff=f_udiff, differ='difflib')
 
        print c.diff_files
 
        if len(c.diff_files) < 1:
 
            c.no_changes = True
 
        f_udiff = differ.get_udiff(c.changeset_1.get_node(f_path),
 
                            c.changeset_2.get_node(f_path))
 
        c.differ = differ.DiffProcessor(f_udiff)
 
        return render('files/file_diff.html')
 
    
 
    def _get_history(self, repo, node, f_path):
 
        from vcs.nodes import NodeKind
 
        if not node.kind is NodeKind.FILE:
 
            return []
 
        changesets = node.history
 
        hist_l = []
 
        for chs in changesets:
 
            n_desc = 'r%s:%s' % (chs.revision, chs._short)
 
            hist_l.append((chs._short, n_desc,))
 
        return hist_l
pylons_app/lib/differ.py
Show inline comments
 
deleted file
pylons_app/public/css/diff.css
Show inline comments
 
div.diffblock {
 
    overflow: auto;
 
    padding: 0px;
 
    border: 1px solid #ccc;
 
    background: #f8f8f8;
 
    font-size: 100%;
 
    line-height: 100%;
 
    /* new */
 
    line-height: 125%;
 
}
 
div.diffblock .code-header{
 
	border-bottom: 1px solid #CCCCCC;
 
	background: #EEEEEE;
 
	color:blue;
 
	padding:10px 0 10px 0;
 
}
 
div.diffblock .code-header span{
 
	margin-left:25px;
 
	font-weight: bold;
 
}
 
div.diffblock .code-body{
 
	background: #EEEEEE;
 
}
 

	
 
.code-difftable{
 
	border-collapse: collapse;
 
	width: 99%;
 
}
 
.code-difftable td:target *{
 
	background:  repeat scroll 0 0 #FFFFBE !important;
 
	text-decoration: underline;
 
}
 
.code-difftable .context{
 
	background:none repeat scroll 0 0 #DDE7EF;
 
}
 
.code-difftable .add{
 
	background:none repeat scroll 0 0 #DDFFDD;
 
}
 
.code-difftable .add ins{
 
	background:none repeat scroll 0 0 #AAFFAA;
 
	text-decoration:none;
 
}
 

	
 
.code-difftable .del{
 
	background:none repeat scroll 0 0 #FFDDDD;
 
}
 
.code-difftable .del del{
 
	background:none repeat scroll 0 0 #FFAAAA;
 
	text-decoration:none;
 
}
 

	
 
.code-difftable .lineno{
 
	background:none repeat scroll 0 0 #EEEEEE !important;
 
	border-right:1px solid #DDDDDD;
 
	padding-left:2px;
 
	padding-right:2px;
 
	text-align:right;
 
	width:20px;
 
	-moz-user-select:none;
 
	-webkit-user-select: none;
 
}
 
.code-difftable .lineno pre{
 
	color:#747474 !important;
 
	font:11px "Bitstream Vera Sans Mono",Monaco,"Courier New",Courier,monospace !important;
 
	letter-spacing:-1px;
 
	text-align:right;
 
	width:20px;
 
}
 
.code-difftable .lineno a{
 
	color:#0000CC !important;
 
}
 
.code-difftable .code td{
 
	margin:0;
 
	padding: 0;
 
}
 
.code-difftable .code pre{
 
	margin:0;
 
	padding:0;
 
}
 

	
 

	
 
.code { 
 
	display: block;
 
	width: 100%;
 
}
 
.code-diff {
 
    padding: 0px;
 
    margin-top: 5px;
 
    margin-bottom: 5px;
 
    border-left: 2px solid #ccc;
 
}
 
.code-diff pre, .line pre { 
 
	padding: 3px;
 
    margin: 0;
 
}
 
.lineno a { 
 
	text-decoration: none; 
 
}
 

	
 
.line{
 
	padding:0;
 
	margin:0;
 
}
 
\ No newline at end of file
pylons_app/public/css/pygments.css
Show inline comments
 
div.codeblock {
 
    overflow: auto;
 
    padding: 0px;
 
    border: 1px solid #ccc;
 
    background: #f8f8f8;
 
    font-size: 100%;
 
    line-height: 100%;
 
    /* new */
 
    line-height: 125%;
 
}
 
div.codeblock .code-header{
 
	border-bottom: 1px solid #CCCCCC;
 
	background: #EEEEEE;
 
	color:blue;
 
	padding:10px 0 10px 0;
 
}
 
div.codeblock .code-header span{
 
div.codeblock .code-header .revision{
 
	margin-left:25px;
 
	font-weight: bold;
 
}
 
div.codeblock .code-header .commit{
 
	margin-left:25px;
 
	font-weight: normal;
 
}
 

	
 
.code-highlight {
 
    padding: 0px;
 
    margin-top: 5px;
 
    margin-bottom: 5px;
 
    border-left: 2px solid #ccc;
 
}
 
.code-highlight pre, .linenodiv pre { 
 
	padding: 5px;
 
    margin: 0;
 
}
 
.linenos a { text-decoration: none; }
 

	
 

	
 
.code { display: block; }
 
.code-highlight .hll { background-color: #ffffcc }
 
.code-highlight .c { color: #408080; font-style: italic } /* Comment */
 
.code-highlight .err { border: 1px solid #FF0000 } /* Error */
 
.code-highlight .k { color: #008000; font-weight: bold } /* Keyword */
 
.code-highlight .o { color: #666666 } /* Operator */
 
.code-highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
 
.code-highlight .cp { color: #BC7A00 } /* Comment.Preproc */
 
.code-highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
 
.code-highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
 
.code-highlight .gd { color: #A00000 } /* Generic.Deleted */
 
.code-highlight .ge { font-style: italic } /* Generic.Emph */
 
.code-highlight .gr { color: #FF0000 } /* Generic.Error */
 
.code-highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
 
.code-highlight .gi { color: #00A000 } /* Generic.Inserted */
 
.code-highlight .go { color: #808080 } /* Generic.Output */
 
.code-highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
 
.code-highlight .gs { font-weight: bold } /* Generic.Strong */
 
.code-highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
 
.code-highlight .gt { color: #0040D0 } /* Generic.Traceback */
 
.code-highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
 
.code-highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
 
.code-highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
 
.code-highlight .kp { color: #008000 } /* Keyword.Pseudo */
 
.code-highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
 
.code-highlight .kt { color: #B00040 } /* Keyword.Type */
 
.code-highlight .m { color: #666666 } /* Literal.Number */
 
.code-highlight .s { color: #BA2121 } /* Literal.String */
 
.code-highlight .na { color: #7D9029 } /* Name.Attribute */
 
.code-highlight .nb { color: #008000 } /* Name.Builtin */
 
.code-highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
 
.code-highlight .no { color: #880000 } /* Name.Constant */
 
.code-highlight .nd { color: #AA22FF } /* Name.Decorator */
 
.code-highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
 
.code-highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
 
.code-highlight .nf { color: #0000FF } /* Name.Function */
 
.code-highlight .nl { color: #A0A000 } /* Name.Label */
 
.code-highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
 
.code-highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
 
.code-highlight .nv { color: #19177C } /* Name.Variable */
 
.code-highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
 
.code-highlight .w { color: #bbbbbb } /* Text.Whitespace */
 
.code-highlight .mf { color: #666666 } /* Literal.Number.Float */
 
.code-highlight .mh { color: #666666 } /* Literal.Number.Hex */
 
.code-highlight .mi { color: #666666 } /* Literal.Number.Integer */
 
.code-highlight .mo { color: #666666 } /* Literal.Number.Oct */
 
.code-highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
 
.code-highlight .sc { color: #BA2121 } /* Literal.String.Char */
 
.code-highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
 
.code-highlight .s2 { color: #BA2121 } /* Literal.String.Double */
 
.code-highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
 
.code-highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
 
.code-highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
 
.code-highlight .sx { color: #008000 } /* Literal.String.Other */
 
.code-highlight .sr { color: #BB6688 } /* Literal.String.Regex */
 
.code-highlight .s1 { color: #BA2121 } /* Literal.String.Single */
 
.code-highlight .ss { color: #19177C } /* Literal.String.Symbol */
 
.code-highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
 
.code-highlight .vc { color: #19177C } /* Name.Variable.Class */
 
.code-highlight .vg { color: #19177C } /* Name.Variable.Global */
 
.code-highlight .vi { color: #19177C } /* Name.Variable.Instance */
 
.code-highlight .il { color: #666666 } /* Literal.Number.Integer.Long */
pylons_app/templates/files/file_diff.html
Show inline comments
 
<%inherit file="/base/base.html"/>
 

	
 
<%def name="title()">
 
    ${_('Repository managment')}
 
</%def>
 
<%def name="breadcrumbs()">
 
    ${h.link_to(u'Home',h.url('/'))}
 
    / 
 
    ${h.link_to(c.repo_name,h.url('files_home',repo_name=c.repo_name))}
 
    /
 
    ${_('files')}
 
</%def>
 
<%def name="page_nav()">
 
        <form action="log">
 
            <dl class="search">
 
                <dt><label>Search: </label></dt>
 
                <dd><input type="text" name="rev" /></dd>
 
            </dl>
 
        </form>
 

	
 
		${self.menu('files')}     
 
</%def>
 
<%def name="css()">
 
<link rel="stylesheet" href="/css/monoblue_custom.css" type="text/css" />
 
<link rel="stylesheet" href="/css/diff.css" type="text/css" />
 
</%def>
 
<%def name="main()">
 
    <h2 class="no-link no-border">${'%s:  %s %s %s' % (_('File diff'),c.diff2,'&rarr;',c.diff1)|n}</h2>
 
<div id="body" class="diffblock">
 
	<div class="code-header">
 
		<span>${h.link_to(c.f_path,h.url('files_home',repo_name=c.repo_name,revision=c.diff2.split(':')[1],f_path=c.f_path))}</span>
 
	</div>
 
	<div class="code-body">
 
 			%if c.no_changes:
 
            	${_('No changes')}
 
            %else:        
 
	            <table class='code-difftable'>
 
	            %for diff in c.diff_files:
 
		            %for x in diff['chunks']:
 
		                %for y in x:
 
		                    <tr class="line ${y['action']}">
 
		                        <td id="#${diff['filename']}_O${y['old_lineno']}" class="lineno old">
 
		                              <pre><a href="#${diff['filename']}_O${y['old_lineno']}">${y['old_lineno']}</a></pre>
 
		                        </td>		                    
 
		                        <td id="#${diff['filename']}_N${y['new_lineno']}"class="lineno new">
 
		                              <pre><a href="#${diff['filename']}_N${y['new_lineno']}">${y['new_lineno']}</a></pre>
 
		                        </td>                        
 
		                       <td class="code">
 
		                           <pre>${y['line']|n}</pre>
 
		                       </td>
 
		                    </tr>
 
		                %endfor$
 
		            %endfor
 
		        %endfor
 
	            </table>
 
				${c.differ.as_HTML()|n}
 
            %endif
 
	</div>
 
</div>
 
</%def>    
 
\ No newline at end of file
pylons_app/templates/files/files_source.html
Show inline comments
 
<dl class="overview">
 
	<dt>${_('Revision')}</dt>
 
	<dd>r${c.files_list.last_changeset.revision}:${c.files_list.last_changeset._short}</dd>
 
	<dt>${_('Size')}</dt>
 
	<dd>${h.filesizeformat(c.files_list.size)}</dd>
 
	<dt>${_('Options')}</dt>
 
	<dd>${h.link_to(_('annotate'),h.url('#'))}  / ${h.link_to(_('raw'),h.url('files_raw_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}</dd>
 
	<dt>${_('History')}</dt>
 
	<dd>
 
		${h.form(h.url('files_diff_home',repo_name=c.repo_name,f_path=c.f_path),method='GET')}
 
		${h.hidden('diff2',c.files_list.last_changeset._short)}
 
		${h.select('diff1','',c.file_history)}
 
		${h.submit('diff','diff')}
 
		${h.end_form()}
 
	</dd>
 
					
 
</dl>		
 
<div id="body" class="codeblock">
 
	<div class="code-header">
 
		<span>${c.files_list.name}@r${c.files_list.last_changeset.revision}:${c.files_list.last_changeset._short}</span>
 
		 <span style="font-size:70%">"${c.file_msg}"</span>
 
		<div class="revision">${c.files_list.name}@r${c.files_list.last_changeset.revision}:${c.files_list.last_changeset._short}</div>
 
		<div class="commit" style="font-size:70%">"${c.file_msg}"</div>
 
	</div>
 
	<div class="code-body">
 
		${h.pygmentize(c.files_list.content,linenos=True,anchorlinenos=True,cssclass="code-highlight")}
 
	</div>
 
</div>
 
\ No newline at end of file
0 comments (0 inline, 0 general)