Exemplo n.º 1
0
    def getContentKey(self, timeSlot):
        """
        Get the content key for the hour covering timeSlot.

        :param float timeSlot: The time slot as milliseconds since Jan 1,
          1970 UTC.
        :return: A Blob with the encoded key.
        :rtype: Blob
        :raises ProducerDb.Error: If there is no key covering timeSlot or other
          database error.
        """
        fixedTimeSlot = ProducerDb.getFixedTimeSlot(timeSlot)
        contentKey = None

        try:
            cursor = self._database.cursor()
            cursor.execute("SELECT key FROM contentkeys where timeslot=?",
                           (fixedTimeSlot, ))
            result = cursor.fetchone()
            if result != None:
                contentKey = Blob(bytearray(result[0]), False)
            cursor.close()
        except Exception as ex:
            raise ProducerDb.Error(
                "Sqlite3ProducerDb.getContentKey: SQLite error: " + str(ex))

        if contentKey == None:
            raise ProducerDb.Error(
                "Sqlite3ProducerDb.getContentKey: Cannot get the key from the database"
            )

        return contentKey
Exemplo n.º 2
0
    def hasContentKey(self, timeSlot):
        """
        Check if a content key exists for the hour covering timeSlot.

        :param float timeSlot: The time slot as milliseconds since Jan 1,
          1970 UTC.
        :return: True if there is a content key for timeSlot.
        :rtype: bool
        :raises ProducerDb.Error: For a database error.
        """
        fixedTimeSlot = ProducerDb.getFixedTimeSlot(timeSlot)
        result = False

        try:
            cursor = self._database.cursor()
            cursor.execute("SELECT key FROM contentkeys where timeslot=?",
                           (fixedTimeSlot, ))
            if cursor.fetchone() != None:
                result = True

            cursor.close()
            return result
        except Exception as ex:
            raise ProducerDb.Error(
                "Sqlite3ProducerDb.hasContentKey: SQLite error: " + str(ex))
Exemplo n.º 3
0
    def getContentKey(self, timeSlot):
        """
        Get the content key for the hour covering timeSlot.

        :param float timeSlot: The time slot as milliseconds since Jan 1,
          1970 UTC.
        :return: A Blob with the encoded key.
        :rtype: Blob
        :raises ProducerDb.Error: If there is no key covering timeSlot or other
          database error.
        """
        fixedTimeSlot = ProducerDb.getFixedTimeSlot(timeSlot)
        contentKey = None

        try:
            cursor = self._database.cursor()
            cursor.execute(
              "SELECT key FROM contentkeys where timeslot=?", (fixedTimeSlot, ))
            result = cursor.fetchone()
            if result != None:
                contentKey = Blob(bytearray(result[0]), False)
            cursor.close()
        except Exception as ex:
            raise ProducerDb.Error(
              "Sqlite3ProducerDb.getContentKey: SQLite error: " + str(ex))

        if contentKey == None:
            raise ProducerDb.Error(
              "Sqlite3ProducerDb.getContentKey: Cannot get the key from the database")

        return contentKey
Exemplo n.º 4
0
    def hasContentKey(self, timeSlot):
        """
        Check if a content key exists for the hour covering timeSlot.

        :param float timeSlot: The time slot as milliseconds since Jan 1,
          1970 UTC.
        :return: True if there is a content key for timeSlot.
        :rtype: bool
        :raises ProducerDb.Error: For a database error.
        """
        fixedTimeSlot = ProducerDb.getFixedTimeSlot(timeSlot)
        result = False

        try:
            cursor = self._database.cursor()
            cursor.execute(
              "SELECT key FROM contentkeys where timeslot=?", (fixedTimeSlot, ))
            if cursor.fetchone() != None:
                result = True

            cursor.close()
            return result
        except Exception as ex:
            raise ProducerDb.Error(
              "Sqlite3ProducerDb.hasContentKey: SQLite error: " + str(ex))
Exemplo n.º 5
0
    def deleteContentKey(self, timeSlot):
        """
         Delete the content key for the hour covering timeSlot. If there is no
         key for the time slot, do nothing.

        :param float timeSlot: The time slot as milliseconds since Jan 1,
          1970 UTC.
        :raises ProducerDb.Error: For a database error.
        """
        fixedTimeSlot = ProducerDb.getFixedTimeSlot(timeSlot)

        try:
            cursor = self._database.cursor()
            cursor.execute("DELETE FROM contentkeys WHERE timeslot=?",
                           (fixedTimeSlot, ))
            self._database.commit()
            cursor.close()
        except Exception as ex:
            raise ProducerDb.Error(
                "Sqlite3ProducerDb.deleteContentKey: SQLite error: " + str(ex))
Exemplo n.º 6
0
    def addContentKey(self, timeSlot, key):
        """
        Add key as the content key for the hour covering timeSlot.

        :param float timeSlot: The time slot as milliseconds since Jan 1,
          1970 UTC.
        :param Blob key: The encoded key.
        :raises ProducerDb.Error: If a key for the same hour already exists in
          the database, or other database error.
        """
        fixedTimeSlot = ProducerDb.getFixedTimeSlot(timeSlot)

        try:
            cursor = self._database.cursor()
            cursor.execute(
                "INSERT INTO contentkeys (timeslot, key) values (?, ?)",
                (fixedTimeSlot, sqlite3.Binary(bytearray(key.buf()))))
            self._database.commit()
            cursor.close()
        except Exception as ex:
            raise ProducerDb.Error(
                "Sqlite3ProducerDb.addContentKey: SQLite error: " + str(ex))
Exemplo n.º 7
0
    def deleteContentKey(self, timeSlot):
        """
         Delete the content key for the hour covering timeSlot. If there is no
         key for the time slot, do nothing.

        :param float timeSlot: The time slot as milliseconds since Jan 1,
          1970 UTC.
        :raises ProducerDb.Error: For a database error.
        """
        fixedTimeSlot = ProducerDb.getFixedTimeSlot(timeSlot)

        try:
            cursor = self._database.cursor()
            cursor.execute(
              "DELETE FROM contentkeys WHERE timeslot=?", (fixedTimeSlot, ))
            self._database.commit()
            cursor.close()
        except Exception as ex:
            raise ProducerDb.Error(
              "Sqlite3ProducerDb.deleteContentKey: SQLite error: " + str(ex))
Exemplo n.º 8
0
    def addContentKey(self, timeSlot, key):
        """
        Add key as the content key for the hour covering timeSlot.

        :param float timeSlot: The time slot as milliseconds since Jan 1,
          1970 UTC.
        :param Blob key: The encoded key.
        :raises ProducerDb.Error: If a key for the same hour already exists in
          the database, or other database error.
        """
        fixedTimeSlot = ProducerDb.getFixedTimeSlot(timeSlot)

        try:
            cursor = self._database.cursor()
            cursor.execute(
              "INSERT INTO contentkeys (timeslot, key) values (?, ?)",
              (fixedTimeSlot, sqlite3.Binary(bytearray(key.buf()))))
            self._database.commit()
            cursor.close()
        except Exception as ex:
            raise ProducerDb.Error(
              "Sqlite3ProducerDb.addContentKey: SQLite error: " + str(ex))