ocrd/ocrd/workspace.py
def add_file(self, file_grp, content=None, **kwargs):
        """
        Add an output file. Creates an :class:`OcrdFile` to pass around and adds that to the
        OcrdMets OUTPUT section.
        """
        log = getLogger('ocrd.workspace.add_file')
        log.debug(
            'outputfile file_grp=%s local_filename=%s content=%s',
            file_grp,
            kwargs.get('local_filename'),
            content is not None)
        if 'pageId' not in kwargs:
            raise ValueError("workspace.add_file must be passed a 'pageId' kwarg, even if it is None.")
        if content is not None and 'local_filename' not in kwargs:
            raise Exception("'content' was set but no 'local_filename'")
        if self.overwrite_mode:
            kwargs['force'] = True

        with pushd_popd(self.directory):
            if 'local_filename' in kwargs:
                # If the local filename has folder components, create those folders
                local_filename_dir = kwargs['local_filename'].rsplit('/', 1)[0]
                if local_filename_dir != kwargs['local_filename'] and not Path(local_filename_dir).is_dir():
                    makedirs(local_filename_dir)
                if 'url' not in kwargs:
                    kwargs['url'] = kwargs['local_filename']

            #  print(kwargs)
            ret = self.mets.add_file(file_grp, **kwargs)

            if content is not None:
                with open(kwargs['local_filename'], 'wb') as f:
                    if isinstance(content, str):
                        content = bytes(content, 'utf-8')
                    f.write(content)

        return ret

        Add an output file. Creates an :class:`OcrdFile` to pass around and adds that to the
        OcrdMets OUTPUT section.
        
Add an output file. Creates an :class:`OcrdFile` to pass around and adds that to the
OcrdMets OUTPUT section.
Add an output file . Creates an : class : ` OcrdFile ` to pass around and adds that to the OcrdMets OUTPUT section .
def add_file(self, file_grp, content=None, **kwargs):
        log = getLogger('ocrd.workspace.add_file')
        log.debug(
            'outputfile file_grp=%s local_filename=%s content=%s',
            file_grp,
            kwargs.get('local_filename'),
            content is not None)
        if 'pageId' not in kwargs:
            raise ValueError("workspace.add_file must be passed a 'pageId' kwarg, even if it is None.")
        if content is not None and 'local_filename' not in kwargs:
            raise Exception("'content' was set but no 'local_filename'")
        if self.overwrite_mode:
            kwargs['force'] = True
        with pushd_popd(self.directory):
            if 'local_filename' in kwargs:
                local_filename_dir = kwargs['local_filename'].rsplit('/', 1)[0]
                if local_filename_dir != kwargs['local_filename'] and not Path(local_filename_dir).is_dir():
                    makedirs(local_filename_dir)
                if 'url' not in kwargs:
                    kwargs['url'] = kwargs['local_filename']
            ret = self.mets.add_file(file_grp, **kwargs)
            if content is not None:
                with open(kwargs['local_filename'], 'wb') as f:
                    if isinstance(content, str):
                        content = bytes(content, 'utf-8')
                    f.write(content)
        return ret
def add_file ( self , file_grp , content = None , ** kwargs ) : log = getLogger ( 'ocrd.workspace.add_file' ) log . debug ( 'outputfile file_grp=%s local_filename=%s content=%s' , file_grp , kwargs . get ( 'local_filename' ) , content is not None ) if 'pageId' not in kwargs : raise ValueError ( "workspace.add_file must be passed a 'pageId' kwarg, even if it is None." ) if content is not None and 'local_filename' not in kwargs : raise Exception ( "'content' was set but no 'local_filename'" ) if self . overwrite_mode : kwargs [ 'force' ] = True with pushd_popd ( self . directory ) : if 'local_filename' in kwargs : local_filename_dir = kwargs [ 'local_filename' ] . rsplit ( '/' , 1 ) [ 0 ] if local_filename_dir != kwargs [ 'local_filename' ] and not Path ( local_filename_dir ) . is_dir ( ) : makedirs ( local_filename_dir ) if 'url' not in kwargs : kwargs [ 'url' ] = kwargs [ 'local_filename' ] ret = self . mets . add_file ( file_grp , ** kwargs ) if content is not None : with open ( kwargs [ 'local_filename' ] , 'wb' ) as f : if isinstance ( content , str ) : content = bytes ( content , 'utf-8' ) f . write ( content ) return ret
Add an output file.
Add an output file .
"""
        Add an output file. Creates an :class:`OcrdFile` to pass around and adds that to the
        OcrdMets OUTPUT section.
        """ # If the local filename has folder components, create those folders #  print(kwargs)
self
file_grp
content