From 417d127c98ed17449ed7afee340f466546a2b27d Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 14 Feb 2013 13:16:45 -0500 Subject: [PATCH] api: Make site settable via configuration files. This works much better for working with staging, since rather than needing to tell each individual tool that you're using staging, you just specify that along with your API (which at the moment implies whether you should be using staging or prod). (imported from commit c1de8e72c24f35ef2160bce5339a5f03c6e1da95) --- humbug/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/humbug/__init__.py b/humbug/__init__.py index 7ccc375..99196f2 100644 --- a/humbug/__init__.py +++ b/humbug/__init__.py @@ -46,7 +46,7 @@ API_VERSTRING = "/api/v1/" def generate_option_group(parser): group = optparse.OptionGroup(parser, 'API configuration') group.add_option('--site', - default='https://humbughq.com', + default=None, help=optparse.SUPPRESS_HELP) group.add_option('--api-key', action='store') @@ -69,7 +69,7 @@ def init_from_options(options): class Client(object): def __init__(self, email=None, api_key=None, config_file=None, verbose=False, retry_on_errors=True, - site="https://humbughq.com", client="API"): + site=None, client="API"): if None in (api_key, email): if config_file is None: config_file = os.path.join(os.environ["HOME"], ".humbugrc") @@ -83,11 +83,16 @@ class Client(object): api_key = config.get("api", "key") if email is None: email = config.get("api", "email") + if site is None: + site = config.get("api", "site", None) self.api_key = api_key self.email = email self.verbose = verbose - self.base_url = site + if site is not None: + self.base_url = site + else: + self.base_url = "https://humbughq.com" self.retry_on_errors = retry_on_errors self.client_name = client