Files
@ 36102488d634
Branch filter:
Location: kallithea/pylons_app/lib/utils.py - annotation
36102488d634
2.9 KiB
text/x-python
Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
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 | cc5cf1a93902 cc5cf1a93902 2811259dc12d 2811259dc12d 2811259dc12d 2811259dc12d 2811259dc12d 670713507d03 670713507d03 f24b9a2934cf aec4c0071cb3 670713507d03 f24b9a2934cf f24b9a2934cf f24b9a2934cf f24b9a2934cf f24b9a2934cf f24b9a2934cf f24b9a2934cf f24b9a2934cf f24b9a2934cf f24b9a2934cf cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 2811259dc12d 2811259dc12d 2811259dc12d 2811259dc12d 2811259dc12d 2811259dc12d 2811259dc12d 2811259dc12d 2811259dc12d 2811259dc12d 2811259dc12d 2811259dc12d 2811259dc12d 2811259dc12d 2811259dc12d 2811259dc12d 2811259dc12d cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 2811259dc12d cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 cc5cf1a93902 36102488d634 36102488d634 36102488d634 36102488d634 36102488d634 cc5cf1a93902 36102488d634 36102488d634 36102488d634 36102488d634 36102488d634 36102488d634 36102488d634 cc5cf1a93902 | import os
import logging
from mercurial import ui, config, hg
from mercurial.error import RepoError
log = logging.getLogger(__name__)
def get_repo_slug(request):
path_info = request.environ.get('PATH_INFO')
uri_lst = path_info.split('/')
repo_name = uri_lst[1]
return repo_name
def is_mercurial(environ):
"""
Returns True if request's target is mercurial server - header
``HTTP_ACCEPT`` of such request would start with ``application/mercurial``.
"""
http_accept = environ.get('HTTP_ACCEPT')
if http_accept and http_accept.startswith('application/mercurial'):
return True
return False
def check_repo_dir(paths):
repos_path = paths[0][1].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 Exception('Not a valid repository in %s' % paths[0][1])
def check_repo(repo_name, base_path):
repo_path = os.path.join(base_path, repo_name)
try:
r = hg.repository(ui.ui(), repo_path)
hg.verify(r)
#here we hnow that repo exists it was verified
log.info('%s repo is already created', repo_name)
return False
#raise Exception('Repo exists')
except RepoError:
log.info('%s repo is free for creation', repo_name)
#it means that there is no valid repo there...
return True
def make_ui(path='hgwebdir.config', checkpaths=True):
"""
A funcion that will read python rc files and make an ui from read options
@param path: path to mercurial config file
"""
if not os.path.isfile(path):
log.error('Unable to read config file %s' % path)
return False
#propagated from mercurial documentation
sections = [
'alias',
'auth',
'decode/encode',
'defaults',
'diff',
'email',
'extensions',
'format',
'merge-patterns',
'merge-tools',
'hooks',
'http_proxy',
'smtp',
'patch',
'paths',
'profiling',
'server',
'trusted',
'ui',
'web',
]
baseui = ui.ui()
cfg = config.config()
cfg.read(path)
if checkpaths:check_repo_dir(cfg.items('paths'))
for section in sections:
for k, v in cfg.items(section):
baseui.setconfig(section, k, v)
return baseui
from vcs.backends.base import BaseChangeset
from vcs.utils.lazy import LazyProperty
class EmptyChangeset(BaseChangeset):
revision = -1
@LazyProperty
def raw_id(self):
"""
Returns raw string identifing this changeset, useful for web
representation.
"""
return '0' * 12
|