# Path: pyca/capture.py
# def sigterm_handler(signum, frame):
# def start_capture(db, upcoming_event):
# def safe_start_capture(event):
# def recording_command(event):
# def control_loop():
# def run():
#     DEVNULL = getattr(subprocess, 'DEVNULL', os.open(os.devnull, os.O_RDWR))
# 
# 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
# def init():
# def get_session():
# def with_session(f):
#     def decorated(*args, **kwargs):
#     def values(cls):
#     def str(cls, value):
#     def get_data(self):
#     def set_data(self, data):
#     def name(self):
#     def directory(self):
#     def remaining_duration(self, time):
#     def status_str(self):
#     def get_tracks(self):
#     def set_tracks(self, tracks):
#     def __repr__(self):
#     def serialize(self):
#     def __init__(self, event=None):
#     def __init__(self, service=None):
#     def update_sync_time(url):
# class Constants():
# class Status(Constants):
# class ServiceStatus(Constants):
# class Service(Constants):
# class BaseEvent():
# class UpcomingEvent(Base, BaseEvent):
# class RecordedEvent(Base, BaseEvent):
# class ServiceStates(Base):
# class UpstreamState(Base):
#     UPCOMING = 1
#     RECORDING = 2
#     FAILED_RECORDING = 3
#     FINISHED_RECORDING = 4
#     UPLOADING = 5
#     FAILED_UPLOADING = 6
#     FINISHED_UPLOADING = 7
#     PARTIAL_RECORDING = 8
#     PAUSED_AFTER_RECORDING = 9
#     STOPPED = 1
#     IDLE = 2
#     BUSY = 3
#     AGENTSTATE = 1
#     CAPTURE = 2
#     INGEST = 3
#     SCHEDULE = 4
# 
# Path: pyca/utils.py
# def http_request(url, post_data=None):
# def get_service(service_type):
# def timestamp():
# def try_mkdir(directory):
# def service(service_name, force_update=False):
# def ensurelist(x):
# def register_ca(status='idle'):
# def recording_state(recording_id, status):
# def update_event_status(dbs, event, status):
# def set_service_status(dbs, service, status):
# def set_service_status_immediate(service, status):
# def get_service_status(dbs, service):
# def update_agent_state():
# def terminate(shutdown=None):
# 
# Path: tests/tools.py
# class ShouldFailException(pycurl.error):
# class CurlMock():
# def should_fail(*args, **kwargs):
# def __terminate():
# def terminate_fn(num):
#     def setopt(self, *args):
#     def perform(self):
#     def getinfo(self, *args):
#     def close(self):
#     CAINFO = 0
#     HTTPAUTH = 1
#     HTTPAUTH_DIGEST = 2
#     HTTPHEADER = 3
#     HTTPPOST = 4
#     HTTP_CODE = 5
#     SSL_VERIFYHOST = 6
#     SSL_VERIFYPEER = 7
#     URL = 8
#     USERPWD = 9
#     WRITEFUNCTION = 10
#     FAILONERROR = 11
#     FOLLOWLOCATION = 12
#     MAX_SEND_SPEED_LARGE = 13


import os
import os.path
import shutil
import tempfile
import unittest
from pyca import capture, config, db, utils
from tests.tools import should_fail, terminate_fn, reload
        config.config()['services']['org.opencastproject.capture.admin'] = ['']

        # Mock event
        db.init()
        self.event = db.BaseEvent()
        self.event.uid = '123123'
        self.event.title = u'äüÄÜß'
        self.event.start = utils.timestamp()
        self.event.end = self.event.start
        self.event.status = db.Status.UPCOMING
        data = [{'data': u'äüÄÜß',
                 'fmttype': 'application/xml',
                 'x-apple-filename': 'episode.xml'},
                {'data': u'äüÄÜß',
                 'fmttype': 'application/xml',
                 'x-apple-filename': 'series.xml'},
                {'data': u'event.title=äüÄÜß\n' +
                         u'org.opencastproject.workflow.config.x=123\n' +
                         u'org.opencastproject.workflow.definition=fast',
                 'fmttype': 'application/text',
                 'x-apple-filename': 'org.opencastproject.capture.agent' +
                                     '.properties'}]
        self.event.set_data({'attach': data})

    def tearDown(self):
        os.close(self.fd)
        os.remove(self.dbfile)
        shutil.rmtree(self.cadir)
        reload(capture)
        reload(config)

