Mercurial > kallithea
changeset 5997:b313d735d9c8
cleanup: get rid of jn as shortcut for os.path.join
It is not used in that many places so it is better to be explicit and use os.path.join .
Discussed on https://bitbucket.org/domruf/kallithea/commits/1da05f42bca3f7042c444fda13a1ae1f6b9c300f#comment-2948124 .
Modified by Mads Kiilerich.
author | domruf <dominikruf@gmail.com> |
---|---|
date | Sun, 12 Jun 2016 21:21:43 +0200 |
parents | d6b3839f3c83 |
children | 037efd94e955 |
files | kallithea/lib/celerylib/__init__.py kallithea/lib/celerylib/tasks.py kallithea/lib/db_manage.py kallithea/lib/indexers/__init__.py kallithea/lib/indexers/daemon.py kallithea/lib/utils.py kallithea/model/scm.py kallithea/tests/__init__.py kallithea/tests/other/manual_test_vcs_operations.py kallithea/tests/scripts/manual_test_concurrency.py kallithea/tests/scripts/manual_test_crawler.py kallithea/tests/vcs/conf.py |
diffstat | 12 files changed, 50 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/celerylib/__init__.py Wed Jun 29 16:53:53 2016 +0200 +++ b/kallithea/lib/celerylib/__init__.py Sun Jun 12 21:21:43 2016 +0200 @@ -26,10 +26,11 @@ """ +import os import socket import traceback import logging -from os.path import join as jn + from pylons import config from hashlib import md5 @@ -98,7 +99,7 @@ log.info('running task with lockkey %s', lockkey) try: - l = DaemonLock(file_=jn(lockkey_path, lockkey)) + l = DaemonLock(file_=os.path.join(lockkey_path, lockkey)) ret = func(*fargs, **fkwargs) l.release() return ret
--- a/kallithea/lib/celerylib/tasks.py Wed Jun 29 16:53:53 2016 +0200 +++ b/kallithea/lib/celerylib/tasks.py Sun Jun 12 21:21:43 2016 +0200 @@ -32,7 +32,6 @@ import traceback import logging import rfc822 -from os.path import join as jn from time import mktime from operator import itemgetter @@ -92,7 +91,7 @@ log.info('running task with lockkey %s', lockkey) try: - lock = l = DaemonLock(file_=jn(lockkey_path, lockkey)) + lock = l = DaemonLock(file_=os.path.join(lockkey_path, lockkey)) # for js data compatibility cleans the key for person from ' akc = lambda k: person(k).replace('"', "")
--- a/kallithea/lib/db_manage.py Wed Jun 29 16:53:53 2016 +0200 +++ b/kallithea/lib/db_manage.py Sun Jun 12 21:21:43 2016 +0200 @@ -31,7 +31,7 @@ import time import uuid import logging -from os.path import dirname as dn, join as jn +from os.path import dirname as dn from kallithea import __dbversion__, __py_version__, EXTERN_TYPE_INTERNAL, DB_MIGRATIONS from kallithea.model.user import UserModel @@ -138,8 +138,8 @@ print 'No upgrade performed' sys.exit(0) - repository_path = jn(dn(dn(dn(os.path.realpath(__file__)))), - 'kallithea/lib/dbmigrate') + repository_path = os.path.join(dn(dn(dn(os.path.realpath(__file__)))), + 'kallithea', 'lib', 'dbmigrate') db_uri = self.dburi try:
--- a/kallithea/lib/indexers/__init__.py Wed Jun 29 16:53:53 2016 +0200 +++ b/kallithea/lib/indexers/__init__.py Sun Jun 12 21:21:43 2016 +0200 @@ -28,7 +28,7 @@ import os import sys import logging -from os.path import dirname as dn, join as jn +from os.path import dirname as dn # Add location of top level folder to sys.path sys.path.append(dn(dn(dn(os.path.realpath(__file__))))) @@ -140,7 +140,7 @@ res = self.searcher.stored_fields(docid[0]) log.debug('result: %s', res) if self.search_type == 'content': - full_repo_path = jn(self.repo_location, res['repository']) + full_repo_path = os.path.join(self.repo_location, res['repository']) f_path = res['path'].split(full_repo_path)[-1] f_path = f_path.lstrip(os.sep) content_short = self.get_short_content(res, docid[1]) @@ -149,7 +149,7 @@ 'f_path': f_path }) elif self.search_type == 'path': - full_repo_path = jn(self.repo_location, res['repository']) + full_repo_path = os.path.join(self.repo_location, res['repository']) f_path = res['path'].split(full_repo_path)[-1] f_path = f_path.lstrip(os.sep) res.update({'f_path': f_path})
--- a/kallithea/lib/indexers/daemon.py Wed Jun 29 16:53:53 2016 +0200 +++ b/kallithea/lib/indexers/daemon.py Sun Jun 12 21:21:43 2016 +0200 @@ -35,7 +35,6 @@ from time import mktime from os.path import dirname as dn -from os.path import join as jn # Add location of top level folder to sys.path project_path = dn(dn(dn(dn(os.path.realpath(__file__))))) @@ -136,7 +135,7 @@ cs = self._get_index_changeset(repo) for _topnode, _dirs, files in cs.walk('/'): for f in files: - index_paths_.add(jn(safe_str(repo.path), safe_str(f.path))) + index_paths_.add(os.path.join(safe_str(repo.path), safe_str(f.path))) except RepositoryError: log.debug(traceback.format_exc())
--- a/kallithea/lib/utils.py Wed Jun 29 16:53:53 2016 +0200 +++ b/kallithea/lib/utils.py Sun Jun 12 21:21:43 2016 +0200 @@ -37,7 +37,7 @@ import decorator import warnings from os.path import abspath -from os.path import dirname as dn, join as jn +from os.path import dirname as dn from paste.script.command import Command, BadCommand @@ -653,7 +653,7 @@ os.makedirs(index_location) try: - l = DaemonLock(file_=jn(dn(index_location), 'make_index.lock')) + l = DaemonLock(file_=os.path.join(dn(index_location), 'make_index.lock')) WhooshIndexingDaemon(index_location=index_location, repo_location=repo_location) \ .run(full_index=full_index) @@ -706,13 +706,13 @@ #CREATE DEFAULT TEST REPOS cur_dir = dn(dn(abspath(__file__))) - tar = tarfile.open(jn(cur_dir, 'tests', 'fixtures', "vcs_test_hg.tar.gz")) - tar.extractall(jn(TESTS_TMP_PATH, HG_REPO)) + tar = tarfile.open(os.path.join(cur_dir, 'tests', 'fixtures', "vcs_test_hg.tar.gz")) + tar.extractall(os.path.join(TESTS_TMP_PATH, HG_REPO)) tar.close() cur_dir = dn(dn(abspath(__file__))) - tar = tarfile.open(jn(cur_dir, 'tests', 'fixtures', "vcs_test_git.tar.gz")) - tar.extractall(jn(TESTS_TMP_PATH, GIT_REPO)) + tar = tarfile.open(os.path.join(cur_dir, 'tests', 'fixtures', "vcs_test_git.tar.gz")) + tar.extractall(os.path.join(TESTS_TMP_PATH, GIT_REPO)) tar.close() #LOAD VCS test stuff
--- a/kallithea/model/scm.py Wed Jun 29 16:53:53 2016 +0200 +++ b/kallithea/model/scm.py Sun Jun 12 21:21:43 2016 +0200 @@ -34,7 +34,6 @@ import logging import cStringIO import pkg_resources -from os.path import join as jn from sqlalchemy import func from pylons.i18n.translation import _ @@ -739,23 +738,23 @@ :param force_create: Create even if same name hook exists """ - loc = jn(repo.path, 'hooks') + loc = os.path.join(repo.path, 'hooks') if not repo.bare: - loc = jn(repo.path, '.git', 'hooks') + loc = os.path.join(repo.path, '.git', 'hooks') if not os.path.isdir(loc): os.makedirs(loc) tmpl_post = "#!/usr/bin/env %s\n" % sys.executable or 'python2' tmpl_post += pkg_resources.resource_string( - 'kallithea', jn('config', 'post_receive_tmpl.py') + 'kallithea', os.path.join('config', 'post_receive_tmpl.py') ) tmpl_pre = "#!/usr/bin/env %s\n" % sys.executable or 'python2' tmpl_pre += pkg_resources.resource_string( - 'kallithea', jn('config', 'pre_receive_tmpl.py') + 'kallithea', os.path.join('config', 'pre_receive_tmpl.py') ) for h_type, tmpl in [('pre', tmpl_pre), ('post', tmpl_post)]: - _hook_file = jn(loc, '%s-receive' % h_type) + _hook_file = os.path.join(loc, '%s-receive' % h_type) has_hook = False log.debug('Installing git hook in repo %s', repo) if os.path.exists(_hook_file):
--- a/kallithea/tests/__init__.py Wed Jun 29 16:53:53 2016 +0200 +++ b/kallithea/tests/__init__.py Sun Jun 12 21:21:43 2016 +0200 @@ -29,7 +29,6 @@ import datetime import hashlib import tempfile -from os.path import join as jn from tempfile import _RandomNameSequence @@ -79,7 +78,7 @@ #SOME GLOBALS FOR TESTS -TESTS_TMP_PATH = jn(tempfile.gettempdir(), 'rc_test_%s' % _RandomNameSequence().next()) +TESTS_TMP_PATH = os.path.join(tempfile.gettempdir(), 'rc_test_%s' % _RandomNameSequence().next()) TEST_USER_ADMIN_LOGIN = 'test_admin' TEST_USER_ADMIN_PASS = 'test12' TEST_USER_ADMIN_EMAIL = 'test_admin@example.com' @@ -107,24 +106,24 @@ GIT_REMOTE_REPO = 'git://github.com/codeinn/vcs.git' -TEST_GIT_REPO = jn(TESTS_TMP_PATH, GIT_REPO) -TEST_GIT_REPO_CLONE = jn(TESTS_TMP_PATH, 'vcsgitclone%s' % uniq_suffix) -TEST_GIT_REPO_PULL = jn(TESTS_TMP_PATH, 'vcsgitpull%s' % uniq_suffix) +TEST_GIT_REPO = os.path.join(TESTS_TMP_PATH, GIT_REPO) +TEST_GIT_REPO_CLONE = os.path.join(TESTS_TMP_PATH, 'vcsgitclone%s' % uniq_suffix) +TEST_GIT_REPO_PULL = os.path.join(TESTS_TMP_PATH, 'vcsgitpull%s' % uniq_suffix) HG_REMOTE_REPO = 'http://bitbucket.org/marcinkuzminski/vcs' -TEST_HG_REPO = jn(TESTS_TMP_PATH, HG_REPO) -TEST_HG_REPO_CLONE = jn(TESTS_TMP_PATH, 'vcshgclone%s' % uniq_suffix) -TEST_HG_REPO_PULL = jn(TESTS_TMP_PATH, 'vcshgpull%s' % uniq_suffix) +TEST_HG_REPO = os.path.join(TESTS_TMP_PATH, HG_REPO) +TEST_HG_REPO_CLONE = os.path.join(TESTS_TMP_PATH, 'vcshgclone%s' % uniq_suffix) +TEST_HG_REPO_PULL = os.path.join(TESTS_TMP_PATH, 'vcshgpull%s' % uniq_suffix) TEST_DIR = tempfile.gettempdir() TEST_REPO_PREFIX = 'vcs-test' # cached repos if any ! # comment out to get some other repos from bb or github -GIT_REMOTE_REPO = jn(TESTS_TMP_PATH, GIT_REPO) -HG_REMOTE_REPO = jn(TESTS_TMP_PATH, HG_REPO) +GIT_REMOTE_REPO = os.path.join(TESTS_TMP_PATH, GIT_REPO) +HG_REMOTE_REPO = os.path.join(TESTS_TMP_PATH, HG_REPO) #skip ldap tests if LDAP lib is not installed ldap_lib_installed = False
--- a/kallithea/tests/other/manual_test_vcs_operations.py Wed Jun 29 16:53:53 2016 +0200 +++ b/kallithea/tests/other/manual_test_vcs_operations.py Sun Jun 12 21:21:43 2016 +0200 @@ -36,7 +36,6 @@ import re import tempfile import time -from os.path import join as jn from tempfile import _RandomNameSequence from subprocess import Popen, PIPE @@ -113,9 +112,9 @@ :param DEST: """ # commit some stuff into this repo - cwd = path = jn(DEST) - #added_file = jn(path, '%ssetupążźć.py' % _RandomNameSequence().next()) - added_file = jn(path, '%ssetup.py' % _RandomNameSequence().next()) + cwd = path = os.path.join(DEST) + #added_file = os.path.join(path, '%ssetupążźć.py' % _RandomNameSequence().next()) + added_file = os.path.join(path, '%ssetup.py' % _RandomNameSequence().next()) Command(cwd).execute('touch %s' % added_file) Command(cwd).execute('%s add %s' % (vcs, added_file))
--- a/kallithea/tests/scripts/manual_test_concurrency.py Wed Jun 29 16:53:53 2016 +0200 +++ b/kallithea/tests/scripts/manual_test_concurrency.py Sun Jun 12 21:21:43 2016 +0200 @@ -30,7 +30,6 @@ import sys import shutil import logging -from os.path import join as jn from os.path import dirname as dn from tempfile import _RandomNameSequence @@ -161,7 +160,7 @@ #============================================================================== def test_clone_with_credentials(no_errors=False, repo=HG_REPO, method=METHOD, seq=None, backend='hg'): - cwd = path = jn(Ui.get_by_key('paths', '/').ui_value, repo) + cwd = path = os.path.join(Ui.get_by_key('paths', '/').ui_value, repo) if seq is None: seq = _RandomNameSequence().next() @@ -169,7 +168,7 @@ try: shutil.rmtree(path, ignore_errors=True) os.makedirs(path) - #print 'made dirs %s' % jn(path) + #print 'made dirs %s' % os.path.join(path) except OSError: raise
--- a/kallithea/tests/scripts/manual_test_crawler.py Wed Jun 29 16:53:53 2016 +0200 +++ b/kallithea/tests/scripts/manual_test_crawler.py Sun Jun 12 21:21:43 2016 +0200 @@ -38,7 +38,6 @@ import os import sys import tempfile -from os.path import join as jn from os.path import dirname as dn __here__ = os.path.abspath(__file__) @@ -62,7 +61,7 @@ print 'Crawling @ %s' % BASE_URI BASE_URI += '%s' -PROJECT_PATH = jn('/', 'home', 'username', 'repos') +PROJECT_PATH = os.path.join('/', 'home', 'username', 'repos') PROJECTS = [ #'linux-magx-pbranch', 'CPython', @@ -70,7 +69,7 @@ ] -cj = cookielib.FileCookieJar(jn(tempfile.gettempdir(), 'rc_test_cookie.txt')) +cj = cookielib.FileCookieJar(os.path.join(tempfile.gettempdir(), 'rc_test_cookie.txt')) o = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) o.addheaders = [ ('User-agent', 'kallithea-crawler'), @@ -82,7 +81,7 @@ def _get_repo(proj): if isinstance(proj, basestring): - repo = vcs.get_repo(jn(PROJECT_PATH, proj)) + repo = vcs.get_repo(os.path.join(PROJECT_PATH, proj)) proj = proj else: repo = proj @@ -117,7 +116,7 @@ def test_changeset_walk(proj, limit=None): repo, proj = _get_repo(proj) - print 'processing', jn(PROJECT_PATH, proj) + print 'processing', os.path.join(PROJECT_PATH, proj) total_time = 0 cnt = 0 @@ -143,7 +142,7 @@ def test_files_walk(proj, limit=100): repo, proj = _get_repo(proj) - print 'processing', jn(PROJECT_PATH, proj) + print 'processing', os.path.join(PROJECT_PATH, proj) total_time = 0 paths_ = OrderedSet(['']) @@ -183,7 +182,7 @@ if __name__ == '__main__': for path in PROJECTS: - repo = vcs.get_repo(jn(PROJECT_PATH, path)) + repo = vcs.get_repo(os.path.join(PROJECT_PATH, path)) for i in range(PASES): print 'PASS %s/%s' % (i, PASES) test_changelog_walk(repo, pages=80)
--- a/kallithea/tests/vcs/conf.py Wed Jun 29 16:53:53 2016 +0200 +++ b/kallithea/tests/vcs/conf.py Sun Jun 12 21:21:43 2016 +0200 @@ -8,7 +8,6 @@ import datetime import shutil import uuid -from os.path import join as jn __all__ = ( 'TEST_HG_REPO', 'TEST_GIT_REPO', 'HG_REMOTE_REPO', 'GIT_REMOTE_REPO', @@ -24,19 +23,19 @@ TEST_TMP_PATH = os.environ.get('VCS_TEST_ROOT', tempfile.gettempdir()) TEST_GIT_REPO = os.environ.get('VCS_TEST_GIT_REPO', - jn(TEST_TMP_PATH, 'vcs-git')) + os.path.join(TEST_TMP_PATH, 'vcs-git')) TEST_GIT_REPO_CLONE = os.environ.get('VCS_TEST_GIT_REPO_CLONE', - jn(TEST_TMP_PATH, 'vcsgitclone%s' % uniq_suffix)) + os.path.join(TEST_TMP_PATH, 'vcsgitclone%s' % uniq_suffix)) TEST_GIT_REPO_PULL = os.environ.get('VCS_TEST_GIT_REPO_PULL', - jn(TEST_TMP_PATH, 'vcsgitpull%s' % uniq_suffix)) + os.path.join(TEST_TMP_PATH, 'vcsgitpull%s' % uniq_suffix)) HG_REMOTE_REPO = 'http://bitbucket.org/marcinkuzminski/vcs' TEST_HG_REPO = os.environ.get('VCS_TEST_HG_REPO', - jn(TEST_TMP_PATH, 'vcs-hg')) + os.path.join(TEST_TMP_PATH, 'vcs-hg')) TEST_HG_REPO_CLONE = os.environ.get('VCS_TEST_HG_REPO_CLONE', - jn(TEST_TMP_PATH, 'vcshgclone%s' % uniq_suffix)) + os.path.join(TEST_TMP_PATH, 'vcshgclone%s' % uniq_suffix)) TEST_HG_REPO_PULL = os.environ.get('VCS_TEST_HG_REPO_PULL', - jn(TEST_TMP_PATH, 'vcshgpull%s' % uniq_suffix)) + os.path.join(TEST_TMP_PATH, 'vcshgpull%s' % uniq_suffix)) TEST_DIR = os.environ.get('VCS_TEST_ROOT', tempfile.gettempdir()) TEST_REPO_PREFIX = 'vcs-test' @@ -80,8 +79,8 @@ PACKAGE_DIR = os.path.abspath(os.path.join( os.path.dirname(__file__), '..')) -_dest = jn(TEST_TMP_PATH, 'aconfig') -shutil.copy(jn(THIS, 'aconfig'), _dest) +_dest = os.path.join(TEST_TMP_PATH, 'aconfig') +shutil.copy(os.path.join(THIS, 'aconfig'), _dest) TEST_USER_CONFIG_FILE = _dest #overide default configurations with kallithea ones