예제 #1
0
    def _recurse_availability_up_tree(node):

        available = node.available
        if not node.parent:
            return node
        else:
            parent = node.parent
        Parent = Item.alias()
        children = Item.select().join(Parent, on=(Item.parent == Parent.pk)).where(Item.parent == parent.pk)
        if not available:
            children_available = children.where(Item.available == True).count() > 0
            available = children_available

        total_files = children.aggregate(fn.SUM(Item.total_files))

        child_remote = children.where(((Item.available == False) & (Item.kind != "Topic")) | (Item.kind == "Topic")).aggregate(fn.SUM(Item.remote_size))
        child_on_disk = children.aggregate(fn.SUM(Item.size_on_disk))

        if parent.available != available:
            parent.available = available
        if parent.total_files != total_files:
            parent.total_files = total_files
        # Ensure that the aggregate sizes are not None
        if parent.remote_size != child_remote and child_remote:
            parent.remote_size = child_remote
        # Ensure that the aggregate sizes are not None
        if parent.size_on_disk != child_on_disk and child_on_disk:
            parent.size_on_disk = child_on_disk
        if parent.is_dirty():
            parent.save()
            _recurse_availability_up_tree(parent)

        return node
예제 #2
0
    def _recurse_availability_up_tree(node):

        available = node.available
        if not node.parent:
            return node
        else:
            parent = node.parent
        Parent = Item.alias()
        children = Item.select().join(Parent, on=(Item.parent == Parent.pk)).where(Item.parent == parent.pk)
        if not available:
            children_available = children.where(Item.available == True).count() > 0
            available = children_available

        total_files = children.aggregate(fn.SUM(Item.total_files))

        child_remote = children.where(((Item.available == False) & (Item.kind != "Topic")) | (Item.kind == "Topic")).aggregate(fn.SUM(Item.remote_size))
        child_on_disk = children.aggregate(fn.SUM(Item.size_on_disk))

        if parent.available != available:
            parent.available = available
        if parent.total_files != total_files:
            parent.total_files = total_files
        # Ensure that the aggregate sizes are not None
        if parent.remote_size != child_remote and child_remote:
            parent.remote_size = child_remote
        # Ensure that the aggregate sizes are not None
        if parent.size_on_disk != child_on_disk and child_on_disk:
            parent.size_on_disk = child_on_disk
        if parent.is_dirty():
            parent.save()
            _recurse_availability_up_tree(parent)

        return node
예제 #3
0
    def convert_dict_to_model(node):
        item = Item(**node)

        item.__dict__.update(**node)

        item.available = False

        # make sure description is a string, not None
        item.description = item.description or ""

        item.extra_fields = _make_extra_fields_value(
            item._meta.get_field_names(), node)

        return item
예제 #4
0
    def convert_dict_to_model(node):
        item = Item(**node)

        item.__dict__.update(**node)

        item.available = False

        # make sure description is a string, not None
        item.description = item.description or ""

        item.extra_fields = _make_extra_fields_value(
            item._meta.get_field_names(),
            node
        )

        return item
예제 #5
0
    def test_writes_db_to_archive(self):
        with tempfile.NamedTemporaryFile() as zffobj:
            zf = zipfile.ZipFile(zffobj, "w")

            with tempfile.NamedTemporaryFile() as dbfobj:
                db = SqliteDatabase(dbfobj.name)
                db.connect()
                with Using(db, [Item]):
                    Item.create_table()
                    item = Item(id="test", title="test",
                                description="test", available=False,
                                slug="srug", kind=NodeType.video,
                                path="/test/test")
                    item.save()
                db.close()

                save_db(db, zf)

            zf.close()

            # reopen the db from the zip, see if our object was saved
            with tempfile.NamedTemporaryFile() as f:
                # we should only have one file in the zipfile, the db. Assume
                # that the first file is the db.
                zf = zipfile.ZipFile(zffobj.name)
                dbfobj = zf.open(zf.infolist()[0])
                f.write(dbfobj.read())
                f.seek(0)

                db = SqliteDatabase(f.name)

                with Using(db, [Item]):
                    Item.get(title="test")
예제 #6
0
    def test_writes_db_to_archive(self):
        with tempfile.NamedTemporaryFile() as zffobj:
            zf = zipfile.ZipFile(zffobj, "w")

            with tempfile.NamedTemporaryFile() as dbfobj:
                db = SqliteDatabase(dbfobj.name)
                db.connect()
                with Using(db, [Item]):
                    Item.create_table()
                    item = Item(id="test",
                                title="test",
                                description="test",
                                available=False,
                                slug="srug",
                                kind=NodeType.video,
                                path="/test/test")
                    item.save()
                db.close()

                save_db(db, zf)

            zf.close()

            # reopen the db from the zip, see if our object was saved
            with tempfile.NamedTemporaryFile() as f:
                # we should only have one file in the zipfile, the db. Assume
                # that the first file is the db.
                zf = zipfile.ZipFile(zffobj.name)
                dbfobj = zf.open(zf.infolist()[0])
                f.write(dbfobj.read())
                f.seek(0)

                db = SqliteDatabase(f.name)

                with Using(db, [Item]):
                    Item.get(title="test")