示例#1
0
 def action_delete(self, records):
     # emit a signal, with a set of songs to delete
     # these songs must be addded to a set so that undo delete
     # can be implemented.
     # display a warning message before emiting any signal
     History.instance().delete(records)
     self.parent().refresh()
     self.setSelection([])
示例#2
0
    def doTask(self):

        hist = History.instance().reopen()

        ts = int(
            (datetime.datetime.now() - datetime.timedelta(28)).timestamp())

        records = []
        page_size = 500
        result = self.client.history_get(hist, ts, None, 0, page_size)
        records += result

        page = 1
        num_pages = 20
        while len(result) > 0 and page < 20:
            p = 90.0 * (page + 1) / num_pages
            self.setProgress(p)
            result = self.client.history_get(hist, ts, None, page, page_size)
            records += result
            page += 1

        print("num history pages: %d" % page)
        print("num history records: %d" % len(records))

        title = "Import History"
        message = "Import %d records?" % len(records)
        options = ["cancel", "ok"]
        i = self.getInput(title, message, options)

        if i > 0:
            #hist = History.instance().reopen()
            # hist._import(records)
            lib = Library.instance().reopen()
            lib.import_record(records)
示例#3
0
    def run_search(self, text, setText=False, refresh=False):
        """
        setText: if true set the text box to contain text
        """
        try:
            hist = History.instance()
            rule = hist.grammar.ruleFromString(text)
            # set a default limit to improve performace for large data sets
            # large is > 50,000 records
            limit = hist.grammar.getMetaValue("limit", 500)
            offset = hist.grammar.getMetaValue("offset", 0)

            action = self.cbox_action.currentData()
            if action is not None:
                rule = AndSearchRule.join(rule,
                                          ExactSearchRule("column", action))

            data = hist.search(rule, \
                orderby = self.tbl_history.sort_orderby,
                reverse = self.tbl_history.sort_reverse,
                limit=limit, offset=offset )
            self.tbl_history.setData(data)

            self.txt_search.setStyleSheet("")
            self.lbl_search.setText("%d/%d" % (len(data), len(hist)))
            self.lbl_error.hide()

        except ParseError as e:
            self.txt_search.setStyleSheet("background: #CC0000;")
            self.lbl_error.setText("%s" % e)
            self.lbl_error.show()
        except Exception as e:
            raise e
示例#4
0
    def doTask(self):
        hist = History.instance().reopen()
        ts = int(
            (datetime.datetime.now() - datetime.timedelta(28)).timestamp())

        rule = AndSearchRule([
            ExactSearchRule("column", "playtime"),
            GreaterThanEqualSearchRule("date", ts, type_=int)
        ])

        print(rule)
        # get all records in the local database
        records = hist.export(rule)

        self.client.history_put(records)
示例#5
0
def test_history_export():

    # db_path = "/Users/nsetzer/Music/Library/yue.db"
    db_path = "D:\\Dropbox\\ConsolePlayer\\yue.db"
    sqlstore = SQLStore(db_path)
    History.init(sqlstore)

    ts = int((datetime.datetime.now() - datetime.timedelta(28)).timestamp())

    rule = AndSearchRule([
        ExactSearchRule("column", "playtime"),
        GreaterThanEqualSearchRule("date", ts, type_=int)
    ])
    # get all records in the local database
    records = History.instance().export(rule)

    print(records)
示例#6
0
def test_history(songs, api, apiw):

    songs = list(apiw.songs.values())
    with open("songs.JSON", "w") as wf:
        wf.write(json.dumps(songs))

    ts = int((datetime.datetime.now() - datetime.timedelta(28)).timestamp())

    rule = AndSearchRule([
        ExactSearchRule("column", "playtime"),
        GreaterThanEqualSearchRule("date", ts, type_=int)
    ])
    # get all records in the local database
    records = History.instance().export(rule)

    # add these records to the remote database
    apiw.history_put(records)

    # get all records from remote, that are not in the local db
    r = apiw.history_get()

    print("found %d records " % len(r))
    print(r[:5])