Skip to content

Commit 040f273

Browse files
author
Burak Yigit Kaya
committed
Refactor initial config step so all defaults are always set (fixes disqus#28)
1 parent b2e2463 commit 040f273

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

phabricator/__init__.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def parse_interfaces(interfaces):
177177
return dict(parsed_interfaces)
178178

179179

180-
class InterfaceNotDefined(NotImplementedError):
180+
class ConfigurationError(Exception):
181181
pass
182182

183183

@@ -190,10 +190,6 @@ def __str__(self):
190190
return '%s: %s' % (self.code, self.message)
191191

192192

193-
class InvalidAccessToken(APIError):
194-
pass
195-
196-
197193
class Result(MutableMapping):
198194
def __init__(self, response):
199195
self.response = response
@@ -323,19 +319,19 @@ class Phabricator(Resource):
323319
def __init__(self, username=None, certificate=None, host=None,
324320
timeout=5, response_format='json', token=None, **kwargs):
325321

326-
# Set values in ~/.arcrc as defaults
327-
if ARCRC:
328-
self.host = host if host else ARCRC['hosts'].keys()[0]
329-
if token or 'token' in ARCRC['hosts'][self.host]:
330-
self.token = token if token else ARCRC['hosts'][self.host]['token']
331-
else:
332-
self.username = username if username else ARCRC['hosts'][self.host]['user']
333-
self.certificate = certificate if certificate else ARCRC['hosts'][self.host]['cert']
334-
else:
335-
self.host = host
336-
self.token = token
337-
self.username = username
338-
self.certificate = certificate
322+
defined_hosts = ARCRC.get('hosts', {})
323+
324+
try:
325+
self.host = host if host else defined_hosts.keys()[0]
326+
except IndexError:
327+
raise ConfigurationError("No host found or provided.")
328+
329+
current_host_config = defined_hosts.get(self.host, {})
330+
self.token = token if token else current_host_config.get('token')
331+
332+
if self.token is None:
333+
self.username = username if username else current_host_config.get('user')
334+
self.certificate = certificate if certificate else current_host_config.get('cert')
339335

340336
self.timeout = timeout
341337
self.response_format = response_format

0 commit comments

Comments
 (0)