# Path: mtr/sync/lib/signals.py

# 
# Path: mtr/sync/lib/exceptions.py
# class ErrorChoicesMixin(object):
#     IMPORT_DATA = 0
#     UNDEFINED = 1
# 
#     STEP_CHOICES = (
#         (IMPORT_DATA, _('import data')),
#         (UNDEFINED, _('unexpected error'))
#     )
# 
# Path: mtr/sync/settings.py
# SETTINGS = getattr_with_prefix('SYNC', 'SETTINGS', {
#     'path': get_buffer_file_path,
#     'default_processor': 'XlsxProcessor',
#     'actions': ['mtr.sync.lib.actions'],
#     'converters': ['mtr.sync.lib.converters'],
#     'processors': [
#         'mtr.sync.lib.processors.xlsx',
#         'mtr.sync.lib.processors.xls',
#         'mtr.sync.lib.processors.ods',
#         'mtr.sync.lib.processors.csv',
#     ],
#     'broker': 'rq',
#     'include': {
#         'api': False,
#         'admin': True,
#     }
# })


import os
import traceback
from django.utils.six.moves import range
from django.utils import timezone
from django.db import transaction, Error
from django.core.exceptions import ValidationError
from .signals import export_started, export_completed, \
    import_started, import_completed, error_raised
from .exceptions import ErrorChoicesMixin
from ..settings import SETTINGS

    def save(self):
        """Save result file"""

        raise NotImplementedError

    def create_export_path(self):
        # TODO: refactor filepath

        filename = '{}{}'.format(
            self.settings.filename or str(self.report.id), self.file_format)
        path = SETTINGS['path'](self.report, '', absolute=True)
        if not os.path.exists(path):
            os.makedirs(path)

        return filename, os.path.join(path, filename)

    def write_header(self, data):
        if self.settings.include_header and data['fields']:
            header_data = [
                field.name or field.attribute
                for field in data['fields']
            ]

            self.write(self.start['row'], header_data)

    def export_data(self, data):
        """Export data from queryset to file and return path"""

        # send signal to create report

# Path: mtr/sync/lib/signals.py

# 
# Path: mtr/sync/lib/exceptions.py
# class ErrorChoicesMixin(object):
#     IMPORT_DATA = 0
#     UNDEFINED = 1
# 
#     STEP_CHOICES = (
#         (IMPORT_DATA, _('import data')),
#         (UNDEFINED, _('unexpected error'))
#     )
# 
# Path: mtr/sync/settings.py
# SETTINGS = getattr_with_prefix('SYNC', 'SETTINGS', {
#     'path': get_buffer_file_path,
#     'default_processor': 'XlsxProcessor',
#     'actions': ['mtr.sync.lib.actions'],
#     'converters': ['mtr.sync.lib.converters'],
#     'processors': [
#         'mtr.sync.lib.processors.xlsx',
#         'mtr.sync.lib.processors.xls',
#         'mtr.sync.lib.processors.ods',
#         'mtr.sync.lib.processors.csv',
#     ],
#     'broker': 'rq',
#     'include': {
#         'api': False,
#         'admin': True,
#     }
# })


# Path: mtr/sync/lib/processor.py
import os
import traceback
from django.utils.six.moves import range
from django.utils import timezone
from django.db import transaction, Error
from django.core.exceptions import ValidationError
from .signals import export_started, export_completed, \
    import_started, import_completed, error_raised
from .exceptions import ErrorChoicesMixin
from ..settings import SETTINGS


    def save(self):
        """Save result file"""

        raise NotImplementedError

    def create_export_path(self):
        # TODO: refactor filepath

        filename = '{}{}'.format(
            self.settings.filename or str(self.report.id), self.file_format)
        path = SETTINGS['path'](self.report, '', absolute=True)
        if not os.path.exists(path):
            os.makedirs(path)

        return filename, os.path.join(path, filename)

    def write_header(self, data):
        if self.settings.include_header and data['fields']:
            header_data = [
                field.name or field.attribute
                for field in data['fields']
            ]

            self.write(self.start['row'], header_data)

    def export_data(self, data):
        """Export data from queryset to file and return path"""

        # send signal to create report

        for response in export_started.send(self):