changeset 8329:6484a0fc0e0b

db: drop url_sep() function that just returns a constant "/"
author Mads Kiilerich <mads@kiilerich.com>
date Mon, 30 Mar 2020 13:17:18 +0200
parents fae2108f65e5
children eabd5a2fd0af
files kallithea/controllers/files.py kallithea/lib/utils.py kallithea/model/db.py kallithea/model/repo.py kallithea/model/repo_group.py kallithea/model/validators.py kallithea/tests/functional/test_admin_repos.py kallithea/tests/models/test_permissions.py kallithea/tests/models/test_repo_groups.py
diffstat 9 files changed, 31 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/files.py	Mon Mar 30 14:52:01 2020 +0200
+++ b/kallithea/controllers/files.py	Mon Mar 30 13:17:18 2020 +0200
@@ -52,7 +52,7 @@
 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 @@
         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
--- a/kallithea/lib/utils.py	Mon Mar 30 14:52:01 2020 +0200
+++ b/kallithea/lib/utils.py	Mon Mar 30 13:17:18 2020 +0200
@@ -48,7 +48,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 meta
+from kallithea.model import db, meta
 from kallithea.model.db import RepoGroup, Repository, Setting, Ui, User, UserGroup, UserLog
 
 
@@ -407,7 +407,7 @@
     """
     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
 
--- a/kallithea/model/db.py	Mon Mar 30 14:52:01 2020 +0200
+++ b/kallithea/model/db.py	Mon Mar 30 13:17:18 2020 +0200
@@ -1057,10 +1057,6 @@
         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 @@
         :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 @@
         :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 @@
 
     @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 @@
         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 @@
         # 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 @@
         :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 @@
                       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 @@
 
     @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 @@
 
     @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 @@
         """
         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):
         """
--- a/kallithea/model/repo.py	Mon Mar 30 14:52:01 2020 +0200
+++ b/kallithea/model/repo.py	Mon Mar 30 13:17:18 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 (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 @@
 
 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 @@
             # 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)
 
--- a/kallithea/model/repo_group.py	Mon Mar 30 14:52:01 2020 +0200
+++ b/kallithea/model/repo_group.py	Mon Mar 30 13:17:18 2020 +0200
@@ -34,6 +34,7 @@
 
 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 @@
         :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)
--- a/kallithea/model/validators.py	Mon Mar 30 14:52:01 2020 +0200
+++ b/kallithea/model/validators.py	Mon Mar 30 13:17:18 2020 +0200
@@ -33,6 +33,7 @@
 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 @@
                 # 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
--- a/kallithea/tests/functional/test_admin_repos.py	Mon Mar 30 14:52:01 2020 +0200
+++ b/kallithea/tests/functional/test_admin_repos.py	Mon Mar 30 13:17:18 2020 +0200
@@ -7,7 +7,8 @@
 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 @@
         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 @@
         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 @@
 
         # 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 @@
         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,
--- a/kallithea/tests/models/test_permissions.py	Mon Mar 30 14:52:01 2020 +0200
+++ b/kallithea/tests/models/test_permissions.py	Mon Mar 30 13:17:18 2020 +0200
@@ -1,5 +1,6 @@
 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 @@
         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,
--- a/kallithea/tests/models/test_repo_groups.py	Mon Mar 30 14:52:01 2020 +0200
+++ b/kallithea/tests/models/test_repo_groups.py	Mon Mar 30 13:17:18 2020 +0200
@@ -3,6 +3,7 @@
 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 @@
         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')