Example #1
0
def index_path(ip, path, parent=None):
    """
    Indexes the file or directory at path to elasticsearch

    :param ip: The IP the path belongs to
    :type ip: InformationPackage
    :param path: The path of the file or directory
    :type path: str
    :param parent: The parent of the tag
    :type parent: TagStructure
    :return: The indexed elasticsearch document
    :rtype: File or Directory
    """

    isfile = os.path.isfile(path)
    id = str(uuid.uuid4())

    tag = Tag.objects.create(information_package=ip)
    tag_version = TagVersion(pk=id, tag=tag, name=os.path.basename(path))
    if parent:
        TagStructure.objects.create(tag=tag, parent=parent, structure=parent.structure)

    if isfile:
        tag_version.elastic_index = 'document'
        tag_version.type = 'document'
        tag_version.save()
        return index_document(ip, path, id)
    else:
        tag_version.elastic_index = 'directory'
        tag_version.type = 'directory'
        tag_version.save()
        return index_directory(ip, path, id)
Example #2
0
def index_path(ip, path, parent=None):
    """
    Indexes the file or directory at path to elasticsearch

    :param ip: The IP the path belongs to
    :type ip: InformationPackage
    :param path: The path of the file or directory
    :type path: str
    :param parent: The parent of the tag
    :type parent: TagStructure
    :return: The indexed elasticsearch document
    :rtype: File or Directory
    """

    isfile = os.path.isfile(path)
    id = str(uuid.uuid4())

    tag = Tag.objects.create(information_package=ip)
    tag_version = TagVersion(pk=id, tag=tag, name=os.path.basename(path))
    if parent:
        TagStructure.objects.create(tag=tag,
                                    parent=parent,
                                    structure=parent.structure)

    logger.debug('indexing {}'.format(path))

    if isfile:
        tag_version.elastic_index = 'document'
        # TODO: minimize db queries
        tag_version.type = TagVersionType.objects.get_or_create(
            name='document', archive_type=False)[0]
        doc, tag_version = index_document(tag_version, path)
        tag_version.save()
    else:
        tag_version.elastic_index = 'directory'
        # TODO: minimize db queries
        tag_version.type = TagVersionType.objects.get_or_create(
            name='directory', archive_type=False)[0]
        doc, tag_version = index_directory(tag_version, path)
        tag_version.save()