Changeset - 6484a0fc0e0b
[Not reviewed]
default
0 9 0
Mads Kiilerich - 6 years ago 2020-03-30 13:17:18
mads@kiilerich.com
db: drop url_sep() function that just returns a constant "/"
9 files changed with 31 insertions and 36 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/files.py
Show inline comments
 
@@ -52,7 +52,7 @@ 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.db import Repository
 
from kallithea.model import db
 
from kallithea.model.repo import RepoModel
 
from kallithea.model.scm import ScmModel
 

	
 
@@ -233,7 +233,7 @@ class FilesController(BaseRepoController
 
        file_node = self.__get_filenode(cs, f_path)
 

	
 
        response.content_disposition = \
 
            'attachment; filename=%s' % f_path.split(Repository.url_sep())[-1]
 
            'attachment; filename=%s' % f_path.split(db.URL_SEP)[-1]
 

	
 
        response.content_type = file_node.mimetype
 
        return file_node.content
kallithea/lib/utils.py
Show inline comments
 
@@ -48,7 +48,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 meta
 
from kallithea.model import db, meta
 
from kallithea.model.db import RepoGroup, Repository, Setting, Ui, User, UserGroup, UserLog
 

	
 

	
 
@@ -407,7 +407,7 @@ def map_groups(path):
 
    """
 
    from kallithea.model.repo_group import RepoGroupModel
 
    sa = meta.Session()
 
    groups = path.split(Repository.url_sep())
 
    groups = path.split(db.URL_SEP)
 
    parent = None
 
    group = None
 

	
kallithea/model/db.py
Show inline comments
 
@@ -1057,10 +1057,6 @@ class Repository(Base, BaseDbModel):
 
        return q
 

	
 
    @classmethod
 
    def url_sep(cls):
 
        return URL_SEP
 

	
 
    @classmethod
 
    def normalize_repo_name(cls, repo_name):
 
        """
 
        Normalizes os specific repo_name to the format internally stored inside
 
@@ -1069,7 +1065,7 @@ class Repository(Base, BaseDbModel):
 
        :param cls:
 
        :param repo_name:
 
        """
 
        return cls.url_sep().join(repo_name.split(os.sep))
 
        return URL_SEP.join(repo_name.split(os.sep))
 

	
 
    @classmethod
 
    def guess_instance(cls, value):
 
@@ -1109,7 +1105,7 @@ class Repository(Base, BaseDbModel):
 
        :param cls:
 
        """
 
        q = Session().query(Ui) \
 
            .filter(Ui.ui_key == cls.url_sep())
 
            .filter(Ui.ui_key == URL_SEP)
 
        q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
 
        return q.one().ui_value
 

	
 
@@ -1129,7 +1125,7 @@ class Repository(Base, BaseDbModel):
 

	
 
    @property
 
    def just_name(self):
 
        return self.repo_name.split(Repository.url_sep())[-1]
 
        return self.repo_name.split(URL_SEP)[-1]
 

	
 
    @property
 
    def groups_with_parents(self):
 
@@ -1148,8 +1144,7 @@ class Repository(Base, BaseDbModel):
 
        Returns base full path for that repository means where it actually
 
        exists on a filesystem
 
        """
 
        q = Session().query(Ui).filter(Ui.ui_key ==
 
                                              Repository.url_sep())
 
        q = Session().query(Ui).filter(Ui.ui_key == URL_SEP)
 
        q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
 
        return q.one().ui_value
 

	
 
@@ -1159,7 +1154,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(Repository.url_sep())
 
        p += self.repo_name.split(URL_SEP)
 
        return os.path.join(*p)
 

	
 
    @property
 
@@ -1179,7 +1174,7 @@ class Repository(Base, BaseDbModel):
 
        :param group_name:
 
        """
 
        path_prefix = self.group.full_path_splitted if self.group else []
 
        return Repository.url_sep().join(path_prefix + [repo_name])
 
        return URL_SEP.join(path_prefix + [repo_name])
 

	
 
    @property
 
    def _ui(self):
 
@@ -1500,10 +1495,6 @@ class RepoGroup(Base, BaseDbModel):
 
                      key=lambda c: c[1].split(cls.SEP))
 

	
 
    @classmethod
 
    def url_sep(cls):
 
        return URL_SEP
 

	
 
    @classmethod
 
    def guess_instance(cls, value):
 
        return super(RepoGroup, cls).guess_instance(value, RepoGroup.get_by_group_name)
 

	
 
@@ -1541,7 +1532,7 @@ class RepoGroup(Base, BaseDbModel):
 

	
 
    @property
 
    def name(self):
 
        return self.group_name.split(RepoGroup.url_sep())[-1]
 
        return self.group_name.split(URL_SEP)[-1]
 

	
 
    @property
 
    def full_path(self):
 
@@ -1549,7 +1540,7 @@ class RepoGroup(Base, BaseDbModel):
 

	
 
    @property
 
    def full_path_splitted(self):
 
        return self.group_name.split(RepoGroup.url_sep())
 
        return self.group_name.split(URL_SEP)
 

	
 
    @property
 
    def repositories(self):
 
