예제 #1
0
    def __init__(self):
        self.archive = site_registry().archive
        self.log = site_registry().log
        self.session = site_registry().session
        self.queue_check_loop = LoopingCall(self.queue_check)
        self.recordings = Recordings()
        self.config = site_registry().config

        reactor.callLater(2, self.start_loop)
예제 #2
0
class ArchiveServer(XMLRPC):
    """ Archive XMLRPC Server
    Used to add the MythTV recording to the Queue.
    """
    def __init__(self, *args, **kwargs):
        XMLRPC.__init__(self, *args, **kwargs)
        self.recording = Recordings()
        self.log = registry.site_registry().log

    @property
    def queue(self):
        return registry.site_registry().queue

    def _get_return_value(self, message, success):
        return {
            'message': message,
            'success': success
        }

    def _archive(self, chanID, startTime, quality):
        program = self.recording.get_recording(chanID, startTime)
        if program:
            msg = 'Archiving %s. (%s, %s)' % (program.title, chanID, startTime)
            self.log.info(msg)
            result = self._get_return_value(msg, True)
            self.queue.add_to_queue(program, quality)
        else:
            msg = 'Could not find Recording: %r, %r' % (chanID, startTime)
            self.log.info(msg)
            result = self._get_return_value(msg, False)
        return result

    def xmlrpc_archive(self, chanID, startTime, quality):
        """ XMLRPC Archive
        @param: chanID: String: MythTV Channel ID
        @param: startTime: MythTV UTC Start Time
        @param: quality: Handbrake Quality
        """
        if Quality.validate(quality):
            return self._archive(chanID, startTime, quality)
        else:
            msg = 'Invalid Quality: %r' % quality
            self.log.error(msg)
            return self._get_return_value(msg, False)
예제 #3
0
 def __init__(self, *args, **kwargs):
     XMLRPC.__init__(self, *args, **kwargs)
     self.recording = Recordings()
     self.log = registry.site_registry().log
예제 #4
0
class QueueController(object):

    def __init__(self):
        self.archive = site_registry().archive
        self.log = site_registry().log
        self.session = site_registry().session
        self.queue_check_loop = LoopingCall(self.queue_check)
        self.recordings = Recordings()
        self.config = site_registry().config

        reactor.callLater(2, self.start_loop)

    def start_loop(self, *args):
        self.queue_check_loop.start(1, now=False)

    def stop_loop(self):
        self.queue_check_loop.stop()

    def lock(self):
        """ Lock
        Lock the queue by stopping the queue check loop.
        """
        self.stop_loop()
        self.log.info('Locking Thread')

    def clear_lock(self, queue_id):
        """ Clear Lock
        Clear the lock by starting the queue check loop.
        """
        self.log.info('Unlocking Thread')
        self.update_status(queue_id, StatusType.finished)
        self.start_loop()

    def record_error(self, queue_id, message):
        """ Record Error
        Record a queue error.
        """
        self.log.error(message)
        self.update_status(queue_id, StatusType.error, message=message)
        self.start_loop()

    @inlineCallbacks
    def queue_check(self):
        """ Queue Check
        Check queue for new recording to archive.
        """
        queue = self.get_next_queue()
        if queue:
            self.lock()
            queue.queued = False
            self.update_status(queue.id, StatusType.running)
            try:
                self.log.info('Processing: %s - %s' % (queue.chan_id, queue.start_time))
                start_time_str = '%sZ' % str(queue.start_time).replace(' ', 'T')
                program = self.recordings.get_recording(queue.chan_id, start_time_str)
                yield self.archive.process(queue, program)
            except ArchiveError, e:
                try:
                    if self.config.cleanup_on_error:
                        self.archive.cleanup()
                except:
                    pass
                self.record_error(queue.id, str(e))
            else:
                self.clear_lock(queue.id)