# Path: processing/docker_utils.py
#     HAVE_DOCKER = True
#     HAVE_DOCKER = False
# def temp_volume(target):


import os
import re
from fame.core.module import ProcessingModule, ModuleInitializationError
from ..docker_utils import temp_volume, HAVE_DOCKER, docker_client

    def save_output(self, output):
        self.log("debug", output)

    def save_images(self, directory):
        extracted_images = False

        # get all images, sorted by page number
        image_files = os.listdir(directory)
        image_files.sort(key=natural_keys)

        for filename in image_files:
            if filename.endswith('.jpeg'):
                # extract page number from filename
                number = filename.split('_')[-1].split('.')[0]
                self.add_support_file('page_#{}'.format(number), os.path.join(directory, filename))
                extracted_images = True

        return extracted_images

    def preview(self, target, target_type):

        args = "--target \"{}\" --target_type {} --max_pages {}".format(
            os.path.basename(target), target_type, self.max_pages)

        # start the right docker
        return docker_client.containers.run(
            'fame/document_preview',
            args,
            volumes={self.outdir: {'bind': '/data', 'mode': 'rw'}},

# Path: processing/docker_utils.py
#     HAVE_DOCKER = True
#     HAVE_DOCKER = False
# def temp_volume(target):


# Path: processing/document_preview/document_preview.py
import os
import re
from fame.core.module import ProcessingModule, ModuleInitializationError
from ..docker_utils import temp_volume, HAVE_DOCKER, docker_client


    def save_output(self, output):
        self.log("debug", output)

    def save_images(self, directory):
        extracted_images = False

        # get all images, sorted by page number
        image_files = os.listdir(directory)
        image_files.sort(key=natural_keys)

        for filename in image_files:
            if filename.endswith('.jpeg'):
                # extract page number from filename
                number = filename.split('_')[-1].split('.')[0]
                self.add_support_file('page_#{}'.format(number), os.path.join(directory, filename))
                extracted_images = True

        return extracted_images

    def preview(self, target, target_type):

        args = "--target \"{}\" --target_type {} --max_pages {}".format(
            os.path.basename(target), target_type, self.max_pages)

        # start the right docker
        return docker_client.containers.run(
            'fame/document_preview',
            args,
            volumes={self.outdir: {'bind': '/data', 'mode': 'rw'}},

            stderr=True,