@@ -287,193 +287,193 @@ def make_ui(read_from='file', path=None,
def set_rhodecode_config(config):
"""Updates pylons config with new settings from database
:param config:
"""
hgsettings = RhodeCodeSettings.get_app_settings()
for k, v in hgsettings.items():
config[k] = v
def invalidate_cache(cache_key, *args):
"""Puts cache invalidation task into db for
further global cache invalidation
from rhodecode.model.scm import ScmModel
if cache_key.startswith('get_repo_cached_'):
name = cache_key.split('get_repo_cached_')[-1]
ScmModel().mark_for_invalidation(name)
class EmptyChangeset(BaseChangeset):
An dummy empty changeset. It's possible to pass hash when creating
an EmptyChangeset
def __init__(self, cs='0' * 40, repo=None):
self._empty_cs = cs
self.revision = -1
self.message = ''
self.author = ''
self.date = ''
self.repository = repo
@LazyProperty
def raw_id(self):
"""Returns raw string identifying this changeset, useful for web
representation.
return self._empty_cs
def short_id(self):
return self.raw_id[:12]
def get_file_changeset(self, path):
return self
def get_file_content(self, path):
return u''
def get_file_size(self, path):
return 0
def map_groups(groups):
"""Checks for groups existence, and creates groups structures.
It returns last group in structure
:param groups: list of groups structure
sa = meta.Session()
parent = None
group = None
for lvl, group_name in enumerate(groups[:-1]):
group = sa.query(Group).filter(Group.group_name == group_name).scalar()
if group is None:
group = Group(group_name, parent)
sa.add(group)
sa.commit()
parent = group
return group
def repo2db_mapper(initial_repo_list, remove_obsolete=False):
"""maps all repos given in initial_repo_list, non existing repositories
are created, if remove_obsolete is True it also check for db entries
that are not in initial_repo_list and removes them.
:param initial_repo_list: list of repositories found by scanning methods
:param remove_obsolete: check for obsolete entries in database
rm = RepoModel()
user = sa.query(User).filter(User.admin == True).first()
added = []
for name, repo in initial_repo_list.items():
group = map_groups(name.split('/'))
group = map_groups(name.split(os.sep))
if not rm.get_by_repo_name(name, cache=False):
log.info('repository %s not found creating default', name)
added.append(name)
form_data = {
'repo_name': name,
'repo_name_full': name,
'repo_type': repo.alias,
'description': repo.description \
if repo.description != 'unknown' else \
'%s repository' % name,
'private': False,
'group_id': getattr(group, 'group_id', None)
}
rm.create(form_data, user, just_db=True)
removed = []
if remove_obsolete:
#remove from database those repositories that are not in the filesystem
for repo in sa.query(Repository).all():
if repo.repo_name not in initial_repo_list.keys():
removed.append(repo.repo_name)
sa.delete(repo)
return added, removed
#set cache regions for beaker so celery can utilise it
def add_cache(settings):
cache_settings = {'regions': None}
for key in settings.keys():
for prefix in ['beaker.cache.', 'cache.']:
if key.startswith(prefix):
name = key.split(prefix)[1].strip()
cache_settings[name] = settings[key].strip()
if cache_settings['regions']:
for region in cache_settings['regions'].split(','):
region = region.strip()
region_settings = {}
for key, value in cache_settings.items():
if key.startswith(region):
region_settings[key.split('.')[1]] = value
region_settings['expire'] = int(region_settings.get('expire',
60))
region_settings.setdefault('lock_dir',
cache_settings.get('lock_dir'))
region_settings.setdefault('data_dir',
cache_settings.get('data_dir'))
if 'type' not in region_settings:
region_settings['type'] = cache_settings.get('type',
'memory')
beaker.cache.cache_regions[region] = region_settings
def get_current_revision():
"""Returns tuple of (number, id) from repository containing this package
or None if repository could not be found.
try:
from vcs import get_repo
from vcs.utils.helpers import get_scm
from vcs.exceptions import RepositoryError, VCSError
repopath = os.path.join(os.path.dirname(__file__), '..', '..')
scm = get_scm(repopath)[0]
repo = get_repo(path=repopath, alias=scm)
tip = repo.get_changeset()
return (tip.revision, tip.short_id)
except (ImportError, RepositoryError, VCSError), err:
logging.debug("Cannot retrieve rhodecode's revision. Original error "
"was: %s" % err)
return None
#==============================================================================
# TEST FUNCTIONS AND CREATORS
def create_test_index(repo_location, config, full_index):
Makes default test index
:param config: test config
:param full_index:
from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon
from rhodecode.lib.pidlock import DaemonLock, LockHeld
repo_location = repo_location
index_location = os.path.join(config['app_conf']['index_dir'], 'index')
if not os.path.exists(index_location):
os.makedirs(index_location)
l = DaemonLock(file=jn(dn(index_location), 'make_index.lock'))
Status change: