prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  download_only w/path fails to use path argument when checking for file
  When `download_only` checks to see if the file already exists before copying it, it ignores the path argument. This means that:
  
  ```
  retriever download MoM2003 -p testdata
  ```
  
  will keep overwriting the file in `testdata` if it exists, and it will not copy the file to `testdata` if the file exists in `.`.
  
  Fixes this is probably just a little logic improvement in the `final_cleanup` function of `download_only`.
  
  
  </issue>
  <code>
  [start of engines/download_only.py]
  1 from __future__ import print_function
  2 from builtins import object
  3 import os
  4 import platform
  5 import shutil
  6 import inspect
  7 
  8 from retriever.lib.engine import filename_from_url
  9 from retriever.lib.models import Engine, no_cleanup
  10 from retriever import DATA_DIR, HOME_DIR
  11 
  12 
  13 class DummyConnection(object):
  14 
  15     def cursor(self):
  16         pass
  17 
  18     def commit(self):
  19         pass
  20 
  21     def rollback(self):
  22         pass
  23 
  24     def close(self):
  25         pass
  26 
  27 
  28 class DummyCursor(DummyConnection):
  29     pass
  30 
  31 
  32 class engine(Engine):
  33     """Engine instance for writing data to a CSV file."""
  34     name = "Download Only"
  35     abbreviation = "download"
  36     required_opts = [("path",
  37                       "File path to copy data files",
  38                       "./"),
  39                      ("subdir",
  40                       "Keep the subdirectories for archived files",
  41                       False)
  42                      ]
  43 
  44     def table_exists(self, dbname, tablename):
  45         """Checks if the file to be downloaded already exists"""
  46         try:
  47             tablename = self.table_name(name=tablename, dbname=dbname)
  48             return os.path.exists(tablename)
  49         except:
  50             return False
  51 
  52     def get_connection(self):
  53         """Gets the db connection."""
  54         self.get_input()
  55         return DummyConnection()
  56 
  57     def final_cleanup(self):
  58         """Copies downloaded files to desired directory
  59 
  60         Copies the downloaded files into the chosen directory unless files with the same
  61         name already exist in the directory.
  62 
  63         """
  64         if hasattr(self, "all_files"):
  65             for file_name in self.all_files:
  66                 file_path, file_name_nopath = os.path.split(file_name)
  67                 subdir = os.path.split(file_path)[1] if self.opts['subdir'] else ''
  68                 dest_path = os.path.join(self.opts['path'], subdir)
  69                 if os.path.abspath(file_path) == os.path.abspath(os.path.join(DATA_DIR, subdir)):
  70                     print ("%s is already in the working directory" %
  71                            file_name_nopath)
  72                     print("Keeping existing copy.")
  73                 else:
  74                     print("Copying %s from %s" % (file_name_nopath, file_path))
  75                     if os.path.isdir(dest_path):
  76                         try:
  77                             shutil.copy(file_name, dest_path)
  78                         except:
  79                             print("Couldn't copy file to %s" % dest_path)
  80                     else:
  81                         try:
  82                             print("Creating directory %s" % dest_path)
  83                             os.makedirs(dest_path)
  84                             shutil.copy(file_name, dest_path)
  85                         except:
  86                             print("Couldn't create directory %s" % dest_path)
  87         self.all_files = set()
  88 
  89     def auto_create_table(self, table, url=None, filename=None, pk=None):
  90         """Download the file if it doesn't exist"""
  91         if url and not filename:
  92             filename = filename_from_url(url)
  93 
  94         if url and not self.find_file(filename):
  95             # If the file doesn't exist, download it
  96             self.download_file(url, filename)
  97 
  98     def insert_data_from_url(self, url):
  99         """Insert data from a web resource"""
  100         filename = filename_from_url(url)
  101         find = self.find_file(filename)
  102         if not find:
  103             self.create_raw_data_dir()
  104             self.download_file(url, filename)
  105 
  106     def find_file(self, filename):
  107         """Checks for the given file and adds it to the list of all files"""
  108         result = Engine.find_file(self, filename)
  109         if not hasattr(self, "all_files"):
  110             self.all_files = set()
  111         if result:
  112             self.all_files.add(result)
  113         return result
  114 
  115     def register_files(self, filenames):
  116         """Identify a list of files to be moved by the download
  117 
  118         When downloading archives with multiple files the engine needs to be
  119         informed of all of the file names so that it can move them.
  120 
  121         """
  122         full_filenames = {self.find_file(filename) for filename in filenames
  123                           if self.find_file(filename)}
  124         self.all_files = self.all_files.union(full_filenames)
  125 
  126 
  127 # replace all other methods with a function that does nothing
  128 def dummy_method(self, *args, **kwargs):
  129     pass
  130 
  131 
  132 methods = inspect.getmembers(engine, predicate=inspect.ismethod)
  133 keep_methods = {'table_exists',
  134                 'get_connection',
  135                 'final_cleanup',
  136                 'auto_create_table',
  137                 'insert_data_from_url',
  138                 }
  139 remove_methods = ['insert_data_from_file']
  140 for name, method in methods:
  141     if (name not in keep_methods and
  142             'download' not in name and
  143             'file' not in name and
  144             'dir' not in name):
  145         setattr(engine, name, dummy_method)
  146 for name in remove_methods:
  147     setattr(engine, name, dummy_method)
  148
  [end of engines/download_only.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/engines/download_only.py b/engines/download_only.py
  --- a/engines/download_only.py
  +++ b/engines/download_only.py
  @@ -66,7 +66,9 @@
                   file_path, file_name_nopath = os.path.split(file_name)
                   subdir = os.path.split(file_path)[1] if self.opts['subdir'] else ''
                   dest_path = os.path.join(self.opts['path'], subdir)
  -                if os.path.abspath(file_path) == os.path.abspath(os.path.join(DATA_DIR, subdir)):
  +                if os.path.isfile(os.path.join(dest_path, file_name_nopath)):
  +                    print ("File already exists at specified location")
  +                elif os.path.abspath(file_path) == os.path.abspath(os.path.join(DATA_DIR, subdir)):
                       print ("%s is already in the working directory" %
                              file_name_nopath)
                       print("Keeping existing copy.")
  
verification_info: {"golden_diff": "diff --git a/engines/download_only.py b/engines/download_only.py\n--- a/engines/download_only.py\n+++ b/engines/download_only.py\n@@ -66,7 +66,9 @@\n                 file_path, file_name_nopath = os.path.split(file_name)\n                 subdir = os.path.split(file_path)[1] if self.opts['subdir'] else ''\n                 dest_path = os.path.join(self.opts['path'], subdir)\n-                if os.path.abspath(file_path) == os.path.abspath(os.path.join(DATA_DIR, subdir)):\n+                if os.path.isfile(os.path.join(dest_path, file_name_nopath)):\n+                    print (\"File already exists at specified location\")\n+                elif os.path.abspath(file_path) == os.path.abspath(os.path.join(DATA_DIR, subdir)):\n                     print (\"%s is already in the working directory\" %\n                            file_name_nopath)\n                     print(\"Keeping existing copy.\")\n", "issue": "download_only w/path fails to use path argument when checking for file\nWhen `download_only` checks to see if the file already exists before copying it, it ignores the path argument. This means that:\n\n```\nretriever download MoM2003 -p testdata\n```\n\nwill keep overwriting the file in `testdata` if it exists, and it will not copy the file to `testdata` if the file exists in `.`.\n\nFixes this is probably just a little logic improvement in the `final_cleanup` function of `download_only`.\n\n", "before_files": [{"content": "from __future__ import print_function\nfrom builtins import object\nimport os\nimport platform\nimport shutil\nimport inspect\n\nfrom retriever.lib.engine import filename_from_url\nfrom retriever.lib.models import Engine, no_cleanup\nfrom retriever import DATA_DIR, HOME_DIR\n\n\nclass DummyConnection(object):\n\n    def cursor(self):\n        pass\n\n    def commit(self):\n        pass\n\n    def rollback(self):\n        pass\n\n    def close(self):\n        pass\n\n\nclass DummyCursor(DummyConnection):\n    pass\n\n\nclass engine(Engine):\n    \"\"\"Engine instance for writing data to a CSV file.\"\"\"\n    name = \"Download Only\"\n    abbreviation = \"download\"\n    required_opts = [(\"path\",\n                      \"File path to copy data files\",\n                      \"./\"),\n                     (\"subdir\",\n                      \"Keep the subdirectories for archived files\",\n                      False)\n                     ]\n\n    def table_exists(self, dbname, tablename):\n        \"\"\"Checks if the file to be downloaded already exists\"\"\"\n        try:\n            tablename = self.table_name(name=tablename, dbname=dbname)\n            return os.path.exists(tablename)\n        except:\n            return False\n\n    def get_connection(self):\n        \"\"\"Gets the db connection.\"\"\"\n        self.get_input()\n        return DummyConnection()\n\n    def final_cleanup(self):\n        \"\"\"Copies downloaded files to desired directory\n\n        Copies the downloaded files into the chosen directory unless files with the same\n        name already exist in the directory.\n\n        \"\"\"\n        if hasattr(self, \"all_files\"):\n            for file_name in self.all_files:\n                file_path, file_name_nopath = os.path.split(file_name)\n                subdir = os.path.split(file_path)[1] if self.opts['subdir'] else ''\n                dest_path = os.path.join(self.opts['path'], subdir)\n                if os.path.abspath(file_path) == os.path.abspath(os.path.join(DATA_DIR, subdir)):\n                    print (\"%s is already in the working directory\" %\n                           file_name_nopath)\n                    print(\"Keeping existing copy.\")\n                else:\n                    print(\"Copying %s from %s\" % (file_name_nopath, file_path))\n                    if os.path.isdir(dest_path):\n                        try:\n                            shutil.copy(file_name, dest_path)\n                        except:\n                            print(\"Couldn't copy file to %s\" % dest_path)\n                    else:\n                        try:\n                            print(\"Creating directory %s\" % dest_path)\n                            os.makedirs(dest_path)\n                            shutil.copy(file_name, dest_path)\n                        except:\n                            print(\"Couldn't create directory %s\" % dest_path)\n        self.all_files = set()\n\n    def auto_create_table(self, table, url=None, filename=None, pk=None):\n        \"\"\"Download the file if it doesn't exist\"\"\"\n        if url and not filename:\n            filename = filename_from_url(url)\n\n        if url and not self.find_file(filename):\n            # If the file doesn't exist, download it\n            self.download_file(url, filename)\n\n    def insert_data_from_url(self, url):\n        \"\"\"Insert data from a web resource\"\"\"\n        filename = filename_from_url(url)\n        find = self.find_file(filename)\n        if not find:\n            self.create_raw_data_dir()\n            self.download_file(url, filename)\n\n    def find_file(self, filename):\n        \"\"\"Checks for the given file and adds it to the list of all files\"\"\"\n        result = Engine.find_file(self, filename)\n        if not hasattr(self, \"all_files\"):\n            self.all_files = set()\n        if result:\n            self.all_files.add(result)\n        return result\n\n    def register_files(self, filenames):\n        \"\"\"Identify a list of files to be moved by the download\n\n        When downloading archives with multiple files the engine needs to be\n        informed of all of the file names so that it can move them.\n\n        \"\"\"\n        full_filenames = {self.find_file(filename) for filename in filenames\n                          if self.find_file(filename)}\n        self.all_files = self.all_files.union(full_filenames)\n\n\n# replace all other methods with a function that does nothing\ndef dummy_method(self, *args, **kwargs):\n    pass\n\n\nmethods = inspect.getmembers(engine, predicate=inspect.ismethod)\nkeep_methods = {'table_exists',\n                'get_connection',\n                'final_cleanup',\n                'auto_create_table',\n                'insert_data_from_url',\n                }\nremove_methods = ['insert_data_from_file']\nfor name, method in methods:\n    if (name not in keep_methods and\n            'download' not in name and\n            'file' not in name and\n            'dir' not in name):\n        setattr(engine, name, dummy_method)\nfor name in remove_methods:\n    setattr(engine, name, dummy_method)\n", "path": "engines/download_only.py"}]}