# Path: photobooth/worker/WorkerTask.py
# class WorkerTask:
# 
#     def __init__(self, **kwargs):
# 
#         assert not kwargs
# 
#     def do(self, picture):
# 
#         raise NotImplementedError()


import logging
import os
from .WorkerTask import WorkerTask
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.




class PictureSaver(WorkerTask):

    def __init__(self, basename):

        super().__init__()

        # Ensure directory exists
        dirname = os.path.dirname(basename)
        if not os.path.exists(dirname):
            os.makedirs(dirname)

    def do(self, picture, filename):

        logging.info('Saving picture as %s', filename)

# Path: photobooth/worker/WorkerTask.py
# class WorkerTask:
# 
#     def __init__(self, **kwargs):
# 
#         assert not kwargs
# 
#     def do(self, picture):
# 
#         raise NotImplementedError()


# Path: photobooth/worker/PictureSaver.py
import logging
import os
from .WorkerTask import WorkerTask

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.




class PictureSaver(WorkerTask):

    def __init__(self, basename):

        super().__init__()

        # Ensure directory exists
        dirname = os.path.dirname(basename)
        if not os.path.exists(dirname):
            os.makedirs(dirname)

    def do(self, picture, filename):

        logging.info('Saving picture as %s', filename)

        with open(filename, 'wb') as f: