def download_files_if_not_in_manifest(files_iterator, output_path):
    """Download the given files to the given path, unless in manifest."""
    local_manifest = read_local_manifest(output_path)
    with open(get_local_manifest_path(output_path), 'a') as manifest_fh:
        for (file_name, width) in files_iterator:
            if is_file_in_manifest(file_name, width, local_manifest):
                logging.info('Skipping file %s', file_name)
                continue
            try:
                download_file(file_name, output_path, width=width)
                write_file_to_manifest(file_name, width, manifest_fh)
            except DownloadException as e:
                logging.error("Could not download %s: %s", file_name,
                              e.message)
Ejemplo n.º 2
0
 def test_download_file_with_non_existing_file(self):
     """Test download_file with a non-existing file."""
     input_value = ('UnexistingExample.jpg', 100)
     with self.assertRaises(thumbnaildownload.FileDoesNotExistException):
         _ = thumbnaildownload.download_file(input_value[0],
                                             self.tmpdir1,
                                             width=input_value[1])
 def setUpClass(cls):
     """Set up the TestCase with the data files."""
     cls.outputfile1 = join(dirname(__file__), 'data', 'Example-100.jpg')
     cls.outputfile2 = join(dirname(__file__), 'data', 'Example-50.jpg')
     cls.tmpdir1 = tempfile.mkdtemp()
     cls.tmpdir2 = tempfile.mkdtemp()
     values = [('Example.jpg', cls.tmpdir1, 100),
               ('Example.jpg', cls.tmpdir2, 50)]
     cls.outputs = [thumbnaildownload.download_file(*input_value)
                     for input_value in values]
     cls.expected = [cls.outputfile1, cls.outputfile2]
Ejemplo n.º 4
0
 def setUpClass(cls):
     """Set up the TestCase with the data files."""
     cls.outputfile1 = join(dirname(__file__), 'data', 'Example-100.jpg')
     cls.outputfile2 = join(dirname(__file__), 'data', 'Example-50.jpg')
     cls.outputfile3 = join(dirname(__file__), 'data', 'Example.jpg')
     cls.tmpdir1 = tempfile.mkdtemp()
     cls.tmpdir2 = tempfile.mkdtemp()
     cls.tmpdir3 = tempfile.mkdtemp()
     values = [('Example.jpg', cls.tmpdir1, 100),
               ('Example.jpg', cls.tmpdir2, 50),
               ('Example.jpg', cls.tmpdir3, 1000)]
     cls.outputs = [
         thumbnaildownload.download_file(*input_value)
         for input_value in values
     ]
     cls.expected = [cls.outputfile1, cls.outputfile2, cls.outputfile3]
 def test_download_file_with_non_existing_file(self):
     """Test download_file with a non-existing file."""
     input_value = ('UnexistingExample.jpg', 100)
     with self.assertRaises(thumbnaildownload.FileDoesNotExistException):
         _ = thumbnaildownload.download_file(input_value[0], self.tmpdir1, width=input_value[1])