Files
@ fdebc5f67dc6
Branch filter:
Location: kallithea/pylons_app/model/hg_model.py - annotation
fdebc5f67dc6
6.4 KiB
text/x-python
Some gui fixes
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | 8fb1abd4178a 8fb1abd4178a 3782a6d698af 3782a6d698af 3171614c0067 3782a6d698af 3782a6d698af 3782a6d698af 3782a6d698af 3782a6d698af 3782a6d698af 3782a6d698af 3782a6d698af 3782a6d698af 3782a6d698af 3782a6d698af 3782a6d698af 3782a6d698af 3782a6d698af 3782a6d698af 3782a6d698af 3782a6d698af 8fb1abd4178a 3782a6d698af a83a1799480c a83a1799480c a83a1799480c 3171614c0067 3171614c0067 664a5b8c551a 7fbf81447c6c c3236d7febad 3171614c0067 a83a1799480c 8fb1abd4178a 7109d15c6813 a83a1799480c a83a1799480c 8fb1abd4178a a83a1799480c 8fb1abd4178a 7109d15c6813 a214462101d2 8fb1abd4178a e9a6783f5502 0e5455fda8fd 0e5455fda8fd 0e5455fda8fd 0e5455fda8fd e9a6783f5502 a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c 5e59f29edf66 0e5455fda8fd a83a1799480c a83a1799480c 3171614c0067 3171614c0067 3171614c0067 fdebc5f67dc6 fdebc5f67dc6 fdebc5f67dc6 3171614c0067 3171614c0067 3171614c0067 a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c 8fb1abd4178a 8fb1abd4178a 8fb1abd4178a 8fb1abd4178a 8fb1abd4178a 8fb1abd4178a 8fb1abd4178a 8fb1abd4178a 8fb1abd4178a a83a1799480c a83a1799480c e9a6783f5502 a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c 664a5b8c551a a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c 6b934c9607e7 a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c a83a1799480c fb7f066126cc fb7f066126cc fb7f066126cc fb7f066126cc fb7f066126cc 0e5455fda8fd fb7f066126cc fb7f066126cc e9a6783f5502 e9a6783f5502 e9a6783f5502 e9a6783f5502 e9a6783f5502 e9a6783f5502 0e5455fda8fd e9a6783f5502 3a66e7421a99 0e5455fda8fd 7fbf81447c6c 7fbf81447c6c 7fbf81447c6c 7fbf81447c6c 7fbf81447c6c a83a1799480c a83a1799480c 664a5b8c551a a83a1799480c a83a1799480c 8fb1abd4178a a83a1799480c a83a1799480c 55d7f2502dfb 55d7f2502dfb 55d7f2502dfb a83a1799480c c3236d7febad 36102488d634 8fb1abd4178a a83a1799480c f7dadd356c79 a83a1799480c 8fb1abd4178a 928416088790 8fb1abd4178a 36102488d634 36102488d634 36102488d634 a83a1799480c 55d7f2502dfb a83a1799480c cd2ee462fc2c 3a66e7421a99 8fb1abd4178a cdf4fda66dd9 cdf4fda66dd9 a83a1799480c | #!/usr/bin/env python
# encoding: utf-8
# Model for hg app
# Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2
# of the License or (at your opinion) any later version of the license.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
"""
Created on April 9, 2010
Model for hg app
@author: marcink
"""
from beaker.cache import cache_region
from mercurial import ui
from mercurial.hgweb.hgwebdir_mod import findrepos
from pylons.i18n.translation import _
from pylons_app.lib.auth import HasRepoPermissionAny
from pylons_app.model import meta
from pylons_app.model.db import Repository, User
from pylons_app.lib import helpers as h
from vcs.exceptions import RepositoryError, VCSError
import logging
import os
import sys
log = logging.getLogger(__name__)
try:
from vcs.backends.hg import MercurialRepository
except ImportError:
sys.stderr.write('You have to import vcs module')
raise Exception('Unable to import vcs')
def _get_repos_cached_initial(app_globals, initial):
"""
return cached dict with repos
"""
g = app_globals
return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui, initial)
@cache_region('long_term', 'cached_repo_list')
def _get_repos_cached():
"""
return cached dict with repos
"""
log.info('getting all repositories list')
from pylons import app_globals as g
return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui)
@cache_region('super_short_term', 'cached_repos_switcher_list')
def _get_repos_switcher_cached(cached_repo_list):
repos_lst = []
for repo in sorted(x for x in cached_repo_list.values()):
if HasRepoPermissionAny('repository.write', 'repository.read', 'repository.admin')(repo.name.lower(), 'main page check'):
repos_lst.append((repo.name.lower(), repo.dbrepo.private,))
return repos_lst
@cache_region('long_term', 'full_changelog')
def _full_changelog_cached(repo_name):
log.info('getting full changelog for %s', repo_name)
return list(reversed(list(HgModel().get_repo(repo_name))))
class HgModel(object):
"""
Mercurial Model
"""
def __init__(self):
"""
Constructor
"""
@staticmethod
def repo_scan(repos_prefix, repos_path, baseui, initial=False):
"""
Listing of repositories in given path. This path should not be a
repository itself. Return a dictionary of repository objects
:param repos_path: path to directory it could take syntax with
* or ** for deep recursive displaying repositories
"""
sa = meta.Session()
def check_repo_dir(path):
"""
Checks the repository
:param path:
"""
repos_path = path.split('/')
if repos_path[-1] in ['*', '**']:
repos_path = repos_path[:-1]
if repos_path[0] != '/':
repos_path[0] = '/'
if not os.path.isdir(os.path.join(*repos_path)):
raise RepositoryError('Not a valid repository in %s' % path)
if not repos_path.endswith('*'):
raise VCSError('You need to specify * or ** at the end of path '
'for recursive scanning')
check_repo_dir(repos_path)
log.info('scanning for repositories in %s', repos_path)
repos = findrepos([(repos_prefix, repos_path)])
if not isinstance(baseui, ui.ui):
baseui = ui.ui()
repos_list = {}
for name, path in repos:
try:
#name = name.split('/')[-1]
if repos_list.has_key(name):
raise RepositoryError('Duplicate repository name %s found in'
' %s' % (name, path))
else:
repos_list[name] = MercurialRepository(path, baseui=baseui)
repos_list[name].name = name
dbrepo = None
if not initial:
dbrepo = sa.query(Repository)\
.filter(Repository.repo_name == name).scalar()
if dbrepo:
log.info('Adding db instance to cached list')
repos_list[name].dbrepo = dbrepo
repos_list[name].description = dbrepo.description
if dbrepo.user:
repos_list[name].contact = dbrepo.user.full_contact
else:
repos_list[name].contact = sa.query(User)\
.filter(User.admin == True).first().full_contact
except OSError:
continue
meta.Session.remove()
return repos_list
def get_repos(self):
for name, repo in _get_repos_cached().items():
if repo._get_hidden():
#skip hidden web repository
continue
last_change = repo.last_change
tip = h.get_changeset_safe(repo, 'tip')
tmp_d = {}
tmp_d['name'] = repo.name
tmp_d['name_sort'] = tmp_d['name'].lower()
tmp_d['description'] = repo.description
tmp_d['description_sort'] = tmp_d['description']
tmp_d['last_change'] = last_change
tmp_d['last_change_sort'] = last_change[1] - last_change[0]
tmp_d['tip'] = tip.raw_id
tmp_d['tip_sort'] = tip.revision
tmp_d['rev'] = tip.revision
tmp_d['contact'] = repo.contact
tmp_d['contact_sort'] = tmp_d['contact']
tmp_d['repo_archives'] = list(repo._get_archives())
tmp_d['last_msg'] = tip.message
tmp_d['repo'] = repo
yield tmp_d
def get_repo(self, repo_name):
return _get_repos_cached()[repo_name]
|