# HG changeset patch # User Mads Kiilerich # Date 2020-10-10 23:02:46 # Node ID 072c0352dd36565a5085499fc0cb5d1088d08ab0 # Parent fb37ca246267b971ae4cde920407d246911f36d6 imports: always use CONFIG as kallithea.CONFIG diff --git a/kallithea/controllers/feed.py b/kallithea/controllers/feed.py --- a/kallithea/controllers/feed.py +++ b/kallithea/controllers/feed.py @@ -33,7 +33,7 @@ from tg import response from tg import tmpl_context as c from tg.i18n import ugettext as _ -from kallithea import CONFIG +import kallithea from kallithea.lib import feeds from kallithea.lib import helpers as h from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired @@ -67,7 +67,7 @@ class FeedController(BaseRepoController) desc_msg.append('tag: %s
' % tag) changes = [] - diff_limit = safe_int(CONFIG.get('rss_cut_off_limit', 32 * 1024)) + diff_limit = safe_int(kallithea.CONFIG.get('rss_cut_off_limit', 32 * 1024)) raw_diff = cs.diff() diff_processor = DiffProcessor(raw_diff, diff_limit=diff_limit, @@ -92,7 +92,7 @@ class FeedController(BaseRepoController) desc_msg.append(h.urlify_text(cs.message)) desc_msg.append('\n') desc_msg.extend(changes) - if asbool(CONFIG.get('rss_include_diff', False)): + if asbool(kallithea.CONFIG.get('rss_include_diff', False)): desc_msg.append('\n\n') desc_msg.append(safe_str(raw_diff)) desc_msg.append('') @@ -109,7 +109,7 @@ class FeedController(BaseRepoController) description=_('Changes on %s repository') % repo_name, ) - rss_items_per_page = safe_int(CONFIG.get('rss_items_per_page', 20)) + rss_items_per_page = safe_int(kallithea.CONFIG.get('rss_items_per_page', 20)) entries=[] for cs in reversed(list(c.db_repo_scm_instance[-rss_items_per_page:])): entries.append(dict( diff --git a/kallithea/controllers/files.py b/kallithea/controllers/files.py --- a/kallithea/controllers/files.py +++ b/kallithea/controllers/files.py @@ -38,6 +38,7 @@ from tg import tmpl_context as c from tg.i18n import ugettext as _ from webob.exc import HTTPFound, HTTPNotFound +import kallithea from kallithea.config.routing import url from kallithea.lib import diffs from kallithea.lib import helpers as h @@ -504,13 +505,12 @@ class FilesController(BaseRepoController except (ImproperArchiveTypeError, KeyError): return _('Unknown archive type') - from kallithea import CONFIG rev_name = cs.raw_id[:12] archive_name = '%s-%s%s' % (repo_name.replace('/', '_'), rev_name, ext) archive_path = None cached_archive_path = None - archive_cache_dir = CONFIG.get('archive_cache_dir') + archive_cache_dir = kallithea.CONFIG.get('archive_cache_dir') if archive_cache_dir and not subrepos: # TODO: subrepo caching? if not os.path.isdir(archive_cache_dir): os.makedirs(archive_cache_dir) diff --git a/kallithea/lib/helpers.py b/kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py +++ b/kallithea/lib/helpers.py @@ -38,6 +38,7 @@ from webhelpers2.html.tags import submit from webhelpers2.number import format_byte_size from webhelpers2.text import chop_at, truncate, wrap_paragraphs +import kallithea from kallithea.config.routing import url from kallithea.lib.annotate import annotate_highlight #============================================================================== @@ -82,9 +83,8 @@ log = logging.getLogger(__name__) def canonical_url(*args, **kargs): '''Like url(x, qualified=True), but returns url that not only is qualified but also canonical, as configured in canonical_url''' - from kallithea import CONFIG try: - parts = CONFIG.get('canonical_url', '').split('://', 1) + parts = kallithea.CONFIG.get('canonical_url', '').split('://', 1) kargs['host'] = parts[1] kargs['protocol'] = parts[0] except IndexError: @@ -94,9 +94,8 @@ def canonical_url(*args, **kargs): def canonical_hostname(): '''Return canonical hostname of system''' - from kallithea import CONFIG try: - parts = CONFIG.get('canonical_url', '').split('://', 1) + parts = kallithea.CONFIG.get('canonical_url', '').split('://', 1) return parts[1].split('/', 1)[0] except IndexError: parts = url('home', qualified=True).split('://', 1) @@ -560,9 +559,8 @@ def show_id(cs): :param cs: changeset instance """ - from kallithea import CONFIG - def_len = safe_int(CONFIG.get('show_sha_length', 12)) - show_rev = asbool(CONFIG.get('show_revision_number', False)) + def_len = safe_int(kallithea.CONFIG.get('show_sha_length', 12)) + show_rev = asbool(kallithea.CONFIG.get('show_revision_number', False)) raw_id = cs.raw_id[:def_len] if show_rev: @@ -1212,25 +1210,24 @@ def urlify_issues(newtext, repo_name): """Urlify issue references according to .ini configuration""" global _urlify_issues_f if _urlify_issues_f is None: - from kallithea import CONFIG from kallithea.model.db import URL_SEP - assert CONFIG['sqlalchemy.url'] # make sure config has been loaded + assert kallithea.CONFIG['sqlalchemy.url'] # make sure config has been loaded # Build chain of urlify functions, starting with not doing any transformation def tmp_urlify_issues_f(s): return s issue_pat_re = re.compile(r'issue_pat(.*)') - for k in CONFIG: + for k in kallithea.CONFIG: # Find all issue_pat* settings that also have corresponding server_link and prefix configuration m = issue_pat_re.match(k) if m is None: continue suffix = m.group(1) - issue_pat = CONFIG.get(k) - issue_server_link = CONFIG.get('issue_server_link%s' % suffix) - issue_sub = CONFIG.get('issue_sub%s' % suffix) - issue_prefix = CONFIG.get('issue_prefix%s' % suffix) + issue_pat = kallithea.CONFIG.get(k) + issue_server_link = kallithea.CONFIG.get('issue_server_link%s' % suffix) + issue_sub = kallithea.CONFIG.get('issue_sub%s' % suffix) + issue_prefix = kallithea.CONFIG.get('issue_prefix%s' % suffix) if issue_prefix: log.error('found unsupported issue_prefix%s = %r - use issue_sub%s instead', suffix, issue_prefix, suffix) if not issue_pat: diff --git a/kallithea/tests/functional/test_search_indexing.py b/kallithea/tests/functional/test_search_indexing.py --- a/kallithea/tests/functional/test_search_indexing.py +++ b/kallithea/tests/functional/test_search_indexing.py @@ -1,6 +1,6 @@ import mock -from kallithea import CONFIG +import kallithea from kallithea.config.conf import INDEX_FILENAMES from kallithea.model.meta import Session from kallithea.model.repo import RepoModel @@ -66,7 +66,7 @@ def rebuild_index(full_index): # (FYI, ENOMEM occurs at forking "git" with python 2.7.3, # Linux 3.2.78-1 x86_64, 3GB memory, and no ulimit # configuration for memory) - create_test_index(base.TESTS_TMP_PATH, CONFIG, full_index=full_index) + create_test_index(base.TESTS_TMP_PATH, kallithea.CONFIG, full_index=full_index) class TestSearchControllerIndexing(base.TestController): diff --git a/kallithea/tests/other/test_vcs_operations.py b/kallithea/tests/other/test_vcs_operations.py --- a/kallithea/tests/other/test_vcs_operations.py +++ b/kallithea/tests/other/test_vcs_operations.py @@ -36,7 +36,7 @@ from tempfile import _RandomNameSequence import pytest -from kallithea import CONFIG +import kallithea from kallithea.lib.utils2 import ascii_bytes, safe_str from kallithea.model.db import Repository, Ui, User, UserIpMap, UserLog from kallithea.model.meta import Session @@ -101,7 +101,7 @@ class HgSshVcsTest(HgVcsTest, SshVcsTest # Specify a custom ssh command on the command line return r"""--config ui.ssh="bash -c 'SSH_ORIGINAL_COMMAND=\"\$2\" SSH_CONNECTION=\"%s 1024 127.0.0.1 22\" kallithea-cli ssh-serve -c %s %s %s' --" ssh://someuser@somehost/%s""" % ( client_ip, - CONFIG['__file__'], + kallithea.CONFIG['__file__'], user.user_id, ssh_key.user_ssh_key_id, repo_name) @@ -112,7 +112,7 @@ class GitSshVcsTest(GitVcsTest, SshVcsTe # Set a custom ssh command in the global environment os.environ['GIT_SSH_COMMAND'] = r"""bash -c 'SSH_ORIGINAL_COMMAND="$2" SSH_CONNECTION="%s 1024 127.0.0.1 22" kallithea-cli ssh-serve -c %s %s %s' --""" % ( client_ip, - CONFIG['__file__'], + kallithea.CONFIG['__file__'], user.user_id, ssh_key.user_ssh_key_id) return "ssh://someuser@somehost/%s""" % repo_name