Parent: [c0bdf0] (diff)

Child: [754c9d] (diff)

Download this file

hg_main.py    68 lines (57 with data), 2.4 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
#-*- python -*-
import logging
# Non-stdlib imports
import pkg_resources
from pylons import c, g
from ming.utils import LazyProperty
from ming.orm.ormsession import ThreadLocalORMSession
# Pyforge-specific imports
from allura.lib import helpers as h
from allura import model as M
from allura.controllers.repository import RepoRootController, RefsController, CommitsController
from allura.controllers.repository import MergeRequestsController
from allura.lib.repository import RepositoryApp
# Local imports
from . import model as HM
from . import version
from .controllers import BranchBrowser
log = logging.getLogger(__name__)
class ForgeHgApp(RepositoryApp):
'''This is the Git app for PyForge'''
__version__ = version.__version__
tool_label='Mercurial'
default_mount_label='Mercurial'
default_mount_point='mercurial'
ordinal=3
forkable=True
default_branch_name='ref/default'
def __init__(self, project, config):
super(ForgeHgApp, self).__init__(project, config)
self.root = RepoRootController()
self.root.ref = RefsController(BranchBrowser)
self.root.ci = CommitsController()
setattr(self.root, 'merge-requests', MergeRequestsController())
@LazyProperty
def repo(self):
return HM.Repository.query.get(app_config_id=self.config._id)
def install(self, project):
'''Create repo object for this tool'''
super(ForgeHgApp, self).install(project)
repo = HM.Repository(
name=self.config.options.mount_point,
tool='hg',
status='initing')
ThreadLocalORMSession.flush_all()
cloned_from_project_id = self.config.options.get('cloned_from_project_id')
cloned_from_repo_id = self.config.options.get('cloned_from_repo_id')
if cloned_from_project_id is not None:
with h.push_config(c, project=M.Project.query.get(_id=cloned_from_project_id)):
cloned_from = HM.Repository.query.get(_id=cloned_from_repo_id)
msg = dict(
cloned_from_path=cloned_from.full_fs_path,
cloned_from_name=cloned_from.app.config.script_name(),
cloned_from_url=cloned_from.app.url)
g.publish('audit', 'repo.clone', msg)
else:
g.publish('audit', 'repo.init',
dict(repo_name=repo.name, repo_path=repo.fs_path))