##// END OF EJS Templates
updated tests for new version 6char password etc...
updated tests for new version 6char password etc...

File last commit:

r531:6fc59ac3 default
r533:53aa1ee1 default
Show More
hg_model.py
172 lines | 6.5 KiB | text/x-python | PythonLexer
Marcin Kuzminski
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
r58 #!/usr/bin/env python
# encoding: utf-8
licensing updates, code cleanups
r252 # Model for hg app
# Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
Added permissions check on repo switcher,...
r373 #
licensing updates, code cleanups
r252 # 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
Marcin Kuzminski
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
r58 @author: marcink
licensing updates, code cleanups
r252 """
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 from beaker.cache import cache_region
from mercurial import ui
from mercurial.hgweb.hgwebdir_mod import findrepos
Added permissions check on repo switcher,...
r373 from pylons.i18n.translation import _
from pylons_app.lib.auth import HasRepoPermissionAny
Added application settings, are now customizable from database...
r350 from pylons_app.model import meta
Fixes #18, removing user, who owns some repositories
r376 from pylons_app.model.db import Repository, User
fixed, empty cs bug....
r450 from pylons_app.lib import helpers as h
Added permissions check on repo switcher,...
r373 from vcs.exceptions import RepositoryError, VCSError
added info about forked repository in few places...
r531 from sqlalchemy.orm import joinedload
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 import logging
Marcin Kuzminski
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
r58 import os
cleared prints leftoovers, and changed current user fetching in login controller
r195 import sys
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 log = logging.getLogger(__name__)
Marcin Kuzminski
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
r58 try:
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 from vcs.backends.hg import MercurialRepository
Marcin Kuzminski
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
r58 except ImportError:
cleared prints leftoovers, and changed current user fetching in login controller
r195 sys.stderr.write('You have to import vcs module')
Change logic for more vcs based.
r95 raise Exception('Unable to import vcs')
Marcin Kuzminski
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
r58
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators...
r368 def _get_repos_cached_initial(app_globals, initial):
added caching queries to hg-app
r482 """return cached dict with repos
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 """
g = app_globals
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators...
r368 return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui, initial)
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245
@cache_region('long_term', 'cached_repo_list')
def _get_repos_cached():
added caching queries to hg-app
r482 """return cached dict with repos
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 """
changed way of getting repository in changelog. + some code cleanups
r276 log.info('getting all repositories list')
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 from pylons import app_globals as g
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui)
Added permissions check on repo switcher,...
r373 @cache_region('super_short_term', 'cached_repos_switcher_list')
def _get_repos_switcher_cached(cached_repo_list):
repos_lst = []
fixed sorting in repo list switcher and removed lower() since repo names can be have capital letters now
r488 for repo in [x for x in cached_repo_list.values()]:
added caching queries to hg-app
r482 if HasRepoPermissionAny('repository.write', 'repository.read',
removed .lower() from permission checking of cached repos list since repos can have capital letters now
r511 'repository.admin')(repo.name, 'main page check'):
fixed sorting in repo list switcher and removed lower() since repo names can be have capital letters now
r488 repos_lst.append((repo.name, repo.dbrepo.private,))
Added permissions check on repo switcher,...
r373
removed .lower() from permission checking of cached repos list since repos can have capital letters now
r511 return sorted(repos_lst, key=lambda k:k[0].lower())
Added permissions check on repo switcher,...
r373
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 @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))))
Marcin Kuzminski
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
r58 class HgModel(object):
added caching queries to hg-app
r482 """Mercurial Model
Marcin Kuzminski
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
r58 """
def __init__(self):
added caching queries to hg-app
r482 pass
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245
@staticmethod
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators...
r368 def repo_scan(repos_prefix, repos_path, baseui, initial=False):
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 """
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
"""
Added application settings, are now customizable from database...
r350 sa = meta.Session()
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 def check_repo_dir(path):
added caching queries to hg-app
r482 """Checks the repository
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 :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)):
Improved testing scenarios. Made test env creator...
r473 raise RepositoryError('Not a valid repository in %s' % path)
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 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:
Added support for repository located in subdirectories.
r248 #name = name.split('/')[-1]
if repos_list.has_key(name):
raise RepositoryError('Duplicate repository name %s found in'
' %s' % (name, path))
else:
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265
Added support for repository located in subdirectories.
r248 repos_list[name] = MercurialRepository(path, baseui=baseui)
repos_list[name].name = name
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators...
r368
dbrepo = None
if not initial:
dbrepo = sa.query(Repository)\
added info about forked repository in few places...
r531 .options(joinedload(Repository.fork))\
.filter(Repository.repo_name == name)\
.scalar()
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators...
r368
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 if dbrepo:
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators...
r368 log.info('Adding db instance to cached list')
db model fix, added repo instance to cached repos list
r303 repos_list[name].dbrepo = dbrepo
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
r265 repos_list[name].description = dbrepo.description
Fixes #18, removing user, who owns some repositories
r376 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
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 except OSError:
continue
Added application settings, are now customizable from database...
r350 meta.Session.remove()
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 return repos_list
Marcin Kuzminski
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
r58 def get_repos(self):
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 for name, repo in _get_repos_cached().items():
if repo._get_hidden():
Marcin Kuzminski
Updated model with never vcs implementation using MercurialRepo class
r73 #skip hidden web repository
continue
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 last_change = repo.last_change
fixed, empty cs bug....
r450 tip = h.get_changeset_safe(repo, 'tip')
Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
r136
Marcin Kuzminski
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
r58 tmp_d = {}
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 tmp_d['name'] = repo.name
fixed sorting of repos with big letters
r222 tmp_d['name_sort'] = tmp_d['name'].lower()
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 tmp_d['description'] = repo.description
Marcin Kuzminski
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
r58 tmp_d['description_sort'] = tmp_d['description']
Marcin Kuzminski
reimplemented summary page,...
r80 tmp_d['last_change'] = last_change
Marcin Kuzminski
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
r58 tmp_d['last_change_sort'] = last_change[1] - last_change[0]
refactoring for new vcs implementation...
r512 tmp_d['tip'] = tip.short_id
Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
r136 tmp_d['tip_sort'] = tip.revision
tmp_d['rev'] = tip.revision
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 tmp_d['contact'] = repo.contact
Marcin Kuzminski
Updated model with never vcs implementation using MercurialRepo class
r73 tmp_d['contact_sort'] = tmp_d['contact']
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 tmp_d['repo_archives'] = list(repo._get_archives())
implemented yui tooltip, and added it into annotation and main page.
r281 tmp_d['last_msg'] = tip.message
db model fix, added repo instance to cached repos list
r303 tmp_d['repo'] = repo
Marcin Kuzminski
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
r58 yield tmp_d
Marcin Kuzminski
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
r74
def get_repo(self, repo_name):
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
r245 return _get_repos_cached()[repo_name]