Ejemplo n.º 1
0
    def save(self, bookmark_file, delimiter=',', silent=False):
        """Bookmarks handling. Saves the bookmarks as
        a csv file.

        :param bookmark_file: filename to load, with full path
        :type bookmark_file: string
        :param delimiter: delimiter to use for creating the csv file,
        defaults to ','
        :type delimiter: string
        :param silent: suppress messagebox
        :type silent: boolean
        :raises : none
        :returns : none
        """

        self.bookmarks.row_list = []
        for item in self.tree.get_children():
            values = self.tree.item(item).get('values')
            values[BM.freq] = str(frequency_pp_parse(values[BM.freq]))
            self.bookmarks.row_list.append(values)
        # Not where we want to do this, and will be fixed with BookmarkSet
        try:
            os.makedirs(os.path.dirname(bookmark_file))
        except IOError:

            logger.info("Error while trying to create bookmark " \
                        "path as {}".format(bookmark_file))
        except OSError:
            logger.info("The bookmark file already exists.")
        self.bookmarks.csv_save(bookmark_file, delimiter)
Ejemplo n.º 2
0
    def _insert_bookmarks(self, bookmarks, silent=False):
        """Method for inserting bookmark data already loaded.

        :param bookmarks: bookmarks to import in the UI
        :type bookmarks: dict
        """

        count = 0
        for line in bookmarks:

            logger.info(line)
            error = False
            if len(line) < LEN_BM:
                line.append("O")
            if frequency_pp_parse(line[BM.freq]) == None:
                error = True
            try:
                line[BM.freq] = frequency_pp(line[BM.freq])
            except ValueError:
                logger.exception("Malformed bookmark in {}"\
                                 " skipping...".format(line))
                continue
            if line[BM.mode] not in CBB_MODES:
                error = True
            if error == True:
                if not silent:
                    tkMessageBox.showerror("Error", "Invalid value in "\
                                           "Bookmark #%i. "\
                                           "Skipping..." %count)
            else:
                item = self.tree.insert('', tk.END, values=line)
                self.bookmark_bg_tag(item, line[BM.lockout])
Ejemplo n.º 3
0
    def _save_gqrx(self, filename):
        """Private method for saving the bookmarks file in csv compatible
        with gqrx bookmark format. It wraps around csv_save method of disk_io
        module.

        :param filename: filename to be saved
        :type filename: string
        """

        for item in self.tree.get_children():
            gqrx_bookmark = []
            values = self.tree.item(item).get('values')
            values[BM.freq] = str(frequency_pp_parse(values[BM.freq]))
            gqrx_bookmark.append(values[0])
            gqrx_bookmark.append(values[2])
            gqrx_bookmark.append(values[1])
            gqrx_bookmark.append("")
            gqrx_bookmark.append("Untagged")
            self.bookmarks.row_list.append(gqrx_bookmark)
        # Not where we want to do this, and will be fixed with BookmarkSet
        try:
            os.makedirs(os.path.dirname(filename))
        except IOError:
            logger.info("Error while trying to create bookmark " \
                        "path as {}".format(filename))
        except OSError:
            logger.info("The bookmark filef already exists.")
        self.bookmarks.row_list.reverse()
        self.bookmarks.csv_save(filename, ";")
Ejemplo n.º 4
0
def test_frequency_pp_parse2():
    freq="2,4"
    pfreq=frequency_pp_parse(freq)
    assert("," not in pfreq)
Ejemplo n.º 5
0
def test_frequency_pp_parse1():
    freq=2
    with pytest.raises(ValueError):
        frequency_pp_parse(freq)