Parent: [820035] (diff)

Download this file

scm_main.py    107 lines (91 with data), 3.6 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
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
#-*- python -*-
import os
import logging
# Non-stdlib imports
import pkg_resources
from pylons import g, c
import genshi
from ming import schema
from ming.orm.base import session
# Pyforge-specific imports
from pyforge.app import Application, ConfigOption, SitemapEntry
from pyforge.lib.helpers import push_config, mixin_reactors, set_context
from pyforge.lib.security import require, has_artifact_access
from pyforge.lib.decorators import react
from pyforge.model import ProjectRole
# Local imports
from . import model
from . import version
from .wsgi import WSGIHook
from .reactors import common_react, hg_react, git_react, svn_react
from .controllers import root
log = logging.getLogger(__name__)
class ForgeSCMApp(Application):
__version__ = version.__version__
permissions = ['configure', 'read' ]
config_options = Application.config_options + [
ConfigOption('type', schema.OneOf('git', 'hg', 'svn'), 'hg'),
]
wsgi=WSGIHook()
def __init__(self, project, config):
Application.__init__(self, project, config)
self.root = root.RootController()
@property
def repo(self):
return model.Repository.query.get(app_config_id=self.config._id)
@property
def sitemap(self):
menu_id = self.config.options.mount_point.title()
with push_config(c, app=self):
return [
SitemapEntry(menu_id, '.')[self.sidebar_menu()] ]
def sidebar_menu(self):
base = self.repo.url()
result = [
SitemapEntry('Home', base),
SitemapEntry('Search', base + 'search'),
SitemapEntry('Init Repo', base + 'reinit'),
]
repo = self.repo
if self.config.options.type in 'hg':
result += [
SitemapEntry('HgWeb', repo.native_url()),
SitemapEntry('Files', repo.native_url() + '/file') ]
elif self.config.options.type == 'git':
result += [
SitemapEntry('GitWeb', repo.native_url() + '.git?p='+repo.app.config.options.mount_point) ]
elif self.config.options.type == 'svn':
result += [
SitemapEntry('Browser', repo.native_url()) ]
return result
@property
def templates(self):
return pkg_resources.resource_filename('forgescm', 'templates')
def install(self, project):
'Set up any default permissions and roles here'
super(ForgeSCMApp, self).install(project)
# Give the installing user all the permissions
pr = c.user.project_role()
for perm in self.permissions:
self.config.acl[perm] = [ pr._id ]
self.config.acl['read'].append(
ProjectRole.query.get(name='*anonymous')._id)
# Create a repository
repo_dir = pkg_resources.resource_filename(
'forgescm',
os.path.join('data', self.project.shortname, self.config.options.mount_point))
repo = model.Repository(
description='This is the repository object',
status='Pending',
type=self.config.options['type'],
repo_dir=repo_dir)
session(repo).flush()
def uninstall(self, project):
"Remove all the plugin's artifacts from the database"
repo = self.repo
if repo: repo.delete()
super(ForgeSCMApp, self).uninstall(project)
mixin_reactors(ForgeSCMApp, common_react)
mixin_reactors(ForgeSCMApp, hg_react)
mixin_reactors(ForgeSCMApp, git_react)
mixin_reactors(ForgeSCMApp, svn_react)