# Path: pyca/capture.py
# def sigterm_handler(signum, frame):
# def start_capture(db, upcoming_event):
# def safe_start_capture(event):
# def recording_command(event):
# def control_loop():
# def run():
#     DEVNULL = getattr(subprocess, 'DEVNULL', os.open(os.devnull, os.O_RDWR))
# 
# 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
# def init():
# def get_session():
# def with_session(f):
#     def decorated(*args, **kwargs):
#     def values(cls):
#     def str(cls, value):
#     def get_data(self):
#     def set_data(self, data):
#     def name(self):
#     def directory(self):
#     def remaining_duration(self, time):
#     def status_str(self):
#     def get_tracks(self):
#     def set_tracks(self, tracks):
#     def __repr__(self):
#     def serialize(self):
#     def __init__(self, event=None):
#     def __init__(self, service=None):
#     def update_sync_time(url):
# class Constants():
# class Status(Constants):
# class ServiceStatus(Constants):
# class Service(Constants):
# class BaseEvent():
# class UpcomingEvent(Base, BaseEvent):
# class RecordedEvent(Base, BaseEvent):
# class ServiceStates(Base):
# class UpstreamState(Base):
#     UPCOMING = 1
#     RECORDING = 2
#     FAILED_RECORDING = 3
#     FINISHED_RECORDING = 4
#     UPLOADING = 5
#     FAILED_UPLOADING = 6
#     FINISHED_UPLOADING = 7
#     PARTIAL_RECORDING = 8
#     PAUSED_AFTER_RECORDING = 9
#     STOPPED = 1
#     IDLE = 2
#     BUSY = 3
#     AGENTSTATE = 1
#     CAPTURE = 2
#     INGEST = 3
#     SCHEDULE = 4
# 
# Path: pyca/utils.py
# def http_request(url, post_data=None):
# def get_service(service_type):
# def timestamp():
# def try_mkdir(directory):
# def service(service_name, force_update=False):
# def ensurelist(x):
# def register_ca(status='idle'):
# def recording_state(recording_id, status):
# def update_event_status(dbs, event, status):
# def set_service_status(dbs, service, status):
# def set_service_status_immediate(service, status):
# def get_service_status(dbs, service):
# def update_agent_state():
# def terminate(shutdown=None):
# 
# Path: tests/tools.py
# class ShouldFailException(pycurl.error):
# class CurlMock():
# def should_fail(*args, **kwargs):
# def __terminate():
# def terminate_fn(num):
#     def setopt(self, *args):
#     def perform(self):
#     def getinfo(self, *args):
#     def close(self):
#     CAINFO = 0
#     HTTPAUTH = 1
#     HTTPAUTH_DIGEST = 2
#     HTTPHEADER = 3
#     HTTPPOST = 4
#     HTTP_CODE = 5
#     SSL_VERIFYHOST = 6
#     SSL_VERIFYPEER = 7
#     URL = 8
#     USERPWD = 9
#     WRITEFUNCTION = 10
#     FAILONERROR = 11
#     FOLLOWLOCATION = 12
#     MAX_SEND_SPEED_LARGE = 13


# Path: tests/test_capture.py
import os
import os.path
import shutil
import tempfile
import unittest
from pyca import capture, config, db, utils
from tests.tools import should_fail, terminate_fn, reload

        config.config()['services']['org.opencastproject.capture.admin'] = ['']

        # Mock event
        db.init()
        self.event = db.BaseEvent()
        self.event.uid = '123123'
        self.event.title = u'äüÄÜß'
        self.event.start = utils.timestamp()
        self.event.end = self.event.start
        self.event.status = db.Status.UPCOMING
        data = [{'data': u'äüÄÜß',
                 'fmttype': 'application/xml',
                 'x-apple-filename': 'episode.xml'},
                {'data': u'äüÄÜß',
                 'fmttype': 'application/xml',
                 'x-apple-filename': 'series.xml'},
                {'data': u'event.title=äüÄÜß\n' +
                         u'org.opencastproject.workflow.config.x=123\n' +
                         u'org.opencastproject.workflow.definition=fast',
                 'fmttype': 'application/text',
                 'x-apple-filename': 'org.opencastproject.capture.agent' +
                                     '.properties'}]
        self.event.set_data({'attach': data})

    def tearDown(self):
        os.close(self.fd)
        os.remove(self.dbfile)
        shutil.rmtree(self.cadir)
        reload(capture)
        reload(config)

        reload(utils)