Mercurial > kallithea
comparison pylons_app/model/hg_model.py @ 265:0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 07 Jun 2010 00:18:33 +0200 |
parents | 3782a6d698af |
children | 5e59f29edf66 |
comparison
equal
deleted
inserted
replaced
264:0d68a749db33 | 265:0e5455fda8fd |
---|---|
25 """ | 25 """ |
26 | 26 |
27 from beaker.cache import cache_region | 27 from beaker.cache import cache_region |
28 from mercurial import ui | 28 from mercurial import ui |
29 from mercurial.hgweb.hgwebdir_mod import findrepos | 29 from mercurial.hgweb.hgwebdir_mod import findrepos |
30 from pylons import app_globals as g | |
31 from vcs.exceptions import RepositoryError, VCSError | 30 from vcs.exceptions import RepositoryError, VCSError |
31 from pylons_app.model.meta import Session | |
32 from pylons_app.model.db import Repository | |
32 import logging | 33 import logging |
33 import os | 34 import os |
34 import sys | 35 import sys |
35 log = logging.getLogger(__name__) | 36 log = logging.getLogger(__name__) |
36 | 37 |
38 from vcs.backends.hg import MercurialRepository | 39 from vcs.backends.hg import MercurialRepository |
39 except ImportError: | 40 except ImportError: |
40 sys.stderr.write('You have to import vcs module') | 41 sys.stderr.write('You have to import vcs module') |
41 raise Exception('Unable to import vcs') | 42 raise Exception('Unable to import vcs') |
42 | 43 |
44 def _get_repos_cached_initial(app_globals): | |
45 """ | |
46 return cached dict with repos | |
47 """ | |
48 g = app_globals | |
49 return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui) | |
43 | 50 |
44 @cache_region('long_term', 'cached_repo_list') | 51 @cache_region('long_term', 'cached_repo_list') |
45 def _get_repos_cached(): | 52 def _get_repos_cached(): |
46 """ | 53 """ |
47 return cached dict with repos | 54 return cached dict with repos |
48 """ | 55 """ |
56 from pylons import app_globals as g | |
49 return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui) | 57 return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui) |
50 | 58 |
51 @cache_region('long_term', 'full_changelog') | 59 @cache_region('long_term', 'full_changelog') |
52 def _full_changelog_cached(repo_name): | 60 def _full_changelog_cached(repo_name): |
53 log.info('getting full changelog for %s', repo_name) | 61 log.info('getting full changelog for %s', repo_name) |
60 | 68 |
61 def __init__(self): | 69 def __init__(self): |
62 """ | 70 """ |
63 Constructor | 71 Constructor |
64 """ | 72 """ |
65 pass | |
66 | 73 |
67 @staticmethod | 74 @staticmethod |
68 def repo_scan(repos_prefix, repos_path, baseui): | 75 def repo_scan(repos_prefix, repos_path, baseui): |
69 """ | 76 """ |
70 Listing of repositories in given path. This path should not be a | 77 Listing of repositories in given path. This path should not be a |
71 repository itself. Return a dictionary of repository objects | 78 repository itself. Return a dictionary of repository objects |
72 :param repos_path: path to directory it could take syntax with | 79 :param repos_path: path to directory it could take syntax with |
73 * or ** for deep recursive displaying repositories | 80 * or ** for deep recursive displaying repositories |
74 """ | 81 """ |
82 sa = Session() | |
75 def check_repo_dir(path): | 83 def check_repo_dir(path): |
76 """ | 84 """ |
77 Checks the repository | 85 Checks the repository |
78 :param path: | 86 :param path: |
79 """ | 87 """ |
100 #name = name.split('/')[-1] | 108 #name = name.split('/')[-1] |
101 if repos_list.has_key(name): | 109 if repos_list.has_key(name): |
102 raise RepositoryError('Duplicate repository name %s found in' | 110 raise RepositoryError('Duplicate repository name %s found in' |
103 ' %s' % (name, path)) | 111 ' %s' % (name, path)) |
104 else: | 112 else: |
113 | |
105 repos_list[name] = MercurialRepository(path, baseui=baseui) | 114 repos_list[name] = MercurialRepository(path, baseui=baseui) |
106 repos_list[name].name = name | 115 repos_list[name].name = name |
116 dbrepo = sa.query(Repository).get(name) | |
117 if dbrepo: | |
118 repos_list[name].description = dbrepo.description | |
119 repos_list[name].contact = dbrepo.user.full_contact | |
107 except OSError: | 120 except OSError: |
108 continue | 121 continue |
109 return repos_list | 122 return repos_list |
110 | 123 |
111 def get_repos(self): | 124 def get_repos(self): |