# 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


from pyca.config import config
from pyca import db
from datetime import datetime
from dateutil.tz import tzutc
from io import BytesIO as bio
from urllib.parse import quote as urlquote
import errno
import json
import logging
import os
import os.path
import pycurl
import time
            logger.info(response)
    except pycurl.error as e:
        logger.warning('Could not set agent state to %s: %s', status, e)


def recording_state(recording_id, status):
    '''Send the state of the current recording to the Matterhorn core.

    :param recording_id: ID of the current recording
    :param status: Status of the recording
    '''
    # If this is a backup CA we do not update the recording state since the
    # actual CA does that and we want to interfere.  We will just run silently
    # in the background:
    if config('agent', 'backup_mode'):
        return
    params = [('state', status)]
    url = service('capture.admin')[0]
    url += f'/recordings/{recording_id}'
    try:
        result = http_request(url, params).decode('utf-8')
        logger.info(result)
    except pycurl.error as e:
        logger.warning('Could not set recording state to %s: %s', status, e)


@db.with_session
def update_event_status(dbs, event, status):
    '''Update the status of a particular event in the database.
    '''

# 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
from pyca.config import config
from pyca import db
from datetime import datetime
from dateutil.tz import tzutc
from io import BytesIO as bio
from urllib.parse import quote as urlquote
import errno
import json
import logging
import os
import os.path
import pycurl
import time

            logger.info(response)
    except pycurl.error as e:
        logger.warning('Could not set agent state to %s: %s', status, e)


def recording_state(recording_id, status):
    '''Send the state of the current recording to the Matterhorn core.

    :param recording_id: ID of the current recording
    :param status: Status of the recording
    '''
    # If this is a backup CA we do not update the recording state since the
    # actual CA does that and we want to interfere.  We will just run silently
    # in the background:
    if config('agent', 'backup_mode'):
        return
    params = [('state', status)]
    url = service('capture.admin')[0]
    url += f'/recordings/{recording_id}'
    try:
        result = http_request(url, params).decode('utf-8')
        logger.info(result)
    except pycurl.error as e:
        logger.warning('Could not set recording state to %s: %s', status, e)


@db.with_session
def update_event_status(dbs, event, status):
    '''Update the status of a particular event in the database.
    '''

    dbs.query(db.RecordedEvent).filter(db.RecordedEvent.start == event.start)\