# HG changeset patch # User Mads Kiilerich # Date 1602494809 -7200 # Node ID 6fbbbd9a627a98c065a3996143a3c260384e7dd4 # Parent 3afc6bff84bb82daa0a41e0d578279c7821dcdbe db: move URL_SEP constant from db to top level kallithea module URL_SEP is used in several places - having it in the db module is too high level. __init__ might not be the best place for this, but it does no harm to the dependencies graph to place constants there. diff -r 3afc6bff84bb -r 6fbbbd9a627a kallithea/__init__.py --- a/kallithea/__init__.py Sat Oct 10 20:04:51 2020 +0200 +++ b/kallithea/__init__.py Mon Oct 12 11:26:49 2020 +0200 @@ -45,6 +45,8 @@ CONFIG = {} +URL_SEP = '/' + # Linked module for extensions EXTENSIONS = {} diff -r 3afc6bff84bb -r 6fbbbd9a627a kallithea/controllers/files.py --- a/kallithea/controllers/files.py Sat Oct 10 20:04:51 2020 +0200 +++ b/kallithea/controllers/files.py Mon Oct 12 11:26:49 2020 +0200 @@ -52,7 +52,6 @@ from kallithea.lib.vcs.exceptions import (ChangesetDoesNotExistError, ChangesetError, EmptyRepositoryError, ImproperArchiveTypeError, NodeAlreadyExistsError, NodeDoesNotExistError, NodeError, RepositoryError, VCSError) from kallithea.lib.vcs.nodes import FileNode -from kallithea.model import db from kallithea.model.repo import RepoModel from kallithea.model.scm import ScmModel @@ -233,7 +232,7 @@ file_node = self.__get_filenode(cs, f_path) response.content_disposition = \ - 'attachment; filename=%s' % f_path.split(db.URL_SEP)[-1] + 'attachment; filename=%s' % f_path.split(kallithea.URL_SEP)[-1] response.content_type = file_node.mimetype return file_node.content diff -r 3afc6bff84bb -r 6fbbbd9a627a kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py Sat Oct 10 20:04:51 2020 +0200 +++ b/kallithea/lib/helpers.py Mon Oct 12 11:26:49 2020 +0200 @@ -57,7 +57,7 @@ #============================================================================== from kallithea.lib.vcs.utils import author_email, author_name from kallithea.model.changeset_status import ChangesetStatusModel -from kallithea.model.db import URL_SEP, ChangesetStatus, Permission, PullRequest, User, UserIpMap +from kallithea.model.db import ChangesetStatus, Permission, PullRequest, User, UserIpMap # mute pyflakes "imported but unused" @@ -1242,7 +1242,7 @@ log.error('invalid issue_url setting %r -> %r %r. Error: %s', issue_pat, issue_server_link, issue_sub, str(e)) issue_url = issue_server_link issue_url = issue_url.replace('{repo}', repo_name) - issue_url = issue_url.replace('{repo_name}', repo_name.split(URL_SEP)[-1]) + issue_url = issue_url.replace('{repo_name}', repo_name.split(kallithea.URL_SEP)[-1]) # if issue_sub is empty use the matched issue reference verbatim if not issue_sub: issue_text = match_obj.group() diff -r 3afc6bff84bb -r 6fbbbd9a627a kallithea/lib/utils.py --- a/kallithea/lib/utils.py Sat Oct 10 20:04:51 2020 +0200 +++ b/kallithea/lib/utils.py Mon Oct 12 11:26:49 2020 +0200 @@ -47,7 +47,7 @@ from kallithea.lib.vcs.exceptions import RepositoryError, VCSError from kallithea.lib.vcs.utils.fakemod import create_module from kallithea.lib.vcs.utils.helpers import get_scm -from kallithea.model import db, meta +from kallithea.model import meta from kallithea.model.db import RepoGroup, Repository, Setting, Ui, User, UserGroup, UserLog @@ -399,7 +399,7 @@ """ from kallithea.model.repo_group import RepoGroupModel sa = meta.Session() - groups = path.split(db.URL_SEP) + groups = path.split(kallithea.URL_SEP) parent = None group = None diff -r 3afc6bff84bb -r 6fbbbd9a627a kallithea/model/db.py --- a/kallithea/model/db.py Sat Oct 10 20:04:51 2020 +0200 +++ b/kallithea/model/db.py Mon Oct 12 11:26:49 2020 +0200 @@ -53,7 +53,6 @@ from kallithea.model.meta import Base, Session -URL_SEP = '/' log = logging.getLogger(__name__) #============================================================================== @@ -1025,7 +1024,7 @@ :param cls: :param repo_name: """ - return URL_SEP.join(repo_name.split(os.sep)) + return kallithea.URL_SEP.join(repo_name.split(os.sep)) @classmethod def guess_instance(cls, value): @@ -1051,7 +1050,7 @@ assert repo_full_path.startswith(base_full_path + os.path.sep) repo_name = repo_full_path[len(base_full_path) + 1:] repo_name = cls.normalize_repo_name(repo_name) - return cls.get_by_repo_name(repo_name.strip(URL_SEP)) + return cls.get_by_repo_name(repo_name.strip(kallithea.URL_SEP)) @classmethod def get_repo_forks(cls, repo_id): @@ -1073,7 +1072,7 @@ @property def just_name(self): - return self.repo_name.split(URL_SEP)[-1] + return self.repo_name.split(kallithea.URL_SEP)[-1] @property def groups_with_parents(self): @@ -1096,7 +1095,7 @@ # we need to split the name by / since this is how we store the # names in the database, but that eventually needs to be converted # into a valid system path - p += self.repo_name.split(URL_SEP) + p += self.repo_name.split(kallithea.URL_SEP) return os.path.join(*p) def get_new_name(self, repo_name): @@ -1106,7 +1105,7 @@ :param group_name: """ path_prefix = self.group.full_path_splitted if self.group else [] - return URL_SEP.join(path_prefix + [repo_name]) + return kallithea.URL_SEP.join(path_prefix + [repo_name]) @property def _ui(self): @@ -1445,7 +1444,7 @@ @property def name(self): - return self.group_name.split(URL_SEP)[-1] + return self.group_name.split(kallithea.URL_SEP)[-1] @property def full_path(self): @@ -1453,7 +1452,7 @@ @property def full_path_splitted(self): - return self.group_name.split(URL_SEP) + return self.group_name.split(kallithea.URL_SEP) @property def repositories(self): @@ -1508,7 +1507,7 @@ """ path_prefix = (self.parent_group.full_path_splitted if self.parent_group else []) - return URL_SEP.join(path_prefix + [group_name]) + return kallithea.URL_SEP.join(path_prefix + [group_name]) def get_api_data(self): """ diff -r 3afc6bff84bb -r 6fbbbd9a627a kallithea/model/repo.py --- a/kallithea/model/repo.py Sat Oct 10 20:04:51 2020 +0200 +++ b/kallithea/model/repo.py Mon Oct 12 11:26:49 2020 +0200 @@ -40,7 +40,7 @@ from kallithea.lib.utils import is_valid_repo_uri, make_ui from kallithea.lib.utils2 import LazyProperty, get_current_authuser, obfuscate_url_pw, remove_prefix from kallithea.lib.vcs.backends import get_backend -from kallithea.model.db import (URL_SEP, Permission, RepoGroup, Repository, RepositoryField, Session, Statistics, Ui, User, UserGroup, UserGroupRepoGroupToPerm, +from kallithea.model.db import (Permission, RepoGroup, Repository, RepositoryField, Session, Statistics, Ui, User, UserGroup, UserGroupRepoGroupToPerm, UserGroupRepoToPerm, UserRepoGroupToPerm, UserRepoToPerm) @@ -49,8 +49,6 @@ class RepoModel(object): - URL_SEPARATOR = URL_SEP - def _create_default_perms(self, repository, private): # create default permission default = 'repository.read' @@ -344,7 +342,7 @@ # while repo_name_full is a full qualified name that is combined # with name and path of group repo_name_full = repo_name - repo_name = repo_name.split(URL_SEP)[-1] + repo_name = repo_name.split(kallithea.URL_SEP)[-1] if kallithea.lib.utils2.repo_name_slug(repo_name) != repo_name: raise Exception('invalid repo name %s' % repo_name) diff -r 3afc6bff84bb -r 6fbbbd9a627a kallithea/model/repo_group.py --- a/kallithea/model/repo_group.py Sat Oct 10 20:04:51 2020 +0200 +++ b/kallithea/model/repo_group.py Mon Oct 12 11:26:49 2020 +0200 @@ -34,7 +34,6 @@ import kallithea.lib.utils2 from kallithea.lib.utils2 import LazyProperty -from kallithea.model import db from kallithea.model.db import Permission, RepoGroup, Repository, Session, Ui, User, UserGroup, UserGroupRepoGroupToPerm, UserRepoGroupToPerm @@ -116,7 +115,7 @@ :param group: instance of group from database :param force_delete: use shutil rmtree to remove all objects """ - paths = group.full_path.split(db.URL_SEP) + paths = group.full_path.split(kallithea.URL_SEP) paths = os.sep.join(paths) rm_path = os.path.join(self.repos_path, paths) diff -r 3afc6bff84bb -r 6fbbbd9a627a kallithea/model/validators.py --- a/kallithea/model/validators.py Sat Oct 10 20:04:51 2020 +0200 +++ b/kallithea/model/validators.py Mon Oct 12 11:26:49 2020 +0200 @@ -27,13 +27,13 @@ from sqlalchemy import func from tg.i18n import ugettext as _ +import kallithea from kallithea.config.routing import ADMIN_PREFIX from kallithea.lib.auth import HasPermissionAny, HasRepoGroupPermissionLevel from kallithea.lib.compat import OrderedSet from kallithea.lib.exceptions import InvalidCloneUriException, LdapImportError from kallithea.lib.utils import is_valid_repo_uri from kallithea.lib.utils2 import asbool, aslist, repo_name_slug -from kallithea.model import db from kallithea.model.db import RepoGroup, Repository, User, UserGroup @@ -326,7 +326,7 @@ # value needs to be aware of group name in order to check # db key This is an actual just the name to store in the # database - repo_name_full = group_path + db.URL_SEP + repo_name + repo_name_full = group_path + kallithea.URL_SEP + repo_name else: group_name = group_path = '' repo_name_full = repo_name diff -r 3afc6bff84bb -r 6fbbbd9a627a kallithea/tests/functional/test_admin_repos.py --- a/kallithea/tests/functional/test_admin_repos.py Sat Oct 10 20:04:51 2020 +0200 +++ b/kallithea/tests/functional/test_admin_repos.py Mon Oct 12 11:26:49 2020 +0200 @@ -6,8 +6,8 @@ import mock import pytest +import kallithea from kallithea.lib import vcs -from kallithea.model import db from kallithea.model.db import Permission, Repository, Ui, User, UserRepoToPerm from kallithea.model.meta import Session from kallithea.model.repo import RepoModel @@ -115,7 +115,7 @@ Session().commit() repo_name = 'ingroup' - repo_name_full = db.URL_SEP.join([group_name, repo_name]) + repo_name_full = kallithea.URL_SEP.join([group_name, repo_name]) description = 'description for newly created repo' response = self.app.post(base.url('repos'), fixture._get_repo_create_params(repo_private=False, @@ -192,7 +192,7 @@ Session().commit() repo_name = 'ingroup' - repo_name_full = db.URL_SEP.join([group_name, repo_name]) + repo_name_full = kallithea.URL_SEP.join([group_name, repo_name]) description = 'description for newly created repo' response = self.app.post(base.url('repos'), fixture._get_repo_create_params(repo_private=False, @@ -206,7 +206,7 @@ # user is allowed to create in this group repo_name = 'ingroup' - repo_name_full = db.URL_SEP.join([group_name_allowed, repo_name]) + repo_name_full = kallithea.URL_SEP.join([group_name_allowed, repo_name]) description = 'description for newly created repo' response = self.app.post(base.url('repos'), fixture._get_repo_create_params(repo_private=False, @@ -267,7 +267,7 @@ Session().commit() repo_name = 'ingroup_inherited_%s' % self.REPO_TYPE - repo_name_full = db.URL_SEP.join([group_name, repo_name]) + repo_name_full = kallithea.URL_SEP.join([group_name, repo_name]) description = 'description for newly created repo' response = self.app.post(base.url('repos'), fixture._get_repo_create_params(repo_private=False, diff -r 3afc6bff84bb -r 6fbbbd9a627a kallithea/tests/models/test_permissions.py --- a/kallithea/tests/models/test_permissions.py Sat Oct 10 20:04:51 2020 +0200 +++ b/kallithea/tests/models/test_permissions.py Mon Oct 12 11:26:49 2020 +0200 @@ -1,5 +1,5 @@ +import kallithea from kallithea.lib.auth import AuthUser -from kallithea.model import db from kallithea.model.db import Permission, User, UserGroupRepoGroupToPerm, UserToPerm from kallithea.model.meta import Session from kallithea.model.permission import PermissionModel @@ -193,7 +193,7 @@ assert a1_auth.repository_group_permissions.get('group2') == 'group.none' # add repo to group - name = db.URL_SEP.join([self.g1.group_name, 'test_perm']) + name = kallithea.URL_SEP.join([self.g1.group_name, 'test_perm']) self.test_repo = fixture.create_repo(name=name, repo_type='hg', repo_group=self.g1, diff -r 3afc6bff84bb -r 6fbbbd9a627a kallithea/tests/models/test_repo_groups.py --- a/kallithea/tests/models/test_repo_groups.py Sat Oct 10 20:04:51 2020 +0200 +++ b/kallithea/tests/models/test_repo_groups.py Mon Oct 12 11:26:49 2020 +0200 @@ -3,7 +3,7 @@ import pytest from sqlalchemy.exc import IntegrityError -from kallithea.model import db +import kallithea from kallithea.model.db import RepoGroup from kallithea.model.meta import Session from kallithea.model.repo import RepoModel @@ -133,7 +133,7 @@ assert self.__check_path('g2', 'g1') # test repo - assert r.repo_name == db.URL_SEP.join(['g2', 'g1', r.just_name]) + assert r.repo_name == kallithea.URL_SEP.join(['g2', 'g1', r.just_name]) def test_move_to_root(self): g1 = fixture.create_repo_group('t11')