Parent: [f4f159] (diff)

Download this file

common_react.py    89 lines (77 with data), 3.1 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
import logging
from pylons import c, g
from ming.orm.base import state
from pyforge.lib.decorators import audit, react
from pyforge.lib.helpers import push_context, set_context, encode_keys
from forgescm.lib import hg, git
from pyforge import model as M
from pymongo import bson
log = logging.getLogger(__name__)
@react('scm.initialized')
def initialized(routing_key, data):
shortname = M.Project.query.get(_id=bson.ObjectId(data['project_id'])).shortname
set_context(shortname, data['mount_point'])
repo = c.app.repo
log.info('Setting repo status for %s', repo)
repo.status = 'Ready'
@react('scm.forked')
def forked_update_source(routing_key, data):
log.info('Updating the source of a fork (%s)', data['forked_from'])
set_context(**encode_keys(data['forked_from']))
repo = c.app.repo
repo.forks.append(data['forked_to'])
@react('scm.forked')
def forked_update_dest(routing_key, data):
log.info('Updating the dest of a fork', data['forked_to'])
set_context(**encode_keys(data['forked_to']))
# Update dest repo
repo = c.app.repo
repo.forked_from.update(data['forked_from'])
repo.clear_commits()
# Copy history from source
commit_extra = dict(
app_config_id = c.app.config._id,
repository_id = repo._id)
# Copy the history
log.info('Begin history copy')
with push_context(**encode_keys(repo.forked_from)):
parent_repo = c.app.repo
for commit in parent_repo.commits:
patches = commit.patches
with push_context(**encode_keys(data['forked_to'])):
commit_dict = state(commit).document.deinstrumented_clone()
commit_dict.update(commit_extra)
del commit_dict['_id']
commit = M.Commit(**commit_dict)
for p in patches:
patch_dict = state(p).document.deinstrumented_clone()
patch_dict.update(commit_extra, commit_id=commit._id)
del patch_dict['_id']
M.Patch(**patch_dict)
log.info('History copy complete')
@react('scm.cloned')
def cloned(routing_key, data):
shortname = M.Project.query.get(_id=bson.ObjectId(data['project_id'])).shortname
set_context(shortname, data['mount_point'])
repo = c.app.repo
# Update the repo status
repo.status = 'Ready'
repo.parent = data['url']
# Load the log & create refresh commit messages
log.info('Begin log %s', data['url'])
type = c.app.config.options['type']
if type == 'hg':
cmd = hg.scm_log('-g', '-p')
parser = hg.LogParser(repo._id)
cmd.run(output_consumer=parser.feed)
elif type == 'git':
cmd = git.scm_log('-p')
parser = git.LogParser(repo._id)
cmd.run(output_consumer=parser.feed)
elif type == 'svn':
cmd = hg.scm_log('-g', '-p', '--debug', 'hg_repo')
parser = hg.LogParser(repo._id)
cmd.run(output_consumer=parser.feed)
else:
log.warning('Cannot index repos of type %s', type)
log.info('Log complete %s', data['url'])