prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Programatically setting config file
  I am trying to write tests for the dftimewolf turbinia module. Loading the configuration on a system that doesn't have one will fail, so I am trying to manually feed in a test config data to see if the module behaves as expected.
  
  I tried setting the `TURBINIA_CONFIG_PATH` environment variable, but this just *adds* the path the list of possible config paths. This would work in a pristine test environment, but it will break in my dev setup where I already have a production turbinia config file set up.
  
  What do you think of giving `TURBINIA_CONFIG_PATH` environment variable precedence over the other potential config locations?
  
  </issue>
  <code>
  [start of turbinia/config/__init__.py]
  1 # -*- coding: utf-8 -*-
  2 # Copyright 2016 Google Inc.
  3 #
  4 # Licensed under the Apache License, Version 2.0 (the "License");
  5 # you may not use this file except in compliance with the License.
  6 # You may obtain a copy of the License at
  7 #
  8 #      http://www.apache.org/licenses/LICENSE-2.0
  9 #
  10 # Unless required by applicable law or agreed to in writing, software
  11 # distributed under the License is distributed on an "AS IS" BASIS,
  12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 # See the License for the specific language governing permissions and
  14 # limitations under the License.
  15 """Basic Turbinia config."""
  16 
  17 from __future__ import unicode_literals
  18 
  19 import imp
  20 import itertools
  21 import logging
  22 import os
  23 import sys
  24 
  25 log = logging.getLogger('turbinia')
  26 
  27 # Look for config files with these names
  28 CONFIGFILES = ['.turbiniarc', 'turbinia.conf', 'turbinia_config.py']
  29 # Look in homedir first, then /etc/turbinia, and finally in the source
  30 # config dir for config files
  31 CONFIGPATH = [
  32     os.path.expanduser('~'),
  33     '/etc/turbinia',
  34     os.path.dirname(os.path.abspath(__file__))]
  35 # Config vars that we expect to exist in the configuration
  36 CONFIGVARS = [
  37     # Turbinia Config
  38     'TASK_MANAGER',
  39     'LOG_FILE',
  40     'LOCK_FILE',
  41     'OUTPUT_DIR',
  42     'SLEEP_TIME',
  43     'SINGLE_RUN',
  44     'MOUNT_DIR_PREFIX',
  45     'SHARED_FILESYSTEM',
  46     # TODO(aarontp): Move this to the recipe config when it's available.
  47     'DEBUG_TASKS',
  48     # GCE CONFIG
  49     'PROJECT',
  50     'ZONE',
  51     'TURBINIA_REGION',
  52     'BUCKET_NAME',
  53     'PSQ_TOPIC',
  54     'PUBSUB_TOPIC',
  55     'GCS_OUTPUT_PATH',
  56     'STATE_MANAGER',
  57     'INSTANCE_ID',
  58     # REDIS CONFIG
  59     'REDIS_HOST',
  60     'REDIS_PORT',
  61     'REDIS_DB',
  62     # Celery config
  63     'CELERY_BROKER',
  64     'CELERY_BACKEND',
  65     'KOMBU_BROKER',
  66     'KOMBU_CHANNEL',
  67     'KOMBU_DURABLE',]
  68 # Environment variable to look for path data in
  69 ENVCONFIGVAR = 'TURBINIA_CONFIG_PATH'
  70 
  71 CONFIG = None
  72 
  73 
  74 class TurbiniaConfigException(Exception):
  75   """Exception for Turbinia configuration."""
  76   pass
  77 
  78 
  79 def LoadConfig():
  80   """Finds Turbinia config file and loads it."""
  81   # TODO(aarontp): Find way to not require global var here.  Maybe a singleton
  82   # pattern on the config class.
  83   # pylint: disable=global-statement
  84   global CONFIG
  85   if CONFIG:
  86     return CONFIG
  87 
  88   if ENVCONFIGVAR in os.environ:
  89     CONFIGPATH.extend(os.environ[ENVCONFIGVAR].split(':'))
  90 
  91   config_file = None
  92   # Load first file found
  93   for _dir, _file in itertools.product(CONFIGPATH, CONFIGFILES):
  94     if os.path.exists(os.path.join(_dir, _file)):
  95       config_file = os.path.join(_dir, _file)
  96       break
  97 
  98   if config_file is None:
  99     raise TurbiniaConfigException('No config files found')
  100 
  101   log.info('Loading config from {0:s}'.format(config_file))
  102   _config = imp.load_source('config', config_file)
  103   _config.configSource = config_file
  104   ValidateAndSetConfig(_config)
  105   CONFIG = _config
  106   return _config
  107 
  108 
  109 def ValidateAndSetConfig(_config):
  110   """Makes sure that the config has the vars loaded and set in the module."""
  111   # TODO(aarontp): Allow for non-mandatory config options
  112   for var in CONFIGVARS:
  113     if not hasattr(_config, var):
  114       raise TurbiniaConfigException(
  115           'No config attribute {0:s}:{1:s}'.format(_config.configSource, var))
  116     if getattr(_config, var) is None:
  117       raise TurbiniaConfigException(
  118           'Config attribute {0:s}:{1:s} is not set'.format(
  119               _config.configSource, var))
  120 
  121     # Set the attribute in the current module
  122     setattr(sys.modules[__name__], var, getattr(_config, var))
  123
  [end of turbinia/config/__init__.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/turbinia/config/__init__.py b/turbinia/config/__init__.py
  --- a/turbinia/config/__init__.py
  +++ b/turbinia/config/__init__.py
  @@ -85,12 +85,16 @@
     if CONFIG:
       return CONFIG
   
  +  # If the environment variable is set, take precedence over the pre-defined
  +  # CONFIGPATHs.
  +  configpath = CONFIGPATH
     if ENVCONFIGVAR in os.environ:
  -    CONFIGPATH.extend(os.environ[ENVCONFIGVAR].split(':'))
  +    configpath = os.environ[ENVCONFIGVAR].split(':')
  +
   
     config_file = None
     # Load first file found
  -  for _dir, _file in itertools.product(CONFIGPATH, CONFIGFILES):
  +  for _dir, _file in itertools.product(configpath, CONFIGFILES):
       if os.path.exists(os.path.join(_dir, _file)):
         config_file = os.path.join(_dir, _file)
         break
  
verification_info: {"golden_diff": "diff --git a/turbinia/config/__init__.py b/turbinia/config/__init__.py\n--- a/turbinia/config/__init__.py\n+++ b/turbinia/config/__init__.py\n@@ -85,12 +85,16 @@\n   if CONFIG:\n     return CONFIG\n \n+  # If the environment variable is set, take precedence over the pre-defined\n+  # CONFIGPATHs.\n+  configpath = CONFIGPATH\n   if ENVCONFIGVAR in os.environ:\n-    CONFIGPATH.extend(os.environ[ENVCONFIGVAR].split(':'))\n+    configpath = os.environ[ENVCONFIGVAR].split(':')\n+\n \n   config_file = None\n   # Load first file found\n-  for _dir, _file in itertools.product(CONFIGPATH, CONFIGFILES):\n+  for _dir, _file in itertools.product(configpath, CONFIGFILES):\n     if os.path.exists(os.path.join(_dir, _file)):\n       config_file = os.path.join(_dir, _file)\n       break\n", "issue": "Programatically setting config file\nI am trying to write tests for the dftimewolf turbinia module. Loading the configuration on a system that doesn't have one will fail, so I am trying to manually feed in a test config data to see if the module behaves as expected.\r\n\r\nI tried setting the `TURBINIA_CONFIG_PATH` environment variable, but this just *adds* the path the list of possible config paths. This would work in a pristine test environment, but it will break in my dev setup where I already have a production turbinia config file set up.\r\n\r\nWhat do you think of giving `TURBINIA_CONFIG_PATH` environment variable precedence over the other potential config locations?\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# Copyright 2016 Google Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Basic Turbinia config.\"\"\"\n\nfrom __future__ import unicode_literals\n\nimport imp\nimport itertools\nimport logging\nimport os\nimport sys\n\nlog = logging.getLogger('turbinia')\n\n# Look for config files with these names\nCONFIGFILES = ['.turbiniarc', 'turbinia.conf', 'turbinia_config.py']\n# Look in homedir first, then /etc/turbinia, and finally in the source\n# config dir for config files\nCONFIGPATH = [\n    os.path.expanduser('~'),\n    '/etc/turbinia',\n    os.path.dirname(os.path.abspath(__file__))]\n# Config vars that we expect to exist in the configuration\nCONFIGVARS = [\n    # Turbinia Config\n    'TASK_MANAGER',\n    'LOG_FILE',\n    'LOCK_FILE',\n    'OUTPUT_DIR',\n    'SLEEP_TIME',\n    'SINGLE_RUN',\n    'MOUNT_DIR_PREFIX',\n    'SHARED_FILESYSTEM',\n    # TODO(aarontp): Move this to the recipe config when it's available.\n    'DEBUG_TASKS',\n    # GCE CONFIG\n    'PROJECT',\n    'ZONE',\n    'TURBINIA_REGION',\n    'BUCKET_NAME',\n    'PSQ_TOPIC',\n    'PUBSUB_TOPIC',\n    'GCS_OUTPUT_PATH',\n    'STATE_MANAGER',\n    'INSTANCE_ID',\n    # REDIS CONFIG\n    'REDIS_HOST',\n    'REDIS_PORT',\n    'REDIS_DB',\n    # Celery config\n    'CELERY_BROKER',\n    'CELERY_BACKEND',\n    'KOMBU_BROKER',\n    'KOMBU_CHANNEL',\n    'KOMBU_DURABLE',]\n# Environment variable to look for path data in\nENVCONFIGVAR = 'TURBINIA_CONFIG_PATH'\n\nCONFIG = None\n\n\nclass TurbiniaConfigException(Exception):\n  \"\"\"Exception for Turbinia configuration.\"\"\"\n  pass\n\n\ndef LoadConfig():\n  \"\"\"Finds Turbinia config file and loads it.\"\"\"\n  # TODO(aarontp): Find way to not require global var here.  Maybe a singleton\n  # pattern on the config class.\n  # pylint: disable=global-statement\n  global CONFIG\n  if CONFIG:\n    return CONFIG\n\n  if ENVCONFIGVAR in os.environ:\n    CONFIGPATH.extend(os.environ[ENVCONFIGVAR].split(':'))\n\n  config_file = None\n  # Load first file found\n  for _dir, _file in itertools.product(CONFIGPATH, CONFIGFILES):\n    if os.path.exists(os.path.join(_dir, _file)):\n      config_file = os.path.join(_dir, _file)\n      break\n\n  if config_file is None:\n    raise TurbiniaConfigException('No config files found')\n\n  log.info('Loading config from {0:s}'.format(config_file))\n  _config = imp.load_source('config', config_file)\n  _config.configSource = config_file\n  ValidateAndSetConfig(_config)\n  CONFIG = _config\n  return _config\n\n\ndef ValidateAndSetConfig(_config):\n  \"\"\"Makes sure that the config has the vars loaded and set in the module.\"\"\"\n  # TODO(aarontp): Allow for non-mandatory config options\n  for var in CONFIGVARS:\n    if not hasattr(_config, var):\n      raise TurbiniaConfigException(\n          'No config attribute {0:s}:{1:s}'.format(_config.configSource, var))\n    if getattr(_config, var) is None:\n      raise TurbiniaConfigException(\n          'Config attribute {0:s}:{1:s} is not set'.format(\n              _config.configSource, var))\n\n    # Set the attribute in the current module\n    setattr(sys.modules[__name__], var, getattr(_config, var))\n", "path": "turbinia/config/__init__.py"}]}