Mercurial > kallithea
changeset 8726:905cab5f971d
model: move Gist constants to db - avoid importing models into db
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Fri, 30 Oct 2020 02:14:04 +0100 |
parents | 6a9e5841cc51 |
children | c98c7d4c9ec3 |
files | kallithea/model/db.py kallithea/model/gist.py |
diffstat | 2 files changed, 10 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/model/db.py Thu Oct 29 11:28:36 2020 +0100 +++ b/kallithea/model/db.py Fri Oct 30 02:14:04 2020 +0100 @@ -47,7 +47,7 @@ from kallithea.lib import ext_json, ssh, webutils from kallithea.lib.exceptions import DefaultUserException from kallithea.lib.utils2 import asbool, ascii_bytes, aslist, get_changeset_safe, get_clone_url, remove_prefix, safe_bytes, safe_int, safe_str, urlreadable -from kallithea.lib.vcs import get_backend +from kallithea.lib.vcs import get_backend, get_repo from kallithea.lib.vcs.backends.base import EmptyChangeset from kallithea.lib.vcs.utils import author_email, author_name from kallithea.lib.vcs.utils.helpers import get_scm @@ -2189,6 +2189,9 @@ _table_args_default_dict, ) + GIST_STORE_LOC = '.rc_gist_store' + GIST_METADATA_FILE = '.rc_gist_metadata' + GIST_PUBLIC = 'public' GIST_PRIVATE = 'private' DEFAULT_FILENAME = 'gistfile1.txt' @@ -2261,9 +2264,7 @@ @property def scm_instance(self): - from kallithea.lib.vcs import get_repo - from kallithea.model.gist import GIST_STORE_LOC - gist_base_path = os.path.join(kallithea.CONFIG['base_path'], GIST_STORE_LOC) + gist_base_path = os.path.join(kallithea.CONFIG['base_path'], self.GIST_STORE_LOC) return get_repo(os.path.join(gist_base_path, self.gist_access_id))
--- a/kallithea/model/gist.py Thu Oct 29 11:28:36 2020 +0100 +++ b/kallithea/model/gist.py Fri Oct 30 02:14:04 2020 +0100 @@ -41,9 +41,6 @@ log = logging.getLogger(__name__) -GIST_STORE_LOC = '.rc_gist_store' -GIST_METADATA_FILE = '.rc_gist_metadata' - def make_gist_access_id(): """Generate a random, URL safe, almost certainly unique gist identifier.""" @@ -62,7 +59,7 @@ :param gist: gist object """ root_path = RepoModel().repos_path - rm_path = os.path.join(root_path, GIST_STORE_LOC, gist.gist_access_id) + rm_path = os.path.join(root_path, db.Gist.GIST_STORE_LOC, gist.gist_access_id) log.info("Removing %s", rm_path) shutil.rmtree(rm_path) @@ -81,7 +78,7 @@ 'gist_expires': gist_expires, 'gist_updated': time.time(), } - with open(os.path.join(repo.path, '.hg', GIST_METADATA_FILE), 'wb') as f: + with open(os.path.join(repo.path, '.hg', db.Gist.GIST_METADATA_FILE), 'wb') as f: f.write(ascii_bytes(ext_json.dumps(metadata))) def get_gist(self, gist): @@ -129,7 +126,7 @@ log.debug('Creating new %s GIST repo %s', gist_type, gist.gist_access_id) repo = RepoModel()._create_filesystem_repo( - repo_name=gist.gist_access_id, repo_type='hg', repo_group=GIST_STORE_LOC) + repo_name=gist.gist_access_id, repo_type='hg', repo_group=db.Gist.GIST_STORE_LOC) processed_mapping = {} for filename in gist_mapping: @@ -153,7 +150,7 @@ # fake Kallithea Repository object fake_repo = AttributeDict(dict( - repo_name=os.path.join(GIST_STORE_LOC, gist.gist_access_id), + repo_name=os.path.join(db.Gist.GIST_STORE_LOC, gist.gist_access_id), scm_instance_no_cache=lambda: repo, )) ScmModel().create_nodes( @@ -217,7 +214,7 @@ # fake Kallithea Repository object fake_repo = AttributeDict(dict( - repo_name=os.path.join(GIST_STORE_LOC, gist.gist_access_id), + repo_name=os.path.join(db.Gist.GIST_STORE_LOC, gist.gist_access_id), scm_instance_no_cache=lambda: gist_repo, ))