prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  download command should probably fail when specified path does not exist
  A datsaet can be downloaded to a specific path with the function `download` while specifying the -p argument. For example `retriever download MCDB -p my_path` will download each of the MCDB files and then copy them to the directory my_path but if my_path does not exist a file called my_path is created and the files overwrite that file as each is copied from the download directory. It may be best if the retriever fails with a warning that the path does not exist. 
  
  
  </issue>
  <code>
  [start of engines/download_only.py]
  1 import os
  2 import platform
  3 import shutil
  4 import inspect
  5 from retriever.lib.engine import filename_from_url
  6 from retriever.lib.models import Engine, no_cleanup
  7 from retriever import DATA_DIR, HOME_DIR
  8 
  9 class DummyConnection:
  10     def cursor(self):
  11         pass
  12     def commit(self):
  13         pass
  14     def rollback(self):
  15         pass
  16     def close(self):
  17         pass
  18 
  19 class DummyCursor(DummyConnection):
  20     pass
  21 
  22 
  23 class engine(Engine):
  24     """Engine instance for writing data to a CSV file."""
  25     name = "Download Only"
  26     abbreviation = "download"
  27     required_opts = [("path",
  28                       "File path to copy data files",
  29                       "./"),
  30                      ]
  31 
  32     def table_exists(self, dbname, tablename):
  33         try:
  34             tablename = self.table_name(name=tablename, dbname=dbname)
  35             return os.path.exists(tablename)
  36         except:
  37             return False
  38 
  39     def get_connection(self):
  40         """Gets the db connection."""
  41         self.get_input()
  42         return DummyConnection()
  43 
  44     def final_cleanup(self):
  45         data_dir = self.format_data_dir()
  46         if hasattr(self, "all_files"):
  47             for file_name in self.all_files:
  48                 file_path, file_name_nopath = os.path.split(file_name)
  49                 if file_path == DATA_DIR:
  50                     print ("%s is already in the working directory" % file_name_nopath)
  51                     print("Keeping existing copy.")
  52                 else:
  53                     print("Copying %s from %s" % (file_name_nopath, file_path))
  54                     shutil.copy(file_name, self.opts['path'])
  55         self.all_files = set()
  56 
  57     def auto_create_table(self, table, url=None, filename=None, pk=None):
  58         if url and not filename:
  59             filename = filename_from_url(url)
  60 
  61         if url and not self.find_file(filename):
  62             # If the file doesn't exist, download it
  63             self.download_file(url, filename)
  64 
  65     def insert_data_from_url(self, url):
  66         filename = filename_from_url(url)
  67         find = self.find_file(filename)
  68         if not find:
  69             self.create_raw_data_dir()
  70             self.download_file(url, filename)
  71 
  72     def find_file(self, filename):
  73         result = Engine.find_file(self, filename)
  74         if not hasattr(self, "all_files"): self.all_files = set()
  75         if result: self.all_files.add(result)
  76         return result
  77 
  78     def register_files(self, filenames):
  79         """Identify a list of files to be moved by the download
  80 
  81         When downloading archives with multiple files the engine needs to be
  82         informed of all of the file names so that it can move them.
  83 
  84         """
  85         full_filenames = {self.find_file(filename) for filename in filenames}
  86         self.all_files = self.all_files.union(full_filenames)
  87 
  88 
  89 # replace all other methods with a function that does nothing
  90 def dummy_method(self, *args, **kwargs):
  91     pass
  92 methods = inspect.getmembers(engine, predicate=inspect.ismethod)
  93 keep_methods = {'table_exists',
  94                 'get_connection',
  95                 'final_cleanup',
  96                 'auto_create_table',
  97                 'insert_data_from_url',
  98                 }
  99 remove_methods = ['insert_data_from_file']
  100 for name, method in methods:
  101     if (not name in keep_methods
  102         and not 'download' in name
  103         and not 'file' in name
  104         and not 'dir' in name):
  105 
  106         setattr(engine, name, dummy_method)
  107 for name in remove_methods:
  108     setattr(engine, name, dummy_method)
  109
  [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
  @@ -51,7 +51,18 @@
                       print("Keeping existing copy.")
                   else:
                       print("Copying %s from %s" % (file_name_nopath, file_path))
  -                    shutil.copy(file_name, self.opts['path'])
  +                    if os.path.isdir(self.opts['path']):
  +                        try:
  +                            shutil.copy(file_name, self.opts['path'])
  +                        except:
  +                            print("Couldn't copy file to %s" % self.opts['path'])
  +                    else:
  +                        try:
  +                            print("Creating directory %s" % self.opts['path'])
  +                            os.mkdir(self.opts['path'])
  +                            shutil.copy(file_name, self.opts['path'])
  +                        except:
  +                            print("Couldn't create directory %s" % self.opts['path'])
           self.all_files = set()
   
       def auto_create_table(self, table, url=None, filename=None, pk=None):
  
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@@ -51,7 +51,18 @@\n                     print(\"Keeping existing copy.\")\n                 else:\n                     print(\"Copying %s from %s\" % (file_name_nopath, file_path))\n-                    shutil.copy(file_name, self.opts['path'])\n+                    if os.path.isdir(self.opts['path']):\n+                        try:\n+                            shutil.copy(file_name, self.opts['path'])\n+                        except:\n+                            print(\"Couldn't copy file to %s\" % self.opts['path'])\n+                    else:\n+                        try:\n+                            print(\"Creating directory %s\" % self.opts['path'])\n+                            os.mkdir(self.opts['path'])\n+                            shutil.copy(file_name, self.opts['path'])\n+                        except:\n+                            print(\"Couldn't create directory %s\" % self.opts['path'])\n         self.all_files = set()\n \n     def auto_create_table(self, table, url=None, filename=None, pk=None):\n", "issue": "download command should probably fail when specified path does not exist\nA datsaet can be downloaded to a specific path with the function `download` while specifying the -p argument. For example `retriever download MCDB -p my_path` will download each of the MCDB files and then copy them to the directory my_path but if my_path does not exist a file called my_path is created and the files overwrite that file as each is copied from the download directory. It may be best if the retriever fails with a warning that the path does not exist. \n\n", "before_files": [{"content": "import os\nimport platform\nimport shutil\nimport inspect\nfrom retriever.lib.engine import filename_from_url\nfrom retriever.lib.models import Engine, no_cleanup\nfrom retriever import DATA_DIR, HOME_DIR\n\nclass DummyConnection:\n    def cursor(self):\n        pass\n    def commit(self):\n        pass\n    def rollback(self):\n        pass\n    def close(self):\n        pass\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                     ]\n\n    def table_exists(self, dbname, tablename):\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        data_dir = self.format_data_dir()\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                if file_path == DATA_DIR:\n                    print (\"%s is already in the working directory\" % file_name_nopath)\n                    print(\"Keeping existing copy.\")\n                else:\n                    print(\"Copying %s from %s\" % (file_name_nopath, file_path))\n                    shutil.copy(file_name, self.opts['path'])\n        self.all_files = set()\n\n    def auto_create_table(self, table, url=None, filename=None, pk=None):\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        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        result = Engine.find_file(self, filename)\n        if not hasattr(self, \"all_files\"): self.all_files = set()\n        if result: 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        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\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 (not name in keep_methods\n        and not 'download' in name\n        and not 'file' in name\n        and not 'dir' in name):\n\n        setattr(engine, name, dummy_method)\nfor name in remove_methods:\n    setattr(engine, name, dummy_method)\n", "path": "engines/download_only.py"}]}