Changeset - 6fbbbd9a627a
[Not reviewed]
default
0 11 0
Mads Kiilerich (mads) - 5 years ago 2020-10-12 11:26:49
mads@kiilerich.com
Grafted from: 1aebb614b3a4
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.
11 files changed with 29 insertions and 32 deletions:
0 comments (0 inline, 0 general)
kallithea/__init__.py
Show inline comments
 
@@ -45,6 +45,8 @@ CELERY_EAGER = False
 

	
 
CONFIG = {}
 

	
 
URL_SEP = '/'
 

	
 
# Linked module for extensions
 
EXTENSIONS = {}
 

	
kallithea/controllers/files.py
Show inline comments
 
@@ -52,7 +52,6 @@ from kallithea.lib.vcs.conf import setti
 
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 @@ class FilesController(BaseRepoController
 
        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
kallithea/lib/helpers.py
Show inline comments
 
@@ -57,7 +57,7 @@ from kallithea.lib.vcs.exceptions import
 
#==============================================================================
 
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 @@ def urlify_issues(newtext, repo_name):
 
                    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()
kallithea/lib/utils.py
Show inline comments
 
@@ -47,7 +47,7 @@ from kallithea.lib.vcs.conf import setti
 
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 @@ def map_groups(path):
 
    """
 
    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
 

	
kallithea/model/db.py
Show inline comments
 
@@ -53,7 +53,6 @@ from kallithea.lib.vcs.utils.helpers imp
 
from kallithea.model.meta import Base, Session
 

	
 

	
 
URL_SEP = '/'
 
log = logging.getLogger(__name__)
 

	
 
#==============================================================================
 
@@ -1025,7 +1024,7 @@ class Repository(Base, BaseDbModel):
 
        :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 @@ class Repository(Base, BaseDbModel):
 
        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 @@ class Repository(Base, BaseDbModel):
 

	
 
    @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 @@ class Repository(Base, BaseDbModel):
 
        # 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 @@ class Repository(Base, BaseDbModel):
 
        :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 @@ class RepoGroup(Base, BaseDbModel):
 

	
 
    @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 @@ class RepoGroup(Base, BaseDbModel):
 

	
 
    @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 @@ class RepoGroup(Base, BaseDbModel):
 
        """
 
        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):
 
        """
kallithea/model/repo.py
Show inline comments
 
@@ -40,7 +40,7 @@ from kallithea.lib.hooks import log_dele
 
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 @@ log = logging.getLogger(__name__)
 

	
 
class RepoModel(object):
 

	
 
    URL_SEPARATOR = URL_SEP
 

	
 
    def _create_default_perms(self, repository, private):
 
        # create default permission
 
        default = 'repository.read'
 
@@ -344,7 +342,7 @@ class RepoModel(object):
 
            # 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)
 

	
kallithea/model/repo_group.py
Show inline comments
 
@@ -34,7 +34,6 @@ import traceback
 

	
 
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 @@ class RepoGroupModel(object):
 
        :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)
kallithea/model/validators.py
Show inline comments
 
@@ -27,13 +27,13 @@ from formencode.validators import CIDR, 
 
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 @@ def ValidRepoName(edit=False, old_data=N
 
                # 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
kallithea/tests/functional/test_admin_repos.py
Show inline comments
 
@@ -6,8 +6,8 @@ import urllib.parse
 
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 @@ class _BaseTestCase(base.TestController)
 
        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 @@ class _BaseTestCase(base.TestController)
 
        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 @@ class _BaseTestCase(base.TestController)
 

	
 
        # 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 @@ class _BaseTestCase(base.TestController)
 
        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,
kallithea/tests/models/test_permissions.py
Show inline comments
 
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 @@ class TestPermissions(base.TestControlle
 
        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,
kallithea/tests/models/test_repo_groups.py
Show inline comments
 
@@ -3,7 +3,7 @@ import os
 
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 @@ class TestRepoGroups(base.TestController
 
        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')
0 comments (0 inline, 0 general)