diff options
author | Julian Mehne <julian.mehne@posteo.de> | 2018-01-23 13:18:06 +0100 |
---|---|---|
committer | Julian Mehne <julian.mehne@posteo.de> | 2018-01-23 13:18:06 +0100 |
commit | d2888c080f00d5d53ff0f30626bc3059cdc95ef8 (patch) | |
tree | c4eed139257b3ecb57ef979d5fd89d6bc3e4fb0b | |
parent | e8586c18e73920ec9c5ad3344a0fbaa53bca3954 (diff) |
Rename get_env to get_xdg_env and clarify docstring.
-rw-r--r-- | alot/__main__.py | 5 | ||||
-rw-r--r-- | alot/helper.py | 4 | ||||
-rw-r--r-- | alot/settings/manager.py | 6 | ||||
-rw-r--r-- | alot/ui.py | 4 | ||||
-rw-r--r-- | tests/helper_test.py | 6 |
5 files changed, 13 insertions, 12 deletions
diff --git a/alot/__main__.py b/alot/__main__.py index 207c8b92..d8ab5b0d 100644 --- a/alot/__main__.py +++ b/alot/__main__.py @@ -11,7 +11,7 @@ import sys import alot from alot.settings.const import settings from alot.settings.errors import ConfigError -from alot.helper import get_env +from alot.helper import get_xdg_env from alot.db.manager import DBManager from alot.ui import UI from alot.commands import * @@ -93,7 +93,8 @@ def main(): # locate alot config files if options.config is None: - xdg_dir = get_env('XDG_CONFIG_HOME', os.path.expanduser('~/.config')) + xdg_dir = get_xdg_env('XDG_CONFIG_HOME', + os.path.expanduser('~/.config')) alotconfig = os.path.join(xdg_dir, 'alot', 'config') if os.path.exists(alotconfig): settings.alot_rc_path = alotconfig diff --git a/alot/helper.py b/alot/helper.py index 06362e06..5fab4819 100644 --- a/alot/helper.py +++ b/alot/helper.py @@ -627,7 +627,7 @@ def email_as_string(mail): return as_string -def get_env(env_name, fallback): - """ Gets environment variable and returns fallback if unset or empty """ +def get_xdg_env(env_name, fallback): + """ Used for XDG_* env variables to return fallback if unset *or* empty """ env = os.environ.get(env_name) return env if env else fallback diff --git a/alot/settings/manager.py b/alot/settings/manager.py index 150bd7d1..591edba8 100644 --- a/alot/settings/manager.py +++ b/alot/settings/manager.py @@ -15,7 +15,7 @@ from configobj import ConfigObj, Section from ..account import SendmailAccount from ..addressbook.abook import AbookAddressBook from ..addressbook.external import ExternalAddressbook -from ..helper import pretty_datetime, string_decode, get_env +from ..helper import pretty_datetime, string_decode, get_xdg_env from ..utils import configobj as checks from .errors import ConfigError, NoMatchingAccount @@ -25,8 +25,8 @@ from .theme import Theme DEFAULTSPATH = os.path.join(os.path.dirname(__file__), '..', 'defaults') -DATA_DIRS = get_env('XDG_DATA_DIRS', - '/usr/local/share:/usr/share').split(':') +DATA_DIRS = get_xdg_env('XDG_DATA_DIRS', + '/usr/local/share:/usr/share').split(':') class SettingsManager(object): @@ -18,7 +18,7 @@ from .commands import CommandCanceled from .commands import CommandParseError from .helper import split_commandline from .helper import string_decode -from .helper import get_env +from .helper import get_xdg_env from .widgets.globals import CompleteEdit from .widgets.globals import ChoiceWidget @@ -84,7 +84,7 @@ class UI(object): # load histories self._cache = os.path.join( - get_env('XDG_CACHE_HOME', os.path.expanduser('~/.cache')), + get_xdg_env('XDG_CACHE_HOME', os.path.expanduser('~/.cache')), 'alot', 'history') self._cmd_hist_file = os.path.join(self._cache, 'commands') self._sender_hist_file = os.path.join(self._cache, 'senders') diff --git a/tests/helper_test.py b/tests/helper_test.py index 02105a29..0350b333 100644 --- a/tests/helper_test.py +++ b/tests/helper_test.py @@ -474,13 +474,13 @@ class TestGetEnv(unittest.TestCase): with mock.patch.dict('os.environ'): if self.env_name in os.environ: del os.environ[self.env_name] - self.assertEqual(helper.get_env(self.env_name, self.default), + self.assertEqual(helper.get_xdg_env(self.env_name, self.default), self.default) def test_env_empty(self): with mock.patch.dict('os.environ'): os.environ[self.env_name] = '' - self.assertEqual(helper.get_env(self.env_name, self.default), + self.assertEqual(helper.get_xdg_env(self.env_name, self.default), self.default) def test_env_not_empty(self): @@ -488,5 +488,5 @@ class TestGetEnv(unittest.TestCase): with mock.patch.dict('os.environ'): os.environ[self.env_name] = custom_path - self.assertEqual(helper.get_env(self.env_name, self.default), + self.assertEqual(helper.get_xdg_env(self.env_name, self.default), custom_path) |