예제 #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 test_history_export3(self):
        """
        show that export returns in the correct order
        """
        if os.path.exists(DB_PATH):
            os.remove(DB_PATH)

        sqlstore = SQLStore(DB_PATH)

        lib = Library(sqlstore)
        h = History(sqlstore)

        h.setLogEnabled(True)
        h.setUpdateEnabled(True)
        lib.history = h

        date = timegm(time.localtime(time.time()))

        dates = [date, date + 2, date + 4]
        uid = 0

        with h.sqlstore.conn:
            c = h.sqlstore.conn.cursor()
            for d in dates:
                h.incrementPlaycount(c, uid, d)

        records = list(h.export())
        self.assertEqual(len(records), 3)
        for d, r in zip(dates, records):
            self.assertEqual(r['date'], d)
예제 #3
0
    def test_history_export(self):

        if os.path.exists(DB_PATH):
            os.remove(DB_PATH)

        sqlstore = SQLStore(DB_PATH)

        lib = Library(sqlstore)
        h = History(sqlstore)

        h.setLogEnabled(True)
        h.setUpdateEnabled(True)
        lib.history = h

        date = timegm(time.localtime(time.time()))

        uid = 0

        with h.sqlstore.conn:
            c = h.sqlstore.conn.cursor()
            h.incrementPlaycount(c, uid, date)

        records = list(h.export())
        self.assertEqual(len(records), 1)
        record = records[0]
        self.assertEqual(record['uid'], uid)
        self.assertEqual(record['date'], date)
        self.assertEqual(record['column'], Song.playtime)
예제 #4
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)
예제 #5
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
예제 #6
0
    def step(self, idx):

        dbpath = os.path.join(os.getcwd(), "remote.db")
        if not isinstance(self.parent.target_source, DirectorySource):
            # target is not a local directory
            tgtdb = self.parent.getTargetLibraryPath()
            self.parent.log("remote db path: %s" % tgtdb)
            if self.parent.target_source.exists(tgtdb):
                #with self.parent.target_source.open(tgtdb,"rb") as rb:
                #    with self.parent.local_source.open(dbpath,"wb") as wb:
                #        wb.write(rb.read())
                source_copy_file(self.parent.target_source, tgtdb,
                                 self.parent.local_source, dbpath)
        else:
            dbpath = self.parent.getTargetLibraryPath()

        self.remote_path = dbpath

        self.parent.log("db local path: %s %s" %
                        (dbpath, os.path.exists(dbpath)))

        if not self.parent.local_source.exists(dbpath):
            self.parent.log("import history: no database")
            return

        remote_store = SQLStore(dbpath)
        remote_history = History(remote_store)
        local_history = History(self.parent.library.sqlstore)

        size = remote_history.size()
        self.parent.log("import history: num records %d" % size)

        if self.no_exec or size == 0:
            self.parent.log("import history: nothing to do")
            return

        self.execute = self.parent.getYesOrNo("Import %d records?" % size,
                                              btn2="import")

        if not self.execute:
            return

        conn = self.parent.library.sqlstore.conn
        with conn:
            c = conn.cursor()
            for record in remote_history.export():
                self.parent.library._import_record(c, record)
예제 #7
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)
예제 #8
0
    def test_history_export2(self):

        if os.path.exists(DB_PATH):
            os.remove(DB_PATH)

        sqlstore = SQLStore(DB_PATH)

        lib = Library(sqlstore)
        h = History(sqlstore)

        h.setLogEnabled(True)
        h.setUpdateEnabled(True)
        lib.history = h

        uid = lib.insert(artist="artist1",
                         album='album1',
                         title='title1',
                         path='/path')

        lib.incrementPlaycount(uid)

        records = list(h.export())
        self.assertEqual(len(records), 1)
        record = records[0]
        self.assertEqual(record['uid'], uid)
        self.assertEqual(record['column'], Song.playtime)
예제 #9
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)
예제 #10
0
def _connect():

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

    username = "******"
    apikey = "f45596be-5355-4cef-bd00-fb63f872b140"

    songs = Library.instance().search("beast")
    song = songs[0]

    api = ApiClient("http://localhost:4200")
    user = api.login("admin", "admin")
    print(user)
    api.setApiUser(username)
    api.setApiKey(user['apikey'])
    apiw = ApiClientWrapper(api)

    songs = apiw.connect()

    return songs, api, apiw
예제 #11
0
    def test_history_import_playback(self):

        if os.path.exists(DB_PATH):
            os.remove(DB_PATH)

        sqlstore = SQLStore(DB_PATH)

        lib = Library(sqlstore)
        h = History(sqlstore)

        h.setLogEnabled(True)
        h.setUpdateEnabled(True)
        lib.history = h

        uid = lib.insert(artist="artist1",
                         album='album1',
                         title='title1',
                         path='/path',
                         last_played=100000)

        songb = lib.songFromId(uid)

        record = {
            'date': 50000,
            'uid': uid,
            'column': Song.playtime,
            'value': None
        }

        lib.import_record(record)

        songa = lib.songFromId(uid)

        self.assertEqual(songa[Song.last_played], songb[Song.last_played])
        self.assertEqual(songa[Song.play_count], 1 + songb[Song.play_count])

        new_date = 300000
        record['date'] = new_date
        lib.import_record(record)

        songa = lib.songFromId(uid)

        self.assertNotEqual(songa[Song.frequency], 0)
        self.assertEqual(songa[Song.last_played], new_date)
        self.assertEqual(songa[Song.play_count], 2 + songb[Song.play_count])
예제 #12
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])
예제 #13
0
    def test_history_import_update_int(self):
        """
        create a song, then a record which will update the
        rating

        import the record and verify that the artist name was changed
        successfully
        """
        if os.path.exists(DB_PATH):
            os.remove(DB_PATH)

        sqlstore = SQLStore(DB_PATH)

        lib = Library(sqlstore)
        h = History(sqlstore)

        h.setLogEnabled(True)
        h.setUpdateEnabled(True)
        lib.history = h

        rate1 = 5
        rate2 = 10
        uid = lib.insert(artist="artist1",
                         album='album1',
                         title='title1',
                         rating=rate1,
                         path='/path')

        songb = lib.songFromId(uid)

        record = {
            'date': 0,
            'uid': uid,
            'column': Song.rating,
            'value': "%s" % rate2
        }

        lib.import_record(record)

        songa = lib.songFromId(uid)

        self.assertNotEqual(songb[Song.rating], songa[Song.rating])
        self.assertEqual(songa[Song.rating], rate2)