Exemplo n.º 1
0
    def handle(self, *args, **options):
        print "Starting"

        if os.path.exists(options["path"]):
            dst_path = os.path.join(options["path"], "ghiro_output")
            if os.path.exists(dst_path):
                print "ERROR: a folder 'ghiro_output' already exist in that path!"
                sys.exit()
            else:
                # Create destination folder.
                os.mkdir(dst_path)
                # Mongo connection.
                db = mongo_connect()
                fs = gridfs.GridFS(db)
                # We are fine, run!
                for analysis in Analysis.objects.all():
                    try:
                       file = get_file(analysis.image_id)
                    except (InvalidId, TypeError) as e:
                        print "Unable to dump %s: %s" % (analysis.id, e)
                        continue
                    else:
                        with open(os.path.join(dst_path, "analysis_%s" % analysis.id), "a") as the_file:
                            the_file.write(file.read())
        else:
            print "ERROR: path not found!"
Exemplo n.º 2
0
    def handle(self, *args, **options):
        print "Starting"

        if os.path.exists(options["path"]):
            dst_path = os.path.join(options["path"], "ghiro_output")
            if os.path.exists(dst_path):
                print "ERROR: a folder 'ghiro_output' already exist in that path!"
                sys.exit()
            else:
                # Create destination folder.
                os.mkdir(dst_path)
                # Mongo connection.
                db = mongo_connect()
                fs = gridfs.GridFS(db)
                # We are fine, run!
                for analysis in Analysis.objects.all():
                    try:
                        file = get_file(analysis.image_id)
                    except (InvalidId, TypeError) as e:
                        print "Unable to dump %s: %s" % (analysis.id, e)
                        continue
                    else:
                        with open(
                                os.path.join(dst_path,
                                             "analysis_%s" % analysis.id),
                                "a") as the_file:
                            the_file.write(file.read())
        else:
            print "ERROR: path not found!"
Exemplo n.º 3
0
    def ready(self):
        """Initialization code.
        It runs once at app startup.
        """
        db = mongo_connect()

        # Indexes.
        db.fs.files.create_index("sha1", unique=True, name="sha1_unique")
        db.fs.files.create_index("uuid", unique=True, name="uuid_unique")
        db.analyses.create_index([("metadata.gps.pos", GEO2D)])
Exemplo n.º 4
0
from datetime import datetime
from bson.objectid import ObjectId
from django.db import models
from django.db.models.signals import pre_delete, pre_save, post_save
from django.dispatch import receiver
from django.conf import settings

from users.models import Profile
from lib.db import get_file, get_file_length, mongo_connect
from lib.exceptions import GhiroValidationException
from ghiro.common import check_allowed_content
from lib.db import save_file
from lib.utils import create_thumb, get_content_type_from_file

db = mongo_connect()
fs = gridfs.GridFS(db)


class Case(models.Model):
    """Collection of image analysis."""

    # Case state.
    STATUSES = (("O", "Open"), ("C", "Closed"))
    name = models.CharField(max_length=255, null=False, blank=False)
    description = models.TextField(null=True, blank=True)
    state = models.CharField(
        max_length=1, choices=STATUSES, default="O", db_index=True, editable=False, null=False, blank=False
    )
    owner = models.ForeignKey(
        Profile,
Exemplo n.º 5
0
# Ghiro - Copyright (C) 2013-2015 Ghiro Developers.
# This file is part of Ghiro.
# See the file 'docs/LICENSE.txt' for license terms.

from pymongo import GEO2D

# Mongo connection.
from lib.db import mongo_connect

db = mongo_connect()

# Indexes.
db.fs.files.ensure_index("sha1", unique=True, name="sha1_unique")
db.fs.files.ensure_index("uuid", unique=True, name="uuid_unique")
db.analyses.ensure_index([("metadata.gps.pos", GEO2D)])