Skip to content

Commit

Permalink
Add command to print out information about SVN revision
Browse files Browse the repository at this point in the history
  • Loading branch information
kxepal committed Jan 24, 2014
1 parent 3b1b75c commit c6040ea
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tasman/app.py
Expand Up @@ -8,8 +8,10 @@
#

import datetime
import time
import urlparse
import xmlrpclib
import pysvn
from copy import copy
from Queue import Queue, Empty
from collections import defaultdict
Expand All @@ -20,8 +22,11 @@

app = XmppFlask('tasman')
app.config['TRAC_URL'] = 'http://trac.miranda-ng.org/rpc'
app.config['SVN_REPO_URL'] = 'http://svn.miranda-ng.org/main'
app.config['SVN_REV_URL'] = 'http://trac.miranda-ng.org/changeset/%d'
app.session_interface = MemorySessionInterface()
MESSAGE_QUEUE = defaultdict(Queue)
svn = pysvn.Client()


@app.route(u'<any(test,тест):cmd>')
Expand Down Expand Up @@ -114,3 +119,29 @@ def ticket(cmd, idx):
items[2] = 'ticket/%d' % idx
url = urlparse.urlunsplit(items)
return render_template('ticket.html', info=info, error=error, url=url)


@app.route(u'r<int:rev>', defaults={'cmd': 'r'})
@app.route(u'<any(rev,revision,commit):cmd> <int:rev>')
@app.route(u'<any(рев,ревизия,коммит):cmd> <int:rev>')
def revision(cmd, rev):
res, err = None, None
try:
log = svn.log(app.config['SVN_REPO_URL'],
revision_start=pysvn.Revision(
pysvn.opt_revision_kind.number, rev),
limit=1)
except pysvn.ClientError:
err = 'No such revision %s' % rev
else:
if not log:
err = 'No such revision %s' % rev
else:
offset = int(time.time()) - int(time.mktime(time.gmtime()))
res = dict(log[0].items())
res['revision'] = res['revision'].number
res['url'] = app.config['SVN_REV_URL'] % res['revision']
res['date'] = datetime.datetime.fromtimestamp(
int(res['date']) - offset).isoformat(sep=' ') + 'Z'

return render_template('revision.html', info=res, error=err)
9 changes: 9 additions & 0 deletions tasman/templates/revision.html
@@ -0,0 +1,9 @@
{%- if error -%}

{{ error }}

{%- else -%}

{{ request.username }}: [{{ info.date }}] {{ info.url }} - {{ info.message }}

{%- endif -%}
71 changes: 71 additions & 0 deletions tasman/tests/test_cmd_revision.py
@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2014 Alexander Shorin
# All rights reserved.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
#

import unittest
from xmppflask import JID
from tasman.app import app


class RevisionCmdTestCase(unittest.TestCase):

def test_not_found(self):
environ = {'xmpp.body': 'rev 000', 'xmpp.jid': JID('tasman@xmpp.ru')}

rv = app(environ)
self.assertEquals(list(rv), ['No such revision 0'])

def test_invalid_id(self):
environ = {'xmpp.body': 'rev XYZ', 'xmpp.jid': JID('tasman@xmpp.ru')}

rv = app(environ)
self.assertEquals(list(rv), [])

def check_resp(self, resp):
expected = u'tasman: [2012-02-11 18:58:26Z] http://trac.miranda-ng.org/changeset/1 - Create defaults dir'
self.assertEqual(resp, expected)

def test_shortcut(self):
environ = {'xmpp.body': 'r1', 'xmpp.jid': JID('tasman@xmpp.ru'),
'xmpp.stanza_type': 'chat'}

rv = app(environ)
self.check_resp(rv.next())

def test_revision_en(self):
environ = {'xmpp.body': 'rev 1', 'xmpp.jid': JID('tasman@xmpp.ru'),
'xmpp.stanza_type': 'chat'}
rv = app(environ)
self.check_resp(rv.next())

environ = {'xmpp.body': 'revision 1', 'xmpp.jid': JID('tasman@xmpp.ru'),
'xmpp.stanza_type': 'chat'}
rv = app(environ)
self.check_resp(rv.next())

environ = {'xmpp.body': 'commit 1', 'xmpp.jid': JID('tasman@xmpp.ru'),
'xmpp.stanza_type': 'chat'}
rv = app(environ)
self.check_resp(rv.next())

def test_ticket_ru(self):
environ = {'xmpp.body': u'рев 1', 'xmpp.jid': JID('tasman@xmpp.ru'),
'xmpp.stanza_type': 'chat'}
rv = app(environ)
self.check_resp(rv.next())

environ = {'xmpp.body': u'ревизия 1',
'xmpp.jid': JID('tasman@xmpp.ru'),
'xmpp.stanza_type': 'chat'}
rv = app(environ)
self.check_resp(rv.next())

environ = {'xmpp.body': u'коммит 1', 'xmpp.jid': JID('tasman@xmpp.ru'),
'xmpp.stanza_type': 'chat'}
rv = app(environ)
self.check_resp(rv.next())

0 comments on commit c6040ea

Please sign in to comment.