django_ocr_server/models.py
def cleanup():
        """
        Removes 'files' and 'ocred_pdfs' that are not related with any the OCRedFile 2019-04-13
        :return: tuple ([removed_files tuple], [removed_pdf tuple],)
        """
        def remove_files(folder, files):
            """
            Removes all files in the 'folder' exclude 'files'
            :param folder: the path to the folder in which will be files removed
            :param files: files that will be excluded from removing
            :return: the list of path of removed files
            """
            removed = []
            for r, d, f in os.walk(folder):
                for file in f:
                    path = os.path.join(r, file)
                    if path not in files:
                        os.remove(path)
                        removed.append(path)
            return removed

        files = tuple(OCRedFile.objects
                      .exclude(
                               file__in=getattr(settings,
                                                'OCR_STORE_FILES_DISABLED_LABEL',
                                                ocr_default_settings.STORE_FILES_DISABLED_LABEL))
                      .exclude(
                               file__in=getattr(settings,
                                                'OCR_FILE_REMOVED_LABEL',
                                                ocr_default_settings.FILE_REMOVED_LABEL))
                      .values_list('file', flat=True))
        removed_files = remove_files(getattr(settings, 'OCR_FILES_UPLOAD_TO', ocr_default_settings.FILES_UPLOAD_TO),
                                     files)
        pdfs = tuple(OCRedFile.objects
                     .exclude(ocred_pdf__isnull=True)
                     .exclude(
                              ocred_pdf__in=getattr(settings,
                                                    'OCR_STORE_PDF_DISABLED_LABEL',
                                                    ocr_default_settings.STORE_PDF_DISABLED_LABEL))
                     .exclude(
                              ocred_pdf__in=getattr(settings,
                                                    'OCR_PDF_REMOVED_LABEL',
                                                    ocr_default_settings.PDF_REMOVED_LABEL))
                     .values_list('ocred_pdf', flat=True))
        removed_pdfs = remove_files(getattr(settings, 'OCR_PDF_UPLOAD_TO', ocr_default_settings.PDF_UPLOAD_TO), pdfs)
        return removed_files, removed_pdfs

        Removes 'files' and 'ocred_pdfs' that are not related with any the OCRedFile 2019-04-13
        :return: tuple ([removed_files tuple], [removed_pdf tuple],)
        
Removes 'files' and 'ocred_pdfs' that are not related with any the OCRedFile 2019-04-13
Removes ' files ' and ' ocred_pdfs ' that are not related with any the OCRedFile 2019 - 04 - 13
def cleanup():
        def remove_files(folder, files):
            removed = []
            for r, d, f in os.walk(folder):
                for file in f:
                    path = os.path.join(r, file)
                    if path not in files:
                        os.remove(path)
                        removed.append(path)
            return removed
        files = tuple(OCRedFile.objects
                      .exclude(
                               file__in=getattr(settings,
                                                'OCR_STORE_FILES_DISABLED_LABEL',
                                                ocr_default_settings.STORE_FILES_DISABLED_LABEL))
                      .exclude(
                               file__in=getattr(settings,
                                                'OCR_FILE_REMOVED_LABEL',
                                                ocr_default_settings.FILE_REMOVED_LABEL))
                      .values_list('file', flat=True))
        removed_files = remove_files(getattr(settings, 'OCR_FILES_UPLOAD_TO', ocr_default_settings.FILES_UPLOAD_TO),
                                     files)
        pdfs = tuple(OCRedFile.objects
                     .exclude(ocred_pdf__isnull=True)
                     .exclude(
                              ocred_pdf__in=getattr(settings,
                                                    'OCR_STORE_PDF_DISABLED_LABEL',
                                                    ocr_default_settings.STORE_PDF_DISABLED_LABEL))
                     .exclude(
                              ocred_pdf__in=getattr(settings,
                                                    'OCR_PDF_REMOVED_LABEL',
                                                    ocr_default_settings.PDF_REMOVED_LABEL))
                     .values_list('ocred_pdf', flat=True))
        removed_pdfs = remove_files(getattr(settings, 'OCR_PDF_UPLOAD_TO', ocr_default_settings.PDF_UPLOAD_TO), pdfs)
        return removed_files, removed_pdfs
def cleanup ( ) : def remove_files ( folder , files ) : """
            Removes all files in the 'folder' exclude 'files'
            :param folder: the path to the folder in which will be files removed
            :param files: files that will be excluded from removing
            :return: the list of path of removed files
            """ removed = [ ] for r , d , f in os . walk ( folder ) : for file in f : path = os . path . join ( r , file ) if path not in files : os . remove ( path ) removed . append ( path ) return removed files = tuple ( OCRedFile . objects . exclude ( file__in = getattr ( settings , 'OCR_STORE_FILES_DISABLED_LABEL' , ocr_default_settings . STORE_FILES_DISABLED_LABEL ) ) . exclude ( file__in = getattr ( settings , 'OCR_FILE_REMOVED_LABEL' , ocr_default_settings . FILE_REMOVED_LABEL ) ) . values_list ( 'file' , flat = True ) ) removed_files = remove_files ( getattr ( settings , 'OCR_FILES_UPLOAD_TO' , ocr_default_settings . FILES_UPLOAD_TO ) , files ) pdfs = tuple ( OCRedFile . objects . exclude ( ocred_pdf__isnull = True ) . exclude ( ocred_pdf__in = getattr ( settings , 'OCR_STORE_PDF_DISABLED_LABEL' , ocr_default_settings . STORE_PDF_DISABLED_LABEL ) ) . exclude ( ocred_pdf__in = getattr ( settings , 'OCR_PDF_REMOVED_LABEL' , ocr_default_settings . PDF_REMOVED_LABEL ) ) . values_list ( 'ocred_pdf' , flat = True ) ) removed_pdfs = remove_files ( getattr ( settings , 'OCR_PDF_UPLOAD_TO' , ocr_default_settings . PDF_UPLOAD_TO ) , pdfs ) return removed_files , removed_pdfs
Removes 'files' and 'ocred_pdfs' that are not related with any the OCRedFile 2019-04-13
Removes ' files ' and ' ocred_pdfs ' that are not related with any the OCRedFile 2019 - 04 - 13
"""
        Removes 'files' and 'ocred_pdfs' that are not related with any the OCRedFile 2019-04-13
        :return: tuple ([removed_files tuple], [removed_pdf tuple],)
        """ """
            Removes all files in the 'folder' exclude 'files'
            :param folder: the path to the folder in which will be files removed
            :param files: files that will be excluded from removing
            :return: the list of path of removed files
            """
None