annotate pylons_app/controllers/changeset.py @ 294:42f5c36820ef

few validation bugfixes/ new repo changesets, first commit changesets
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 14 Jun 2010 01:16:57 +0200
parents cad478edb1c7
children fdf9f6ee5217
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
1 #!/usr/bin/env python
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
2 # encoding: utf-8
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
3 # changeset controller for pylons
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
294
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
5 from pylons import tmpl_context as c, url
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
6 from pylons.controllers.util import redirect
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
7 from pylons_app.lib.auth import LoginRequired
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
8 from pylons_app.lib.base import BaseController, render
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
9 from pylons_app.model.hg_model import HgModel
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
10 from vcs.exceptions import RepositoryError
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
11 from vcs.nodes import FileNode
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
12 from vcs.utils import diffs as differ
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
13 import logging
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
14 import traceback
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
15
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
16 # This program is free software; you can redistribute it and/or
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
17 # modify it under the terms of the GNU General Public License
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
18 # as published by the Free Software Foundation; version 2
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
19 # of the License or (at your opinion) any later version of the license.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
20 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
21 # This program is distributed in the hope that it will be useful,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
24 # GNU General Public License for more details.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
25 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
26 # You should have received a copy of the GNU General Public License
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
27 # along with this program; if not, write to the Free Software
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
28 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
29 # MA 02110-1301, USA.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
30 """
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
31 Created on April 25, 2010
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
32 changeset controller for pylons
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
33 @author: marcink
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
34 """
193
50a39f923f31 Added file annotation template. Bumped version to 0.6.8. Changelog and changeset are now cleaned with js, it's still very beta.
Marcin Kuzminski <marcin@python-works.com>
parents: 103
diff changeset
35
50a39f923f31 Added file annotation template. Bumped version to 0.6.8. Changelog and changeset are now cleaned with js, it's still very beta.
Marcin Kuzminski <marcin@python-works.com>
parents: 103
diff changeset
36
103
665b344927f4 Added changeset controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 log = logging.getLogger(__name__)
665b344927f4 Added changeset controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38
665b344927f4 Added changeset controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39 class ChangesetController(BaseController):
193
50a39f923f31 Added file annotation template. Bumped version to 0.6.8. Changelog and changeset are now cleaned with js, it's still very beta.
Marcin Kuzminski <marcin@python-works.com>
parents: 103
diff changeset
40
50a39f923f31 Added file annotation template. Bumped version to 0.6.8. Changelog and changeset are now cleaned with js, it's still very beta.
Marcin Kuzminski <marcin@python-works.com>
parents: 103
diff changeset
41 @LoginRequired()
103
665b344927f4 Added changeset controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 def __before__(self):
193
50a39f923f31 Added file annotation template. Bumped version to 0.6.8. Changelog and changeset are now cleaned with js, it's still very beta.
Marcin Kuzminski <marcin@python-works.com>
parents: 103
diff changeset
43 super(ChangesetController, self).__before__()
103
665b344927f4 Added changeset controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44
193
50a39f923f31 Added file annotation template. Bumped version to 0.6.8. Changelog and changeset are now cleaned with js, it's still very beta.
Marcin Kuzminski <marcin@python-works.com>
parents: 103
diff changeset
45 def index(self, revision):
50a39f923f31 Added file annotation template. Bumped version to 0.6.8. Changelog and changeset are now cleaned with js, it's still very beta.
Marcin Kuzminski <marcin@python-works.com>
parents: 103
diff changeset
46 hg_model = HgModel()
294
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
47 try:
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
48 c.changeset = hg_model.get_repo(c.repo_name).get_changeset(revision)
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
49 except RepositoryError:
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
50 log.error(traceback.format_exc())
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
51 return redirect(url('hg_home'))
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
52 else:
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
53 try:
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
54 c.changeset_old = c.changeset.parents[0]
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
55 except IndexError:
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
56 c.changeset_old = None
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
57 c.changes = []
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
58
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
59 for node in c.changeset.added:
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
60 filenode_old = FileNode(node.path, '')
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
61 if filenode_old.is_binary or node.is_binary:
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
62 diff = 'binary file'
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
63 else:
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
64 f_udiff = differ.get_udiff(filenode_old, node)
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
65 diff = differ.DiffProcessor(f_udiff).as_html()
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
66 try:
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
67 diff = unicode(diff)
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
68 except:
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
69 log.warning('Decoding failed of %s', filenode_old)
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
70 log.warning('Decoding failed of %s', node)
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
71 diff = 'unsupported type'
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
72 cs1 = None
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
73 cs2 = node.last_changeset.raw_id
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
74 c.changes.append(('added', node, diff, cs1, cs2))
218
58b46f9194c3 version bump. Made changesets work as should, but vcs had to be fixed for that.
Marcin Kuzminski <marcin@python-works.com>
parents: 193
diff changeset
75
294
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
76 for node in c.changeset.changed:
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
77 filenode_old = c.changeset_old.get_node(node.path)
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
78 if filenode_old.is_binary or node.is_binary:
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
79 diff = 'binary file'
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
80 else:
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
81 f_udiff = differ.get_udiff(filenode_old, node)
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
82 diff = differ.DiffProcessor(f_udiff).as_html()
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
83 try:
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
84 diff = unicode(diff)
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
85 except:
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
86 log.warning('Decoding failed of %s', filenode_old)
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
87 log.warning('Decoding failed of %s', node)
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
88 diff = 'unsupported type'
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
89 cs1 = filenode_old.last_changeset.raw_id
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
90 cs2 = node.last_changeset.raw_id
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
91 c.changes.append(('changed', node, diff, cs1, cs2))
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
92
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
93 for node in c.changeset.removed:
42f5c36820ef few validation bugfixes/ new repo changesets, first commit changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
94 c.changes.append(('removed', node, None, None, None))
218
58b46f9194c3 version bump. Made changesets work as should, but vcs had to be fixed for that.
Marcin Kuzminski <marcin@python-works.com>
parents: 193
diff changeset
95
193
50a39f923f31 Added file annotation template. Bumped version to 0.6.8. Changelog and changeset are now cleaned with js, it's still very beta.
Marcin Kuzminski <marcin@python-works.com>
parents: 103
diff changeset
96 return render('changeset/changeset.html')