Exemple #1
0
 def hide_user_config():
     """Moves the user's config file, if it exists, to make it unreachable.
     """
     DataFile.ensure_path(Config.PATH)
     if os.path.exists(Config.PATH):
         os.rename(Config.PATH, Config.PATH + ".tmp")
     copyfile(Config.DEFAULT_PATH, Config.PATH)
Exemple #2
0
    def download(self, download_queue, display=None):
        """Downloads this episode to the file system.

        This method currently only supports downloading from an external URL.
        In the future, it may be worthwhile to determine whether the episode's
        source is a local file and simply copy it instead.

        Args:
            download_queue: the download_queue overseeing this download
            display: (optional) the display to write status updates to
        """
        if self._enclosure is None:
            if display is not None:
                display.change_status("Download failed: episode does not have"
                                      " a valid media source")
            return

        feed_directory = self._feed_directory()
        episode_partial_filename = helpers.sanitize_path(str(self))
        extension = os.path.splitext(self._enclosure)[1].split('?')[0]
        output_path = os.path.join(feed_directory,
                                   episode_partial_filename + str(extension))
        DataFile.ensure_path(output_path)

        if display is not None:
            display.change_status("Starting episode download...")

        t = threading.Thread(target=DataFile.download_to_file,
                             args=[
                                 self._enclosure, output_path,
                                 str(self), download_queue, display
                             ],
                             name="download_%s" % str(self))
        t.start()
Exemple #3
0
    def __init__(self):
        """
        If the database file does not exist but the old Feeds file does, we
        create the database using the old format.
        """
        existed = os.path.exists(self.PATH)
        DataFile.ensure_path(self.PATH)

        self._using_memory = not helpers.is_true(
            Config["restrict_memory_usage"])

        file_conn = sqlite3.connect(self.PATH, check_same_thread=False)
        file_conn.execute("PRAGMA foreign_keys = ON")

        if self._using_memory:
            memory_conn = sqlite3.connect(":memory:", check_same_thread=False)
            self._copy_database(file_conn, memory_conn)
            self._conn = memory_conn
        else:
            self._conn = file_conn

        if not existed and os.path.exists(self.OLD_PATH):
            self._create_from_old_feeds()

        self.migrate()
Exemple #4
0
 def hide_user_feeds():
     """Moves the user's feeds file, if it exists, to make it unreachable.
     """
     DataFile.ensure_path(Feeds.PATH)
     if os.path.exists(Feeds.PATH):
         os.rename(Feeds.PATH, Feeds.PATH + ".tmp")
     copyfile(Feeds.DEFAULT_PATH, Feeds.PATH)
Exemple #5
0
 def restore_user_database():
     """Restores the user's database files if they have been hidden."""
     DataFile.ensure_path(Database.PATH)
     DataFile.ensure_path(Database.OLD_PATH)
     if os.path.exists(Database.PATH + ".tmp"):
         os.rename(Database.PATH + ".tmp", Database.PATH)
     if os.path.exists(Database.OLD_PATH + ".tmp"):
         os.rename(Database.OLD_PATH + ".tmp", Database.OLD_PATH)
Exemple #6
0
 def hide_user_database():
     """Moves the user's database files to make them unreachable."""
     DataFile.ensure_path(Database.PATH)
     DataFile.ensure_path(Database.OLD_PATH)
     if os.path.exists(Database.PATH):
         os.rename(Database.PATH, Database.PATH + ".tmp")
     if os.path.exists(Database.OLD_PATH):
         os.rename(Database.OLD_PATH, Database.OLD_PATH + ".tmp")
Exemple #7
0
def test_datafile_download():
    urls = ["https://google.com", "https://bing.com", "https://amazon.com"]
    attempt = 0
    for url in urls:
        DataFile.download_to_file(url, "datafile_download_temp")
        r = requests.get(urls[attempt])
        if r.status_code == 200:
            break
    assert os.path.exists("datafile_download_temp")
    os.remove("datafile_download_temp")
Exemple #8
0
    def __init__(self):
        existed = os.path.exists(self.PATH)
        DataFile.ensure_path(self.PATH)
        self._conn = sqlite3.connect(self.PATH, check_same_thread=False)
        self._conn.execute("PRAGMA foreign_keys = ON")

        if not existed and os.path.exists(self.OLD_PATH):
            self._create_from_old_feeds()

        self.migrate()
Exemple #9
0
    def close(self):
        """Close the database.

        If we were using an in-memory copy of the data, it is written
        to the database file here.
        """
        if self._using_memory:
            DataFile.ensure_path(self.PATH)
            os.rename(self.PATH, self.PATH + ".old")

            file_conn = sqlite3.connect(self.PATH)
            self._copy_database(self._conn, file_conn)
        self._conn.close()
Exemple #10
0
def test_datafile_download_bad_url(display):
    display.change_status = mock.MagicMock(name="change_status")
    mydownloadqueue = DownloadQueue()
    url = "https://bad"
    DataFile.download_to_file(url,
                              "datafile_download_temp",
                              "datafile download name",
                              mydownloadqueue,
                              display=display)
    while mydownloadqueue.length > 0:
        pass
    assert display.change_status.call_count > 0
    assert not os.path.exists("datafile_download_temp")
Exemple #11
0
    def __init__(self):
        """
        If the database file does not exist but the old Feeds file does, we
        create the database using the old format.
        """
        existed = os.path.exists(self.PATH)
        DataFile.ensure_path(self.PATH)
        self._conn = sqlite3.connect(self.PATH, check_same_thread=False)
        self._conn.execute("PRAGMA foreign_keys = ON")

        if not existed and os.path.exists(self.OLD_PATH):
            self._create_from_old_feeds()

        self.migrate()
Exemple #12
0
 def restore_user_feeds():
     """Restores the user's feeds file if it has been hidden."""
     DataFile.ensure_path(Feeds.PATH)
     if os.path.exists(Feeds.PATH + ".tmp"):
         os.rename(Feeds.PATH + ".tmp", Feeds.PATH)
Exemple #13
0
 def restore_user_config():
     """Restores the user's config file if it has been hidden."""
     DataFile.ensure_path(Config.PATH)
     if os.path.exists(Config.PATH + ".tmp"):
         os.rename(Config.PATH + ".tmp", Config.PATH)