Skip to content

Commit 1ab97bb

Browse files
committed
Support controlling configuration filename through a constructor argument (closes #70)
1 parent 214d849 commit 1ab97bb

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

backslash/contrib/slash_plugin.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from ..session import APPEND_UPCOMING_TESTS_STR
3737
from ..__version__ import __version__ as BACKSLASH_CLIENT_VERSION
3838

39-
_CONFIG_FILE = os.path.expanduser('~/.backslash/config.json')
39+
_DEFAULT_CONFIG_FILENAME = os.path.expanduser('~/.backslash/config.json')
4040

4141
_logger = logbook.Logger(__name__)
4242

@@ -63,10 +63,12 @@ class BackslashPlugin(PluginInterface):
6363

6464
client = current_test = session = None
6565

66-
def __init__(self, url=None, keepalive_interval=None, runtoken=None, propagate_exceptions=False):
66+
def __init__(self, url=None, keepalive_interval=None, runtoken=None,
67+
propagate_exceptions=False, config_filename=_DEFAULT_CONFIG_FILENAME):
6768
super(BackslashPlugin, self).__init__()
6869
self._url = url
6970
self._repo_cache = {}
71+
self._config_filename = config_filename
7072
self._file_hash_cache = {}
7173
self._keepalive_interval = keepalive_interval
7274
self._keepalive_thread = None
@@ -504,21 +506,21 @@ def _get_existing_tokens(self):
504506
return self._get_config().get('run_tokens', {})
505507

506508
def _get_config(self):
507-
if not os.path.isfile(_CONFIG_FILE):
509+
if not os.path.isfile(self._config_filename):
508510
return {}
509-
with open(_CONFIG_FILE) as f:
511+
with open(self._config_filename) as f:
510512
return json.load(f)
511513

512514
def _save_token(self, token):
513-
tmp_filename = _CONFIG_FILE + '.tmp'
515+
tmp_filename = self._config_filename + '.tmp'
514516
cfg = self._get_config()
515517
cfg.setdefault('run_tokens', {})[self._get_backslash_url()] = token
516518

517519
ensure_dir(os.path.dirname(tmp_filename))
518520

519521
with open(tmp_filename, 'w') as f:
520522
json.dump(cfg, f, indent=2)
521-
os.rename(tmp_filename, _CONFIG_FILE)
523+
os.rename(tmp_filename, self._config_filename)
522524

523525
@registers_on(None)
524526
def fetch_token(self, username, password):

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Changelog
22
=========
33

4+
* :feature:`70` Configuration filename for the bundled Slash plugin can now be controlled through a constructor argument
45
* :feature:`68` Support blacklisting warning categories from being reported to backslash
56
* :release:`2.33.1 <30-1-2018>`
67
* :bug:`63` Avoid accidental deprecation when examining exception attributes

0 commit comments

Comments
 (0)