@@ -1604,7 +1595,7 @@ class RepoGroup(Base, BaseDbModel):
 
        """
 
        path_prefix = (self.parent_group.full_path_splitted if
 
                       self.parent_group else [])
 
        return RepoGroup.url_sep().join(path_prefix + [group_name])
 
        return 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 (Permission, RepoGroup, Repository, RepositoryField, Session, Statistics, Ui, User, UserGroup, UserGroupRepoGroupToPerm,
 
from kallithea.model.db import (URL_SEP, Permission, RepoGroup, Repository, RepositoryField, Session, Statistics, Ui, User, UserGroup, UserGroupRepoGroupToPerm,
 
                                UserGroupRepoToPerm, UserRepoGroupToPerm, UserRepoToPerm)
 

	
 

	
 
@@ -49,7 +49,7 @@ log = logging.getLogger(__name__)
 

	
 
class RepoModel(object):
 

	
 
    URL_SEPARATOR = Repository.url_sep()
 
    URL_SEPARATOR = URL_SEP
 

	
 
    def _create_default_perms(self, repository, private):
 
        # create default permission
 
@@ -343,7 +343,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(self.URL_SEPARATOR)[-1]
 
            repo_name = repo_name.split(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,6 +34,7 @@ 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
 

	
 

	
 
@@ -115,7 +116,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(RepoGroup.url_sep())
 
        paths = group.full_path.split(db.URL_SEP)
 
        paths = os.sep.join(paths)
 

	
 
        rm_path = os.path.join(self.repos_path, paths)
kallithea/model/validators.py
Show inline comments
 
@@ -33,6 +33,7 @@ from kallithea.lib.compat import Ordered
 
from kallithea.lib.exceptions import InvalidCloneUriException, LdapImportError
 
from kallithea.lib.utils import is_valid_repo_uri
 
from kallithea.lib.utils2 import aslist, repo_name_slug, str2bool
 
from kallithea.model import db
 
from kallithea.model.db import RepoGroup, Repository, User, UserGroup
 

	
 

	
 
@@ -325,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 + RepoGroup.url_sep() + repo_name
 
                repo_name_full = group_path + db.URL_SEP + repo_name
 
            else:
 
                group_name = group_path = ''
 
                repo_name_full = repo_name
kallithea/tests/functional/test_admin_repos.py
Show inline comments
 
@@ -7,7 +7,8 @@ import mock
 
import pytest
 

	
 
from kallithea.lib import vcs
 
from kallithea.model.db import Permission, RepoGroup, Repository, Ui, User, UserRepoToPerm
 
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
 
from kallithea.model.repo_group import RepoGroupModel
 
@@ -114,7 +115,7 @@ class _BaseTestCase(base.TestController)
 
        Session().commit()
 

	
 
        repo_name = 'ingroup'
 
        repo_name_full = RepoGroup.url_sep().join([group_name, repo_name])
 
        repo_name_full = db.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,
 
@@ -191,7 +192,7 @@ class _BaseTestCase(base.TestController)
 
        Session().commit()
 

	
 
        repo_name = 'ingroup'
 
        repo_name_full = RepoGroup.url_sep().join([group_name, repo_name])
 
        repo_name_full = db.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,
 
@@ -205,7 +206,7 @@ class _BaseTestCase(base.TestController)
 

	
 
        # user is allowed to create in this group
 
        repo_name = 'ingroup'
 
        repo_name_full = RepoGroup.url_sep().join([group_name_allowed, repo_name])
 
        repo_name_full = db.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,
 
@@ -266,7 +267,7 @@ class _BaseTestCase(base.TestController)
 
        Session().commit()
 

	
 
        repo_name = 'ingroup_inherited_%s' % self.REPO_TYPE
 
        repo_name_full = RepoGroup.url_sep().join([group_name, repo_name])
 
        repo_name_full = db.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
 
from kallithea.lib.auth import AuthUser
 
from kallithea.model.db import Permission, RepoGroup, User, UserGroupRepoGroupToPerm, UserToPerm
 
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
 
from kallithea.model.repo import RepoModel
 
@@ -222,7 +223,7 @@ class TestPermissions(base.TestControlle
 
        assert a1_auth.permissions['repositories_groups'] == {'group1': 'group.none', 'group2': 'group.none'}
 

	
 
        # add repo to group
 
        name = RepoGroup.url_sep().join([self.g1.group_name, 'test_perm'])
 
        name = db.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,6 +3,7 @@ import os
 
import pytest
 
from sqlalchemy.exc import IntegrityError
 

	
 
from kallithea.model import db
 
from kallithea.model.db import RepoGroup
 
from kallithea.model.meta import Session
 
from kallithea.model.repo import RepoModel
 
@@ -132,8 +133,7 @@ class TestRepoGroups(base.TestController
 
        assert self.__check_path('g2', 'g1')
 

	
 
        # test repo
 
        assert r.repo_name == RepoGroup.url_sep().join(['g2', 'g1',
 
                                                                r.just_name])
 
        assert r.repo_name == db.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)