# HG changeset patch # User domruf # Date 2016-06-13 19:39:47 # Node ID 037efd94e9559c60fed4f9f314f881a8c1f48288 # Parent b313d735d9c87a598fee539bda0ea12c1794d577 cleanup: get rid of dn as shortcut for os.path.dirname We keep 'dirname' as shortcut despite having removed the 'join' shortcut: * the name is less ambiguous than 'join'. * dirname is often applied multiple times - spelling it out would be too verbose. diff --git a/kallithea/lib/db_manage.py b/kallithea/lib/db_manage.py --- a/kallithea/lib/db_manage.py +++ b/kallithea/lib/db_manage.py @@ -31,7 +31,7 @@ import sys import time import uuid import logging -from os.path import dirname as dn +from os.path import dirname from kallithea import __dbversion__, __py_version__, EXTERN_TYPE_INTERNAL, DB_MIGRATIONS from kallithea.model.user import UserModel @@ -138,7 +138,7 @@ class DbManage(object): print 'No upgrade performed' sys.exit(0) - repository_path = os.path.join(dn(dn(dn(os.path.realpath(__file__)))), + repository_path = os.path.join(dirname(dirname(dirname(os.path.realpath(__file__)))), 'kallithea', 'lib', 'dbmigrate') db_uri = self.dburi diff --git a/kallithea/lib/indexers/__init__.py b/kallithea/lib/indexers/__init__.py --- a/kallithea/lib/indexers/__init__.py +++ b/kallithea/lib/indexers/__init__.py @@ -28,10 +28,10 @@ Original author and date, and relevant c import os import sys import logging -from os.path import dirname as dn +from os.path import dirname # Add location of top level folder to sys.path -sys.path.append(dn(dn(dn(os.path.realpath(__file__))))) +sys.path.append(dirname(dirname(dirname(os.path.realpath(__file__))))) from whoosh.analysis import RegexTokenizer, LowercaseFilter from whoosh.fields import TEXT, ID, STORED, NUMERIC, BOOLEAN, Schema, FieldType, DATETIME diff --git a/kallithea/lib/indexers/daemon.py b/kallithea/lib/indexers/daemon.py --- a/kallithea/lib/indexers/daemon.py +++ b/kallithea/lib/indexers/daemon.py @@ -34,10 +34,10 @@ import traceback from shutil import rmtree from time import mktime -from os.path import dirname as dn +from os.path import dirname # Add location of top level folder to sys.path -project_path = dn(dn(dn(dn(os.path.realpath(__file__))))) +project_path = dirname(dirname(dirname(dirname(os.path.realpath(__file__))))) sys.path.append(project_path) from kallithea.config.conf import INDEX_EXTENSIONS, INDEX_FILENAMES diff --git a/kallithea/lib/paster_commands/cache_keys.py b/kallithea/lib/paster_commands/cache_keys.py --- a/kallithea/lib/paster_commands/cache_keys.py +++ b/kallithea/lib/paster_commands/cache_keys.py @@ -35,8 +35,8 @@ from kallithea.lib.utils import BasePast from kallithea.model.db import CacheInvalidation # Add location of top level folder to sys.path -from os.path import dirname as dn -rc_path = dn(dn(dn(os.path.realpath(__file__)))) +from os.path import dirname +rc_path = dirname(dirname(dirname(os.path.realpath(__file__)))) sys.path.append(rc_path) diff --git a/kallithea/lib/paster_commands/cleanup.py b/kallithea/lib/paster_commands/cleanup.py --- a/kallithea/lib/paster_commands/cleanup.py +++ b/kallithea/lib/paster_commands/cleanup.py @@ -38,8 +38,8 @@ from kallithea.lib.utils2 import safe_st from kallithea.model.db import Ui # Add location of top level folder to sys.path -from os.path import dirname as dn -rc_path = dn(dn(dn(os.path.realpath(__file__)))) +from os.path import dirname +rc_path = dirname(dirname(dirname(os.path.realpath(__file__)))) sys.path.append(rc_path) diff --git a/kallithea/lib/paster_commands/install_iis.py b/kallithea/lib/paster_commands/install_iis.py --- a/kallithea/lib/paster_commands/install_iis.py +++ b/kallithea/lib/paster_commands/install_iis.py @@ -25,8 +25,8 @@ from paste.script.appinstall import Abst from paste.script.command import BadCommand # Add location of top level folder to sys.path -from os.path import dirname as dn -rc_path = dn(dn(dn(os.path.realpath(__file__)))) +from os.path import dirname +rc_path = dirname(dirname(dirname(os.path.realpath(__file__)))) sys.path.append(rc_path) class Command(AbstractInstallCommand): diff --git a/kallithea/lib/paster_commands/ishell.py b/kallithea/lib/paster_commands/ishell.py --- a/kallithea/lib/paster_commands/ishell.py +++ b/kallithea/lib/paster_commands/ishell.py @@ -32,8 +32,8 @@ import sys from kallithea.lib.utils import BasePasterCommand # Add location of top level folder to sys.path -from os.path import dirname as dn -rc_path = dn(dn(dn(os.path.realpath(__file__)))) +from os.path import dirname +rc_path = dirname(dirname(dirname(os.path.realpath(__file__)))) sys.path.append(rc_path) diff --git a/kallithea/lib/paster_commands/make_index.py b/kallithea/lib/paster_commands/make_index.py --- a/kallithea/lib/paster_commands/make_index.py +++ b/kallithea/lib/paster_commands/make_index.py @@ -34,8 +34,8 @@ from kallithea.model.repo import RepoMod from kallithea.lib.utils import BasePasterCommand, load_rcextensions # Add location of top level folder to sys.path -from os.path import dirname as dn -rc_path = dn(dn(dn(os.path.realpath(__file__)))) +from os.path import dirname +rc_path = dirname(dirname(dirname(os.path.realpath(__file__)))) sys.path.append(rc_path) @@ -71,7 +71,7 @@ class Command(BasePasterCommand): from kallithea.lib.pidlock import LockHeld, DaemonLock from kallithea.lib.indexers.daemon import WhooshIndexingDaemon try: - l = DaemonLock(file_=os.path.join(dn(dn(index_location)), + l = DaemonLock(file_=os.path.join(dirname(dirname(index_location)), 'make_index.lock')) WhooshIndexingDaemon(index_location=index_location, repo_location=repo_location, diff --git a/kallithea/lib/paster_commands/make_rcextensions.py b/kallithea/lib/paster_commands/make_rcextensions.py --- a/kallithea/lib/paster_commands/make_rcextensions.py +++ b/kallithea/lib/paster_commands/make_rcextensions.py @@ -33,8 +33,8 @@ import pkg_resources from kallithea.lib.utils import BasePasterCommand, ask_ok # Add location of top level folder to sys.path -from os.path import dirname as dn -rc_path = dn(dn(dn(os.path.realpath(__file__)))) +from os.path import dirname +rc_path = dirname(dirname(dirname(os.path.realpath(__file__)))) sys.path.append(rc_path) diff --git a/kallithea/lib/paster_commands/repo_scan.py b/kallithea/lib/paster_commands/repo_scan.py --- a/kallithea/lib/paster_commands/repo_scan.py +++ b/kallithea/lib/paster_commands/repo_scan.py @@ -33,8 +33,8 @@ from kallithea.model.scm import ScmModel from kallithea.lib.utils import BasePasterCommand, repo2db_mapper # Add location of top level folder to sys.path -from os.path import dirname as dn -rc_path = dn(dn(dn(os.path.realpath(__file__)))) +from os.path import dirname +rc_path = dirname(dirname(dirname(os.path.realpath(__file__)))) sys.path.append(rc_path) diff --git a/kallithea/lib/paster_commands/setup_db.py b/kallithea/lib/paster_commands/setup_db.py --- a/kallithea/lib/paster_commands/setup_db.py +++ b/kallithea/lib/paster_commands/setup_db.py @@ -26,8 +26,8 @@ from paste.script.command import BadComm from paste.deploy import appconfig # Add location of top level folder to sys.path -from os.path import dirname as dn -rc_path = dn(dn(dn(os.path.realpath(__file__)))) +from os.path import dirname +rc_path = dirname(dirname(dirname(os.path.realpath(__file__)))) sys.path.append(rc_path) diff --git a/kallithea/lib/paster_commands/update_repoinfo.py b/kallithea/lib/paster_commands/update_repoinfo.py --- a/kallithea/lib/paster_commands/update_repoinfo.py +++ b/kallithea/lib/paster_commands/update_repoinfo.py @@ -36,8 +36,8 @@ from kallithea.model.repo import RepoMod from kallithea.model.meta import Session # Add location of top level folder to sys.path -from os.path import dirname as dn -rc_path = dn(dn(dn(os.path.realpath(__file__)))) +from os.path import dirname +rc_path = dirname(dirname(dirname(os.path.realpath(__file__)))) sys.path.append(rc_path) diff --git a/kallithea/lib/utils.py b/kallithea/lib/utils.py --- a/kallithea/lib/utils.py +++ b/kallithea/lib/utils.py @@ -37,7 +37,7 @@ import shutil import decorator import warnings from os.path import abspath -from os.path import dirname as dn +from os.path import dirname from paste.script.command import Command, BadCommand @@ -653,7 +653,7 @@ def create_test_index(repo_location, con os.makedirs(index_location) try: - l = DaemonLock(file_=os.path.join(dn(index_location), 'make_index.lock')) + l = DaemonLock(file_=os.path.join(dirname(index_location), 'make_index.lock')) WhooshIndexingDaemon(index_location=index_location, repo_location=repo_location) \ .run(full_index=full_index) @@ -705,12 +705,12 @@ def create_test_env(repos_test_path, con shutil.rmtree(data_path) #CREATE DEFAULT TEST REPOS - cur_dir = dn(dn(abspath(__file__))) + cur_dir = dirname(dirname(abspath(__file__))) 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__))) + cur_dir = dirname(dirname(abspath(__file__))) 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() diff --git a/kallithea/tests/fixture.py b/kallithea/tests/fixture.py --- a/kallithea/tests/fixture.py +++ b/kallithea/tests/fixture.py @@ -27,9 +27,9 @@ from kallithea.model.user_group import U from kallithea.model.gist import GistModel from kallithea.model.scm import ScmModel from kallithea.lib.vcs.backends.base import EmptyChangeset +from os.path import dirname -dn = os.path.dirname -FIXTURES = os.path.join(dn(dn(os.path.abspath(__file__))), 'tests', 'fixtures') +FIXTURES = os.path.join(dirname(dirname(os.path.abspath(__file__))), 'tests', 'fixtures') def error_function(*args, **kwargs): diff --git a/kallithea/tests/functional/test_admin.py b/kallithea/tests/functional/test_admin.py --- a/kallithea/tests/functional/test_admin.py +++ b/kallithea/tests/functional/test_admin.py @@ -5,9 +5,9 @@ from kallithea.tests import * from kallithea.model.db import UserLog from kallithea.model.meta import Session from kallithea.lib.utils2 import safe_unicode +from os.path import dirname -dn = os.path.dirname -FIXTURES = os.path.join(dn(dn(os.path.abspath(__file__))), 'fixtures') +FIXTURES = os.path.join(dirname(dirname(os.path.abspath(__file__))), 'fixtures') class TestAdminController(TestController): diff --git a/kallithea/tests/scripts/manual_test_concurrency.py b/kallithea/tests/scripts/manual_test_concurrency.py --- a/kallithea/tests/scripts/manual_test_concurrency.py +++ b/kallithea/tests/scripts/manual_test_concurrency.py @@ -30,7 +30,7 @@ import os import sys import shutil import logging -from os.path import dirname as dn +from os.path import dirname from tempfile import _RandomNameSequence from subprocess import Popen, PIPE @@ -47,7 +47,7 @@ from kallithea.lib.auth import get_crypt from kallithea.tests import HG_REPO from kallithea.config.environment import load_environment -rel_path = dn(dn(dn(dn(os.path.abspath(__file__))))) +rel_path = dirname(dirname(dirname(dirname(os.path.abspath(__file__))))) conf = appconfig('config:development.ini', relative_to=rel_path) load_environment(conf.global_conf, conf.local_conf) diff --git a/kallithea/tests/scripts/manual_test_crawler.py b/kallithea/tests/scripts/manual_test_crawler.py --- a/kallithea/tests/scripts/manual_test_crawler.py +++ b/kallithea/tests/scripts/manual_test_crawler.py @@ -38,10 +38,10 @@ import time import os import sys import tempfile -from os.path import dirname as dn +from os.path import dirname __here__ = os.path.abspath(__file__) -__root__ = dn(dn(dn(__here__))) +__root__ = dirname(dirname(dirname(__here__))) sys.path.append(__root__) from kallithea.lib import vcs