示例#1
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)
示例#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 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)