# Path: repoxplorer/controllers/renderers.py
# class CSVRenderer(object):
#     def __init__(self, path, extra_vars):
#         pass
# 
#     def render(self, template_path, namespace):
#         buf = StringIO()
#         # Assume namespace an array of dict
#         if not isinstance(namespace, list):
#             namespace = [namespace]
#         for e in namespace:
#             assert isinstance(e, dict)
#         keys = list(namespace[0].keys())
#         keys.sort()
#         w = csv.DictWriter(buf, fieldnames=keys)
#         w.writeheader()
#         for e in namespace:
#             d = {}
#             for k, v in e.items():
#                 if not any([
#                         isinstance(v, str),
#                         isinstance(v, list),
#                         isinstance(v, int),
#                         isinstance(v, float)]):
#                     raise ValueError(
#                         "'%s' (type: %s) is not supported for CSV output" % (
#                             str(v), type(v)))
#                 if isinstance(v, str):
#                     d[k] = v
#                 elif isinstance(v, list):
#                     d[k] = ";".join(v)
#                 else:
#                     d[k] = str(v)
#             w.writerow(d)
#         buf.seek(0)
#         return buf.read()


import os
import sys
import copy
from repoxplorer.controllers.renderers import CSVRenderer
            'class': 'logging.StreamHandler',
            'formatter': 'console'
        },
        'normal': {
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'level': 'DEBUG',
            'formatter': 'normal',
            'filename': '',
            'when': 'D',
            'interval': 1,
            'backupCount': 30,
        },
    },
    'formatters': {
        'console': {'format': ('%(levelname)-5.5s [%(name)s] %(message)s')},
        'normal': {'format': ('%(asctime)s %(levelname)-5.5s [%(name)s]'
                              ' %(message)s')},
    }
}

# Internal dev pecan server
server = {
    'port': '51000',
    'host': '0.0.0.0'
}

# Pecan REST and rendering configuration
app = {
    'root': 'repoxplorer.controllers.root.RootController',
    'modules': ['repoxplorer'],

# Path: repoxplorer/controllers/renderers.py
# class CSVRenderer(object):
#     def __init__(self, path, extra_vars):
#         pass
# 
#     def render(self, template_path, namespace):
#         buf = StringIO()
#         # Assume namespace an array of dict
#         if not isinstance(namespace, list):
#             namespace = [namespace]
#         for e in namespace:
#             assert isinstance(e, dict)
#         keys = list(namespace[0].keys())
#         keys.sort()
#         w = csv.DictWriter(buf, fieldnames=keys)
#         w.writeheader()
#         for e in namespace:
#             d = {}
#             for k, v in e.items():
#                 if not any([
#                         isinstance(v, str),
#                         isinstance(v, list),
#                         isinstance(v, int),
#                         isinstance(v, float)]):
#                     raise ValueError(
#                         "'%s' (type: %s) is not supported for CSV output" % (
#                             str(v), type(v)))
#                 if isinstance(v, str):
#                     d[k] = v
#                 elif isinstance(v, list):
#                     d[k] = ";".join(v)
#                 else:
#                     d[k] = str(v)
#             w.writerow(d)
#         buf.seek(0)
#         return buf.read()


# Path: config.py
import os
import sys
import copy
from repoxplorer.controllers.renderers import CSVRenderer

            'class': 'logging.StreamHandler',
            'formatter': 'console'
        },
        'normal': {
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'level': 'DEBUG',
            'formatter': 'normal',
            'filename': '',
            'when': 'D',
            'interval': 1,
            'backupCount': 30,
        },
    },
    'formatters': {
        'console': {'format': ('%(levelname)-5.5s [%(name)s] %(message)s')},
        'normal': {'format': ('%(asctime)s %(levelname)-5.5s [%(name)s]'
                              ' %(message)s')},
    }
}

# Internal dev pecan server
server = {
    'port': '51000',
    'host': '0.0.0.0'
}

# Pecan REST and rendering configuration
app = {
    'root': 'repoxplorer.controllers.root.RootController',
    'modules': ['repoxplorer'],

    'custom_renderers': {'csv': CSVRenderer},