# Path: pyca/config.py
# def config(*args):
#     '''Get a specific configuration value or the whole configuration, loading
#     the configuration file if it was not before.
# 
#     :param key: optional configuration key to return
#     :type key: string
#     :return: Part of the configuration object containing the configuration
#              or configuration value.
#              If a part of the configuration object (e.g. configobj.Section) is
#              returned, it can be treated like a dictionary.
#              Returning None, if the configuration value is not found.
#     '''
#     cfg = __config or update_configuration()
#     for key in args:
#         if cfg is None:
#             return
#         cfg = cfg.get(key)
#     return cfg


import json
import os.path
import string
from pyca.config import config
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, Text, LargeBinary, DateTime, \
    create_engine
from sqlalchemy.orm import sessionmaker
from datetime import datetime
from functools import wraps
    __tablename__ = 'event'

    uid = Column('uid', Text(), nullable=False, primary_key=True)
    start = Column('start', Integer(), primary_key=True)
    end = Column('end', Integer(), nullable=False)
    title = Column('title', Text())
    data = Column('data', LargeBinary(), nullable=False)
    status = Column('status', Integer(), nullable=False,
                    default=Status.UPCOMING)
    tracks = Column('tracks', LargeBinary(), nullable=True)

    def get_data(self):
        '''Load JSON data from event.
        '''
        return json.loads(self.data.decode('utf-8'))

    def set_data(self, data):
        '''Store data as JSON.
        '''
        # Python 3 wants bytes
        self.data = json.dumps(data).encode('utf-8')

    def name(self):
        '''Returns the filesystem name of this event.
        '''
        return 'recording-%i-%s' % (self.start, self.uid)

    def directory(self):
        '''Returns recording directory of this event.
        '''

# Path: pyca/config.py
# def config(*args):
#     '''Get a specific configuration value or the whole configuration, loading
#     the configuration file if it was not before.
# 
#     :param key: optional configuration key to return
#     :type key: string
#     :return: Part of the configuration object containing the configuration
#              or configuration value.
#              If a part of the configuration object (e.g. configobj.Section) is
#              returned, it can be treated like a dictionary.
#              Returning None, if the configuration value is not found.
#     '''
#     cfg = __config or update_configuration()
#     for key in args:
#         if cfg is None:
#             return
#         cfg = cfg.get(key)
#     return cfg


# Path: pyca/db.py
import json
import os.path
import string
from pyca.config import config
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, Text, LargeBinary, DateTime, \
    create_engine
from sqlalchemy.orm import sessionmaker
from datetime import datetime
from functools import wraps

    __tablename__ = 'event'

    uid = Column('uid', Text(), nullable=False, primary_key=True)
    start = Column('start', Integer(), primary_key=True)
    end = Column('end', Integer(), nullable=False)
    title = Column('title', Text())
    data = Column('data', LargeBinary(), nullable=False)
    status = Column('status', Integer(), nullable=False,
                    default=Status.UPCOMING)
    tracks = Column('tracks', LargeBinary(), nullable=True)

    def get_data(self):
        '''Load JSON data from event.
        '''
        return json.loads(self.data.decode('utf-8'))

    def set_data(self, data):
        '''Store data as JSON.
        '''
        # Python 3 wants bytes
        self.data = json.dumps(data).encode('utf-8')

    def name(self):
        '''Returns the filesystem name of this event.
        '''
        return 'recording-%i-%s' % (self.start, self.uid)

    def directory(self):
        '''Returns recording directory of this event.
        '''

        return os.path.join(config('capture', 'directory'), self.name())