Ejemplo n.º 1
0
def execute_unless_deleted(db_object, partial_func):
    if db_object.pk:
        if exists_in_db(db_object):
            partial_func()
        else:
            raise ObjectDeletedError("The object {0} has been deleted from the database. Aborting save.".format(db_object))
    else:
        # If the object doesn't have a primary key we assume that it being newly created and this safe to touch the database.
        partial_func()
Ejemplo n.º 2
0
def _ensure_db_state(resultspackage):
    if not exists_in_db(resultspackage):
        raise ObjectDeletedError(
            "The resultspackage has been deleted. Aborting and scheduling clean up of directory..."
        )

    if resultspackage.status == ResultsPackageStatus.CANCELLED:
        raise PackageCancelledError(
            "The resultspackage has been cancelled. Aborting and scheduling clean up of directory..."
        )
Ejemplo n.º 3
0
def execute_unless_deleted(db_object, partial_func):
    if db_object.pk:
        if exists_in_db(db_object):
            partial_func()
        else:
            raise ObjectDeletedError(
                "The object {0} has been deleted from the database. Aborting save."
                .format(db_object))
    else:
        # If the object doesn't have a primary key we assume that it being newly created and this safe to touch the database.
        partial_func()
Ejemplo n.º 4
0
def ensure_compatible(page_object):
    page_object = refetch_from_db(page_object)

    filename = "compat_image.png"

    image = PIL.Image.open(page_object.page_image.path).convert('RGB')
    tmpdir = tempfile.mkdtemp()
    image.save(os.path.join(tmpdir, filename))

    compatible_image_path = os.path.join(page_object.image_path, filename)
    f = open(os.path.join(tmpdir, filename), 'rb')

    if exists_in_db(page_object):
        page_object.compat_page_image.save(compatible_image_path, File(f))
    else:
        warnings.warn("The page was deleted from the database before it could be processed.")

    f.close()
    shutil.rmtree(tmpdir)

    return page_object
Ejemplo n.º 5
0
def processed(dbobject):
    dbobject = refetch_from_db(dbobject)
    dbobject.processed = True
    if exists_in_db(dbobject):
        dbobject.save()
    return dbobject
Ejemplo n.º 6
0
def _ensure_db_state(resultspackage):
    if not exists_in_db(resultspackage):
        raise ObjectDeletedError("The resultspackage has been deleted. Aborting and scheduling clean up of directory...")

    if resultspackage.status == ResultsPackageStatus.CANCELLED:
        raise PackageCancelledError("The resultspackage has been cancelled. Aborting and scheduling clean up of directory...")