36
36
from ..session import APPEND_UPCOMING_TESTS_STR
37
37
from ..__version__ import __version__ as BACKSLASH_CLIENT_VERSION
38
38
39
- _CONFIG_FILE = os .path .expanduser ('~/.backslash/config.json' )
39
+ _DEFAULT_CONFIG_FILENAME = os .path .expanduser ('~/.backslash/config.json' )
40
40
41
41
_logger = logbook .Logger (__name__ )
42
42
@@ -63,10 +63,12 @@ class BackslashPlugin(PluginInterface):
63
63
64
64
client = current_test = session = None
65
65
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 ):
67
68
super (BackslashPlugin , self ).__init__ ()
68
69
self ._url = url
69
70
self ._repo_cache = {}
71
+ self ._config_filename = config_filename
70
72
self ._file_hash_cache = {}
71
73
self ._keepalive_interval = keepalive_interval
72
74
self ._keepalive_thread = None
@@ -504,21 +506,21 @@ def _get_existing_tokens(self):
504
506
return self ._get_config ().get ('run_tokens' , {})
505
507
506
508
def _get_config (self ):
507
- if not os .path .isfile (_CONFIG_FILE ):
509
+ if not os .path .isfile (self . _config_filename ):
508
510
return {}
509
- with open (_CONFIG_FILE ) as f :
511
+ with open (self . _config_filename ) as f :
510
512
return json .load (f )
511
513
512
514
def _save_token (self , token ):
513
- tmp_filename = _CONFIG_FILE + '.tmp'
515
+ tmp_filename = self . _config_filename + '.tmp'
514
516
cfg = self ._get_config ()
515
517
cfg .setdefault ('run_tokens' , {})[self ._get_backslash_url ()] = token
516
518
517
519
ensure_dir (os .path .dirname (tmp_filename ))
518
520
519
521
with open (tmp_filename , 'w' ) as f :
520
522
json .dump (cfg , f , indent = 2 )
521
- os .rename (tmp_filename , _CONFIG_FILE )
523
+ os .rename (tmp_filename , self . _config_filename )
522
524
523
525
@registers_on (None )
524
526
def fetch_token (self , username , password ):
0 commit comments