Skip to content

Commit

Permalink
Flatten out environmental var check.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Socol committed Apr 10, 2012
1 parent fa5d653 commit 8a6fb6c
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions statsd/__init__.py
@@ -1,5 +1,5 @@
import socket
import os
import socket

try:
from django.conf import settings
Expand All @@ -11,22 +11,25 @@

__all__ = ['StatsClient', 'statsd']

VERSION = (0, 4, 0)
VERSION = (0, 5, 0)
__version__ = '.'.join(map(str, VERSION))


statsd = None

if settings:
try:
host = getattr(settings, 'STATSD_HOST', 'localhost')
port = getattr(settings, 'STATSD_PORT', 8125)
prefix = getattr(settings, 'STATSD_PREFIX', None)
statsd = StatsClient(host, port, prefix)
except (socket.error, socket.gaierror, ImportError):
try:
host = os.environ['STATSD_HOST']
port = int(os.environ['STATSD_PORT'])
prefix = os.environ.get('STATSD_PREFIX')
statsd = StatsClient(host, port, prefix)
except (socket.error, socket.gaierror, KeyError):
statsd = None

pass
elif 'STATSD_HOST' in os.environ:
try:
host = os.environ['STATSD_HOST']
port = int(os.environ['STATSD_PORT'])
prefix = os.environ.get('STATSD_PREFIX')
statsd = StatsClient(host, port, prefix)
except (socket.error, socket.gaierror, KeyError):
pass

0 comments on commit 8a6fb6c

Please sign in to comment.