Parent: [a404b5] (diff)

Download this file

svn_react.py    95 lines (81 with data), 2.8 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'''
Subversion support is a little bit weird. The approach used here is to
use the repo_dir as a base and have a svn repo checked out alongside an hg clone
of that svn repo:
$repo_dir
|-svn_repo
\-hg_repo
We will use the hgsubversion extension to clone svn=>hg and then use as
much as possible from the hg implementation after that.
'''
import logging
from cStringIO import StringIO
from pylons import c, g
from pymongo import bson
from pyforge.lib.decorators import audit, react
from pyforge.lib.helpers import push_context, set_context, encode_keys
from pyforge.model import Project
from forgescm.lib import svn, hg
from forgescm import model as M
log = logging.getLogger(__name__)
## Auditors
@audit('scm.svn.init')
def init(routing_key, data):
log.info('SVN init')
repo = c.app.repo
return repo.do_init(data, "svn")
@audit('scm.svn.clone')
def clone(routing_key, data):
repo = c.app.repo
return repo.do_clone(data['url'], "svn")
@audit('scm.svn.fork')
def fork(routing_key, data):
assert False # SVN forking is not supported
@audit('scm.svn.reclone')
def reclone(routing_key, data):
set_context(data['project_id'], data['mount_point'])
repo = c.app.repo
repo.clear_commits()
# Perform the clone
try:
svn.svn_clone(repo.parent)
svn.setup_commit_hook(repo.repo_dir, c.app.config.script_name()[1:])
g.publish('react', 'scm.cloned', dict(
url=data['url']))
repo.status = 'Ready'
except AssertionError, ae:
g.publish('react', 'error', dict(
message=ae.args[0]))
repo.status = 'Error: %s' % ae.args[0]
except Exception, ex:
g.publish('react', 'error', dict(message=str(ex)))
repo.status = 'Error: %s' % ex
## Reactors
@react('scm.svn.refresh_commit')
def refresh_commit(routing_key, data):
set_context(data['project_id'], data['mount_point'])
repo = c.app.repo
hash = data['hash']
log.info('Refresh commit %s', hash)
# Load the log
try:
svn.scm_rebase().run_exc()
cmd = svn.scm_log('-g', '-p', '--debug', '-r', hash).run_exc()
parser = hg.LogParser(repo._id)
parser.feed(StringIO(cmd.output))
except AssertionError, ae:
g.publish('react', 'error', dict(
message=ae.args[0]))
repo.status = 'Error: %s' % ae.args[0]
except Exception, ex:
g.publish('react', 'error', dict(message=str(ex)))
repo.status = 'Error: %s' % ex
@react('scm.svn.cloned')
def refresh_log(routing_key, data):
set_context(data['project_id'], data['mount_point'])
repo = c.app.repo
repo.clear_commits()
cmd = svn.scm_log('-g', '-p', '--debug')
cmd.run()
parser = hg.LogParser(repo._id)
parser.feed(StringIO(cmd.output))