# Path: pypeman/errors.py
# class PypemanConfigError(PypemanError):
#     """ custom error """


import logging
import os
import re
from collections import OrderedDict
from pypeman.message import Message
from pypeman.errors import PypemanConfigError
            reverse = True
            sort_key = order_by[1:]
        else:
            reverse = False
            sort_key = order_by

        result = []
        for value in sorted(self.messages.values(), key=lambda x: x[sort_key], reverse=reverse):

            resp = dict(value)
            resp['message'] = Message.from_dict(resp['message'])

            result.append(resp)

        return result[start: start + count]

    async def total(self):
        return len(self.messages)


class FileMessageStoreFactory(MessageStoreFactory):
    """
    Generate a FileMessageStore message store instance.
    Store a file in `<base_path>/<store_id>/<month>/<day>/` hierachy.
    """

    # TODO add an option to reguraly archive old file or delete them
    def __init__(self, path):
        super().__init__()
        if path is None:

# Path: pypeman/errors.py
# class PypemanConfigError(PypemanError):
#     """ custom error """


# Path: pypeman/msgstore.py
import logging
import os
import re
from collections import OrderedDict
from pypeman.message import Message
from pypeman.errors import PypemanConfigError

            reverse = True
            sort_key = order_by[1:]
        else:
            reverse = False
            sort_key = order_by

        result = []
        for value in sorted(self.messages.values(), key=lambda x: x[sort_key], reverse=reverse):

            resp = dict(value)
            resp['message'] = Message.from_dict(resp['message'])

            result.append(resp)

        return result[start: start + count]

    async def total(self):
        return len(self.messages)


class FileMessageStoreFactory(MessageStoreFactory):
    """
    Generate a FileMessageStore message store instance.
    Store a file in `<base_path>/<store_id>/<month>/<day>/` hierachy.
    """

    # TODO add an option to reguraly archive old file or delete them
    def __init__(self, path):
        super().__init__()
        if path is None:

            raise PypemanConfigError('file message store requires a path')