Skip to content

Commit

Permalink
Simplify config dir functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
wummel committed Mar 11, 2014
1 parent 14409b0 commit 0ad5969
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
13 changes: 2 additions & 11 deletions linkcheck/__init__.py
Expand Up @@ -43,28 +43,19 @@
import _LinkChecker_configdata as configdata


def main_is_frozen ():
"""Return True iff running inside a py2exe-generated executable."""
return hasattr(sys, "frozen")


def module_path ():
"""Return absolute directory of system executable."""
return os.path.dirname(os.path.abspath(sys.executable))


def get_install_data ():
"""Return absolute path of LinkChecker data installation directory."""
if main_is_frozen():
from .loader import is_frozen
if is_frozen():
return module_path()
return configdata.install_data


def get_config_dir ():
"""Return absolute path of LinkChecker example configuration."""
return os.path.join(get_install_data(), "share", "linkchecker")


# application log areas
LOG_ROOT = "linkcheck"
LOG_CMDLINE = "linkcheck.cmdline"
Expand Down
17 changes: 8 additions & 9 deletions linkcheck/configuration/__init__.py
Expand Up @@ -28,7 +28,7 @@
import socket
import _LinkChecker_configdata as configdata
from .. import (log, LOG_CHECK, LOG_ROOT, ansicolor, lognames,
get_config_dir, fileutil, configdict)
get_install_data, fileutil, configdict)
from . import confparse
from ..decorators import memoized

Expand Down Expand Up @@ -92,6 +92,11 @@ def get_modules_info ():
return lines


def get_share_dir ():
"""Return absolute path of LinkChecker example configuration."""
return os.path.join(get_install_data(), "share", "linkchecker")


def get_share_file (filename, devel_dir=None):
"""Return a filename in the share directory.
@param devel_dir: directory to search when developing
Expand All @@ -102,13 +107,7 @@ def get_share_file (filename, devel_dir=None):
@rtype: string
@raises: ValueError if not found
"""
paths = [
# when running under py2exe
os.path.join(os.path.dirname(os.path.abspath(sys.executable)),
"share", "linkchecker"),
# after installing as a package
configdata.config_dir,
]
paths = [get_share_dir()]
if devel_dir is not None:
# when developing
paths.insert(0, devel_dir)
Expand Down Expand Up @@ -413,7 +412,7 @@ def get_user_config():
@rtype string
"""
# initial config (with all options explained)
initialconf = normpath(os.path.join(get_config_dir(), "linkcheckerrc"))
initialconf = normpath(os.path.join(get_share_dir(), "linkcheckerrc"))
# per user config settings
userconf = normpath("~/.linkchecker/linkcheckerrc")
if os.path.isfile(initialconf) and not os.path.exists(userconf) and \
Expand Down

0 comments on commit 0ad5969

Please sign in to comment.