ocrd/ocrd/workspace.py
def remove_file(self, ID, force=False, keep_file=False, page_recursive=False, page_same_group=False):
        """
        Remove a file from the workspace.

        Arguments:
            ID (string|OcrdFile): ID of the file to delete or the file itself
            force (boolean): Continue removing even if file not found in METS
            keep_file (boolean): Whether to keep files on disk
            page_recursive (boolean): Whether to remove all images referenced in the file if the file is a PAGE-XML document.
            page_same_group (boolean): Remove only images in the same file group as the PAGE-XML. Has no effect unless ``page_recursive`` is ``True``.
        """
        log = getLogger('ocrd.workspace.remove_file')
        log.debug('Deleting mets:file %s', ID)
        if not force and self.overwrite_mode:
            force = True
        if isinstance(ID, OcrdFile):
            ID = ID.ID
        try:
            ocrd_file_ = self.mets.remove_file(ID)
            ocrd_files = [ocrd_file_] if isinstance(ocrd_file_, OcrdFile) else ocrd_file_
            if page_recursive:
                with pushd_popd(self.directory):
                    for ocrd_file in ocrd_files:
                        if ocrd_file.mimetype != MIMETYPE_PAGE:
                            continue
                        ocrd_page = parse(self.download_file(ocrd_file).local_filename, silence=True)
                        for img_url in ocrd_page.get_AllAlternativeImagePaths():
                            img_kwargs = {'url': img_url}
                            if page_same_group:
                                img_kwargs['fileGrp'] = ocrd_file.fileGrp
                            for img_file in self.mets.find_files(**img_kwargs):
                                self.remove_file(img_file, keep_file=keep_file, force=force)
            if not keep_file:
                with pushd_popd(self.directory):
                    for ocrd_file in ocrd_files:
                        if not ocrd_file.local_filename:
                            log.warning("File not locally available %s", ocrd_file)
                            if not force:
                                raise Exception("File not locally available %s" % ocrd_file)
                        else:
                            log.info("rm %s [cwd=%s]", ocrd_file.local_filename, self.directory)
                            unlink(ocrd_file.local_filename)
            return ocrd_file_
        except FileNotFoundError as e:
            if not force:
                raise e

        Remove a file from the workspace.

        Arguments:
            ID (string|OcrdFile): ID of the file to delete or the file itself
            force (boolean): Continue removing even if file not found in METS
            keep_file (boolean): Whether to keep files on disk
            page_recursive (boolean): Whether to remove all images referenced in the file if the file is a PAGE-XML document.
            page_same_group (boolean): Remove only images in the same file group as the PAGE-XML. Has no effect unless ``page_recursive`` is ``True``.
        
Remove a file from the workspace.
Remove a file from the workspace .
def remove_file(self, ID, force=False, keep_file=False, page_recursive=False, page_same_group=False):
        log = getLogger('ocrd.workspace.remove_file')
        log.debug('Deleting mets:file %s', ID)
        if not force and self.overwrite_mode:
            force = True
        if isinstance(ID, OcrdFile):
            ID = ID.ID
        try:
            ocrd_file_ = self.mets.remove_file(ID)
            ocrd_files = [ocrd_file_] if isinstance(ocrd_file_, OcrdFile) else ocrd_file_
            if page_recursive:
                with pushd_popd(self.directory):
                    for ocrd_file in ocrd_files:
                        if ocrd_file.mimetype != MIMETYPE_PAGE:
                            continue
                        ocrd_page = parse(self.download_file(ocrd_file).local_filename, silence=True)
                        for img_url in ocrd_page.get_AllAlternativeImagePaths():
                            img_kwargs = {'url': img_url}
                            if page_same_group:
                                img_kwargs['fileGrp'] = ocrd_file.fileGrp
                            for img_file in self.mets.find_files(**img_kwargs):
                                self.remove_file(img_file, keep_file=keep_file, force=force)
            if not keep_file:
                with pushd_popd(self.directory):
                    for ocrd_file in ocrd_files:
                        if not ocrd_file.local_filename:
                            log.warning("File not locally available %s", ocrd_file)
                            if not force:
                                raise Exception("File not locally available %s" % ocrd_file)
                        else:
                            log.info("rm %s [cwd=%s]", ocrd_file.local_filename, self.directory)
                            unlink(ocrd_file.local_filename)
            return ocrd_file_
        except FileNotFoundError as e:
            if not force:
                raise e
def remove_file ( self , ID , force = False , keep_file = False , page_recursive = False , page_same_group = False ) : log = getLogger ( 'ocrd.workspace.remove_file' ) log . debug ( 'Deleting mets:file %s' , ID ) if not force and self . overwrite_mode : force = True if isinstance ( ID , OcrdFile ) : ID = ID . ID try : ocrd_file_ = self . mets . remove_file ( ID ) ocrd_files = [ ocrd_file_ ] if isinstance ( ocrd_file_ , OcrdFile ) else ocrd_file_ if page_recursive : with pushd_popd ( self . directory ) : for ocrd_file in ocrd_files : if ocrd_file . mimetype != MIMETYPE_PAGE : continue ocrd_page = parse ( self . download_file ( ocrd_file ) . local_filename , silence = True ) for img_url in ocrd_page . get_AllAlternativeImagePaths ( ) : img_kwargs = { 'url' : img_url } if page_same_group : img_kwargs [ 'fileGrp' ] = ocrd_file . fileGrp for img_file in self . mets . find_files ( ** img_kwargs ) : self . remove_file ( img_file , keep_file = keep_file , force = force ) if not keep_file : with pushd_popd ( self . directory ) : for ocrd_file in ocrd_files : if not ocrd_file . local_filename : log . warning ( "File not locally available %s" , ocrd_file ) if not force : raise Exception ( "File not locally available %s" % ocrd_file ) else : log . info ( "rm %s [cwd=%s]" , ocrd_file . local_filename , self . directory ) unlink ( ocrd_file . local_filename ) return ocrd_file_ except FileNotFoundError as e : if not force : raise e
Remove a file from the workspace.
Remove a file from the workspace .
"""
        Remove a file from the workspace.

        Arguments:
            ID (string|OcrdFile): ID of the file to delete or the file itself
            force (boolean): Continue removing even if file not found in METS
            keep_file (boolean): Whether to keep files on disk
            page_recursive (boolean): Whether to remove all images referenced in the file if the file is a PAGE-XML document.
            page_same_group (boolean): Remove only images in the same file group as the PAGE-XML. Has no effect unless ``page_recursive`` is ``True``.
        """
self
ID
ID of the file to delete or the file itself
ID of the file to delete or the file itself
force
Continue removing even if file not found in METS
Continue removing even if file not found in METS
keep_file
Whether to keep files on disk
Whether to keep files on disk
page_recursive
Whether to remove all images referenced in the file if the file is a PAGE-XML document.
Whether to remove all images referenced in the file if the file is a PAGE - XML document .
page_same_group
Remove only images in the same file group as the PAGE-XML. Has no effect unless ``page_recursive`` is ``True``.
Remove only images in the same file group as the PAGE - XML . Has no effect unless ` ` page_recursive ` ` is ` ` True ` ` .