Esempio n. 1
0
File: s3.py Progetto: ying-w/stor
    def download_object(self, dest, config=None, **kwargs):
        """
        Downloads a file from S3 to a destination file.

        Args:
            dest (str): The destination path to download file to.

        Notes:
            - The destination directory will be created automatically if it doesn't exist.

            - This method downloads to paths relative to the current
              directory.
        """
        result = {'source': self, 'dest': dest, 'success': True}
        if utils.has_trailing_slash(self):
            # Handle directory markers separately
            utils.make_dest_dir(str(dest))
            return result

        dl_kwargs = {
            'bucket': self.bucket,
            'key': str(self.resource),
            'filename': str(dest),
            'config': config
        }
        utils.make_dest_dir(self.parts_class(dest).parent)
        try:
            self._make_s3_transfer('download_file', **dl_kwargs)
        except exceptions.RemoteError as e:
            result['success'] = False
            result['error'] = e
        return result
Esempio n. 2
0
    def test_make_dest_dir_w_oserror(self):
        with utils.NamedTemporaryDirectory() as tmp_d:
            test_file = os.path.join(tmp_d, 'test_file')
            open(test_file, 'w').close()

            with self.assertRaisesRegexp(OSError, 'File exists'):
                utils.make_dest_dir(test_file)
            self.assertFalse(os.path.isdir(test_file))
Esempio n. 3
0
 def test_make_dest_dir_w_enotdir_error(self):
     with utils.NamedTemporaryDirectory() as tmp_d:
         test_file = os.path.join(tmp_d, 'test_file')
         open(test_file, 'w').close()
         with self.assertRaisesRegexp(OSError,
                                      'already exists as a file') as exc:
             new_dir = os.path.join(test_file, 'test')
             utils.make_dest_dir(new_dir)
         self.assertEquals(exc.exception.errno, errno.ENOTDIR)
         self.assertFalse(os.path.isdir(new_dir))
Esempio n. 4
0
 def test_make_dest_dir_existing(self):
     with utils.NamedTemporaryDirectory() as tmp_d:
         dest_dir = os.path.join(tmp_d, 'test')
         os.mkdir(dest_dir)
         utils.make_dest_dir(dest_dir)
         self.assertTrue(os.path.isdir(dest_dir))