示例#1
0
文件: api.py 项目: mabroor/mayan
def find_lowest_available_suffix(index_instance, document):
    # TODO: verify extension's role in query
    index_instance_documents = DocumentRenameCount.objects.filter(index_instance=index_instance)#.filter(document__file_extension=document.file_extension)
    files_list = []
    for index_instance_document in index_instance_documents:
        files_list.append(assemble_suffixed_filename(index_instance_document.document.file.name, index_instance_document.suffix))

    for suffix in xrange(MAX_SUFFIX_COUNT):
        if assemble_suffixed_filename(document.file.name, suffix) not in files_list:
            return suffix

    raise MaxSuffixCountReached(ugettext(u'Maximum suffix (%s) count reached.') % MAX_SUFFIX_COUNT)
示例#2
0
def fs_create_document_link(index_instance, document, suffix=0):
    if FILESERVING_ENABLE:
        filename = assemble_suffixed_filename(document.file.name, suffix)
        filepath = assemble_path_from_list(
            [FILESERVING_PATH,
             get_instance_path(index_instance), filename])

        try:
            os.symlink(document.file.path, filepath)
        except OSError, exc:
            if exc.errno == errno.EEXIST:
                # This link should not exist, try to delete it
                try:
                    os.unlink(filepath)
                    # Try again
                    os.symlink(document.file.path, filepath)
                except Exception, exc:
                    raise Exception(
                        _(u'Unable to create symbolic link, file exists and could not be deleted: %(filepath)s; %(exc)s'
                          ) % {
                              'filepath': filepath,
                              'exc': exc
                          })
            else:
                raise Exception(
                    _(u'Unable to create symbolic link: %(filepath)s; %(exc)s')
                    % {
                        'filepath': filepath,
                        'exc': exc
                    })
示例#3
0
def fs_create_document_link(index_instance, document, suffix=0):
    if FILESERVING_ENABLE:
        filename = assemble_suffixed_filename(document.file.name, suffix)
        filepath = assemble_path_from_list([FILESERVING_PATH, get_instance_path(index_instance), filename])

        try:
            os.symlink(document.file.path, filepath)
        except OSError, exc:
            if exc.errno == errno.EEXIST:
                # This link should not exist, try to delete it
                try:
                    os.unlink(filepath)
                    # Try again
                    os.symlink(document.file.path, filepath)
                except Exception, exc:
                    raise Exception(
                        _(
                            u"Unable to create symbolic link, file exists and could not be deleted: %(filepath)s; %(exc)s"
                        )
                        % {"filepath": filepath, "exc": exc}
                    )
            else:
                raise Exception(
                    _(u"Unable to create symbolic link: %(filepath)s; %(exc)s") % {"filepath": filepath, "exc": exc}
                )
示例#4
0
文件: api.py 项目: spacedman/mayan
def find_lowest_available_suffix(index_instance, document):
    # TODO: verify extension's role in query
    index_instance_documents = DocumentRenameCount.objects.filter(
        index_instance=index_instance
    )  #.filter(document__file_extension=document.file_extension)
    files_list = []
    for index_instance_document in index_instance_documents:
        files_list.append(
            assemble_suffixed_filename(
                index_instance_document.document.file.name,
                index_instance_document.suffix))

    for suffix in xrange(MAX_SUFFIX_COUNT):
        if assemble_suffixed_filename(document.file.name,
                                      suffix) not in files_list:
            return suffix

    raise MaxSuffixCountReached(
        ugettext(u'Maximum suffix (%s) count reached.') % MAX_SUFFIX_COUNT)
示例#5
0
def fs_delete_document_link(index_instance, document, suffix=0):
    if FILESERVING_ENABLE:
        filename = assemble_suffixed_filename(document.file.name, suffix)
        filepath = assemble_path_from_list([FILESERVING_PATH, get_instance_path(index_instance), filename])

        try:
            os.unlink(filepath)
        except OSError, exc:
            if exc.errno != errno.ENOENT:
                # Raise when any error other than doesn't exits
                raise Exception(_(u"Unable to delete document symbolic link; %s") % exc)
示例#6
0
def fs_delete_document_link(index_instance, document, suffix=0):
    if FILESERVING_ENABLE:
        filename = assemble_suffixed_filename(document.file.name, suffix)
        filepath = assemble_path_from_list(
            [FILESERVING_PATH,
             get_instance_path(index_instance), filename])

        try:
            os.unlink(filepath)
        except OSError, exc:
            if exc.errno != errno.ENOENT:
                # Raise when any error other than doesn't exits
                raise Exception(
                    _(u'Unable to delete document symbolic link; %s') % exc)