def test_instantiate_from_existing_folder(self):
     """Downloader can instantiate self from an existing folder if that folder has a thread_details.pkl file that it can load,
     and optionally, an ignore list text file, or a few already downloaded files. As long as the thread_details.pkl
     file exists, it is ok to instantiate one from a directory."""
     downloader = BatchDownloader.from_directory(self.existing_directory)
     self.assertIsNotNone(downloader)
     self.assertIsNotNone(downloader.links_retriever)
     self.assertIsNotNone(downloader.ifilter)
Esempio n. 2
0
 def cli_synchronise_to_directory(self, args):
     res = None
     try:
         downloader = BatchDownloader.from_directory(args.dir)
         self.downloader_start(downloader)
         self.recent_threads_add(downloader)
         res = downloader.destination_folder
     except (ValueError, FileNotFoundError) as err:
         print('[Removing from recent]:', err)
         self.recent_threads.remove(args.dir)
     finally:
         self.save_config()
     return res
Esempio n. 3
0
    def cli_synchronise_recent_threads(self, args):
        pop_list = set()
        for thread_dir in self.recent_threads:
            if not os.path.exists(thread_dir):
                pop_list.add(thread_dir)
                continue

            try:
                downloader = BatchDownloader.from_directory(thread_dir)
                self.downloader_start(downloader)
                if downloader.links_retriever.thread_is_dead():
                    pop_list.add(thread_dir)
            except (
                    ValueError, FileNotFoundError
            ) as err:  # LinksRetriever raises a ValueError when a thread has 404'd, or thread pickle detail doesn't exist.
                print('[Removing from recent]', err)
                pop_list.add(thread_dir)

        self.recent_threads = list((os.path.abspath(thread_dir)
                                    for thread_dir in self.recent_threads
                                    if thread_dir not in pop_list))
        self.save_config()

        return self.recent_threads
 def test_attempt_to_instantiate_on_directory_without_pickle_file(self):
     tempdir = TemporaryDirectory(dir=TMP_DIRECTORY)
     with self.assertRaises(FileNotFoundError):
         downloader = BatchDownloader.from_directory(tempdir.name)
 def test_num_downloaded(self):
     downloader = BatchDownloader.from_directory(self.existing_directory)
     downloaded = downloader.get_files_downloaded()
     self.assertEqual(len(downloaded), self.num_files_to_download)