コード例 #1
0
    def getFileDocumentEntity(self, fileDescriptor: FileDescriptor, title: str,
                              author: str, pageCount: int, wordCount: int,
                              characterCount: int) -> None:
        '''
            # TODO
        '''

        table = self.table
        coreModuleTables = self.coreModuleTables
        fileEntity = self.coreModuleQuerier.getFileInDatabase(fileDescriptor)

        s = select([
            table['file_document']
            ]).\
            where(and_(
                coreModuleTables['file'].c.id == fileEntity['id']
            ))

        i = table['file_document'].insert().values(id_file=fileEntity['id'],
                                                   title=title,
                                                   author=author,
                                                   pages=pageCount,
                                                   words=wordCount,
                                                   characters=characterCount)

        return dbTools.getSingletonEntity(s,
                                          i,
                                          self.dbEngine,
                                          allowParallel=True)
コード例 #2
0
    def getFilePathEntity(self, filePath: str, fileSchemeAndHost: str):
        '''
            Get the database value for the given filePath.

            :param filePath: The file path to retrieve.
            :type filePath: str
            :param fileSchemeAndHost: The file scheme and host to support multiple locations
            :type filePath: str

            :return: A file path entity
            :rtype: dict
        '''

        table = self.table

        s = select([
            table['file_path']
            ]).\
            where(table['file_path'].c.path == filePath)

        i = table['file_path'].insert().values(path=filePath,
                                               scheme_host=fileSchemeAndHost)

        return dbTools.getSingletonEntity(s,
                                          i,
                                          self.dbEngine,
                                          allowParallel=False)
コード例 #3
0
    def getFileEntity(self, fileDescriptor: FileDescriptor,
                      fileMimeEntity: any, fileEncodingEntity: any,
                      filePathEntity: any):
        '''
            Add a file entity in the database.

            :param fileDescriptor: A file descriptor.
            :type fileDescriptor: :class:`public.fileDescriptor.FileDescriptor`
            :param fileMimeEntity: dict
            :type fileMimeEntity: A file mime entity.
            :param fileEncodingEntity: A file encoding entity
            :type fileEncodingEntity: dict
            :param filePathEntity: A file path entity.
            :type filePathEntity: dict

            :return: A file entity
            :rtype: dict
        '''

        table = self.table

        s = select([
            table['file']
            ]).\
            where(and_(
                table['file'].c.id_file_mime == fileMimeEntity['id'],
                table['file'].c.id_file_encoding == fileEncodingEntity['id'],
                table['file'].c.id_file_path == filePathEntity['id'],
                table['file'].c.filename == fileDescriptor.name
            ))

        i = table['file'].insert().values(
            id_file_mime=fileMimeEntity['id'],
            id_file_encoding=fileEncodingEntity['id'],
            id_file_path=filePathEntity['id'],
            filename=fileDescriptor.name,
            size_kilobyte=fileDescriptor.sizeKB,
            last_update=fileDescriptor.modificationDateTime,
            file_description=fileDescriptor.description)

        return dbTools.getSingletonEntity(s,
                                          i,
                                          self.dbEngine,
                                          allowParallel=True)
コード例 #4
0
    def getMetaNameEntity(self, metaName: str):
        '''
            Get the database value for the given meta name.

            :param filePath: The meta name to retrieve.
            :type filePath: str

            :return: A file path entity
            :rtype: dict
        '''

        table = self.table

        s = select([
            table['meta_name']
            ]).\
            where(table['meta_name'].c.name == metaName)

        i = table['meta_name'].insert().values(name=metaName)

        return dbTools.getSingletonEntity(s, i, self.dbEngine)
コード例 #5
0
    def getMetaValueEntity(self, documentEntity: dict, metaNameEntity: dict,
                           metaValue: str):
        '''
            __TODO__
        '''

        table = self.table

        s = select([
            table['meta_value']
            ]).\
            where(and_(
                    table['meta_value'].c.id_meta_name == metaNameEntity['id'],
                    table['meta_value'].c.id_file_document == documentEntity['id'],
                    table['meta_value'].c.value == str(metaValue)[:511]
            ))

        i = table['meta_value'].insert().values(
            id_meta_name=metaNameEntity['id'],
            id_file_document=documentEntity['id'],
            value=metaValue)

        return dbTools.getSingletonEntity(s, i, self.dbEngine)
コード例 #6
0
    def getChapterEntity(self, parentChapterEntity: dict or None,
                         chapterTitle: str):
        '''
            __TODO__
        '''

        table = self.table

        parentChapterId = None
        if parentChapterEntity:
            parentChapterId = parentChapterEntity['id']

        s = select([
            table['chapter']
            ]).\
            where(and_(
                table['chapter'].c.id_parent_chapter == parentChapterId,
                table['chapter'].c.title == chapterTitle
            ))

        i = table['chapter'].insert().values(id_parent_chapter=parentChapterId,
                                             title=chapterTitle)

        return dbTools.getSingletonEntity(s, i, self.dbEngine)
コード例 #7
0
    def getFileMimeEntity(self, fileMime: str):
        '''
            Get the database value for the given fileMime.

            :param fileMime: The file mime to retrieve.
            :type fileMime: str

            :return: A file mime entity
            :rtype: dict
        '''

        table = self.table

        s = select([
            table['file_mime']
            ]).\
            where(table['file_mime'].c.mime == fileMime)

        i = table['file_mime'].insert().values(mime=fileMime)

        return dbTools.getSingletonEntity(s,
                                          i,
                                          self.dbEngine,
                                          allowParallel=False)
コード例 #8
0
    def getFileEncodingEntity(self, fileEncoding: str):
        '''
            Get the database value for the given fileEncoding.

            :param fileEncoding: The file encoding to retrieve.
            :type fileEncoding: str

            :return: A file encoding entity
            :rtype: dict
        '''

        table = self.table

        s = select([
            table['file_encoding']
            ]).\
            where(table['file_encoding'].c.encoding == fileEncoding)

        i = table['file_encoding'].insert().values(encoding=fileEncoding)

        return dbTools.getSingletonEntity(s,
                                          i,
                                          self.dbEngine,
                                          allowParallel=False)