Example #1
0
 def __init__(self, handler, db, rootfs=None):
     self._db = db
     self._changed = []
     db.medialist.connect(self)
     self.udisk = UDisks(handler, db, rootfs)
Example #2
0
 def __init__(self, handler, db, rootfs=None):
     self._db = db
     self._changed = []
     db.medialist.connect(self)
     self.udisk = UDisks(handler, db, rootfs)
Example #3
0
class Controller(object):
    """
    The controller defines the callbacks Item and Media need. On client
    side this is all implemented in the Client class.
    """
    def __init__(self, handler, db, rootfs=None):
        self._db = db
        self._changed = []
        db.medialist.connect(self)
        self.udisk = UDisks(handler, db, rootfs)

    def _beacon_parse(self, item):
        """
        Parse an item
        Called by Item objects
        """
        return parse(self._db, item)

    @kaa.coroutine()
    def _beacon_update_all(self):
        """
        Timed callback to write all changes to the db.
        Called by Item objects
        """
        yield kaa.inprogress(self._db.read_lock)
        changes = self._changed
        self._changed = []
        for item in changes:
            self._db.update_object(item._beacon_id, item._beacon_changes)
            item._beacon_changes = {}
        # commit to update monitors
        self._db.commit()

    def _beacon_update(self, item):
        """
        Mark item as changed to be updated in the db.
        Called by Item objects
        """
        if not self._changed:
            # register timer to do the changes
            kaa.OneShotTimer(self._beacon_update_all).start(0.1)
        self._changed.append(item)

    def query(self, **query):
        """
        Database query.
        Called by Item objects
        """
        return self._db.query(**query)

    @kaa.coroutine()
    def delete_item(self, item):
        """
        Delete an item.
        Called by Item objects
        """
        yield kaa.inprogress(self._db.read_lock)
        self._db.delete_object(item._beacon_id)

    def eject(self, media):
        """
        Eject media
        Called by Media objects
        """
        self.udisk.eject(media)

    def _beacon_media_information(self, media):
        """
        Get media information from the database.
        Called by Media objects
        """
        return self._db.query_media(media)
Example #4
0
class Controller(object):
    """
    The controller defines the callbacks Item and Media need. On client
    side this is all implemented in the Client class.
    """
    def __init__(self, handler, db, rootfs=None):
        self._db = db
        self._changed = []
        db.medialist.connect(self)
        self.udisk = UDisks(handler, db, rootfs)

    def _beacon_parse(self, item):
        """
        Parse an item
        Called by Item objects
        """
        return parse(self._db, item)

    @kaa.coroutine()
    def _beacon_update_all(self):
        """
        Timed callback to write all changes to the db.
        Called by Item objects
        """
        yield kaa.inprogress(self._db.read_lock)
        changes = self._changed
        self._changed = []
        for item in changes:
            self._db.update_object(item._beacon_id, item._beacon_changes)
            item._beacon_changes = {}
        # commit to update monitors
        self._db.commit()

    def _beacon_update(self, item):
        """
        Mark item as changed to be updated in the db.
        Called by Item objects
        """
        if not self._changed:
            # register timer to do the changes
            kaa.OneShotTimer(self._beacon_update_all).start(0.1)
        self._changed.append(item)

    def query(self, **query):
        """
        Database query.
        Called by Item objects
        """
        return self._db.query(**query)

    @kaa.coroutine()
    def delete_item(self, item):
        """
        Delete an item.
        Called by Item objects
        """
        yield kaa.inprogress(self._db.read_lock)
        self._db.delete_object(item._beacon_id)

    def eject(self, media):
        """
        Eject media
        Called by Media objects
        """
        self.udisk.eject(media)

    def _beacon_media_information(self, media):
        """
        Get media information from the database.
        Called by Media objects
        """
        return self._db.query_media(media)