Ejemplo n.º 1
0
    def presentation(self):
        self.services.getServices(readyOnly=True)

        # Make sure we have network
        if not helper.hasNetwork() and self.settings.getUser(
                'offline-behavior') == 'wait':
            self.waitForNetwork()

        if not slideshow.SHOWN_IP:
            self.startupScreen()

        logging.info('Starting presentation')
        i = 0
        while True:
            i += 1
            time_process = time.time()

            # Avoid showing images if the display is off
            if self.queryPowerFunc is not None and self.queryPowerFunc(
            ) is False:
                logging.info("Display is off, exit quietly")
                break

            #if (i % 100) == 0:
            #  CacheManager.garbageCollect(cacheFolder)

            displaySize = {
                'width': self.settings.getUser('width'),
                'height': self.settings.getUser('height'),
                'force_orientation': self.settings.getUser('force_orientation')
            }
            randomize = (not self.ignoreRandomize) and bool(
                self.settings.getUser('randomize_images'))
            self.ignoreRandomize = False

            try:
                result = self.services.servicePrepareNextItem(
                    self.settings.get('tempfolder'), self.supportedFormats,
                    displaySize, randomize)
                if self.handleErrors(result):
                    continue
            except RequestNoNetwork:
                offline = self.settings.getUser('offline-behavior')
                if offline == 'wait':
                    self.waitForNetwork()
                    continue
                elif offline == 'ignore':
                    pass

            filenameProcessed = self.process(result)
            if filenameProcessed is None:
                continue

            time_process = time.time() - time_process
            self.delayNextImage(time_process)
            self.handleEvents()
            self.showPreloadedImage(filenameProcessed, result.mimetype,
                                    result.id)

        self.thread = None
Ejemplo n.º 2
0
    def handle(self, app, about):
        if about == 'tvservice':
            result = {}
            result['resolution'] = self.displaymgr.available()
            result['status'] = self.displaymgr.current()
            return self.jsonify(result)
        elif about == 'current':
            image, mime = self.displaymgr.get()
            response = app.make_response(image)
            response.headers.set('Content-Type', mime)
            return response
        elif about == 'drivers':
            result = self.drivermgr.list().keys()
            return self.jsonify(result)
        elif about == 'timezone':
            result = helper.timezoneList()
            return self.jsonify(result)
        elif about == 'version':
            output = subprocess.check_output(['git', 'log', '-n1'],
                                             stderr=self.void)
            lines = output.split('\n')
            infoDate = lines[2][5:].strip()
            infoCommit = lines[0][7:].strip()
            output = subprocess.check_output(['git', 'status'],
                                             stderr=self.void)
            lines = output.split('\n')
            infoBranch = lines[0][10:].strip()
            return self.jsonify({
                'date': infoDate,
                'commit': infoCommit,
                'branch': infoBranch
            })
        elif about == 'color':
            return self.jsonify(self.slideshow.getColorInformation())
        elif about == 'sensor':
            return self.jsonify({'sensor': self.colormatch.hasSensor()})
        elif about == 'display':
            return self.jsonify({'display': self.displaymgr.isEnabled()})
        elif about == 'network':
            return self.jsonify({'network': helper.hasNetwork()})

        self.setAbort(404)
Ejemplo n.º 3
0
    def handle(self, app, about):
        if about == 'tvservice':
            result = {}
            result['resolution'] = self.displaymgr.available()
            result['status'] = self.displaymgr.current()
            return self.jsonify(result)
        elif about == 'current':
            image, mime = self.displaymgr.get()
            response = app.make_response(image)
            response.headers.set('Content-Type', mime)
            return response
        elif about == 'drivers':
            result = self.drivermgr.list().keys()
            return self.jsonify(result)
        elif about == 'timezone':
            result = helper.timezoneList()
            return self.jsonify(result)
        elif about == 'version':
            output = subprocess.check_output(['git', 'log', '-n1'],
                                             stderr=self.void)
            lines = output.split('\n')
            infoDate = lines[2][5:].strip()
            infoCommit = lines[0][7:].strip()
            output = subprocess.check_output(['git', 'status'],
                                             stderr=self.void)
            lines = output.split('\n')
            infoBranch = lines[0][10:].strip()
            return self.jsonify({
                'date': infoDate,
                'commit': infoCommit,
                'branch': infoBranch
            })
        elif about == 'color':
            return self.jsonify(self.slideshow.getColorInformation())
        elif about == 'sensor':
            return self.jsonify({'sensor': self.colormatch.hasSensor()})
        elif about == 'display':
            return self.jsonify({'display': self.displaymgr.isEnabled()})
        elif about == 'network':
            return self.jsonify({'network': helper.hasNetwork()})
        elif about == 'hardware':
            output = ''
            try:
                output = subprocess.check_output(
                    ['/opt/vc/bin/vcgencmd', 'get_throttled'],
                    stderr=self.void)
            except:
                logging.exception('Unable to execute /opt/vc/bin/vcgencmd')
            if not output.startswith('throttled='):
                logging.error('Output from vcgencmd get_throttled has changed')
                output = 'throttled=0x0'
            try:
                h = int(output[10:].strip(), 16)
            except:
                logging.exception(
                    'Unable to convert output from vcgencmd get_throttled')
            result = {
                'undervoltage': h & (1 << 0 | 1 << 16) > 0,
                'frequency': h & (1 << 1 | 1 << 17) > 0,
                'throttling': h & (1 << 2 | 1 << 18) > 0,
                'temperature': h & (1 << 3 | 1 << 19) > 0
            }
            return self.jsonify(result)
        elif about == 'messages':
            # This should be made more general purpose since other parts need similar service
            msgs = []
            images = self.servicemgr.getTotalImageCount
            timeneeded = images * self.settings.getUser('interval')
            timeavailable = self.settings.getUser('refresh') * 3600
            if timeavailable > 0 and timeneeded > timeavailable:
                msgs.append({
                    'level':
                    'WARNING',
                    'message':
                    'Change every %d seconds with %d images will take %dh, refresh keywords is %dh'
                    % (self.settings.getUser('interval'), images,
                       timeneeded / 3600, timeavailable / 3600),
                    'link':
                    None
                })

            return self.jsonify(msgs)
        self.setAbort(404)
Ejemplo n.º 4
0
    def presentation(self):
        self.services.getServices(readyOnly=True)

        # Make sure we have network
        if not helper.hasNetwork() and self.settings.getUser(
                'offline-behavior') == 'wait':
            self.waitForNetwork()

        if not slideshow.SHOWN_IP:
            self.startupScreen()

        logging.info('Starting presentation')
        i = 0
        while self.running:
            i += 1
            time_process = time.time()

            if (i % 10) == 0:
                self.cacheMgr.garbageCollect()

            displaySize = {
                'width': self.settings.getUser('width'),
                'height': self.settings.getUser('height'),
                'force_orientation': self.settings.getUser('force_orientation')
            }
            randomize = (not self.ignoreRandomize) and bool(
                self.settings.getUser('randomize_images'))
            self.ignoreRandomize = False

            try:
                result = self.services.servicePrepareNextItem(
                    self.settings.get('tempfolder'), self.supportedFormats,
                    displaySize, randomize)
                if self.handleErrors(result):
                    continue
            except RequestNoNetwork:
                offline = self.settings.getUser('offline-behavior')
                if offline == 'wait':
                    self.waitForNetwork()
                    continue
                elif offline == 'ignore':
                    pass

            filenameProcessed = self.process(result)
            if filenameProcessed is None:
                continue

            time_process = time.time() - time_process
            self.delayNextImage(time_process)
            if self.running:
                # Skip this section if we were killed while waiting around
                self.handleEvents()
                self.showPreloadedImage(filenameProcessed, result.mimetype,
                                        result.id)

        self.thread = None
        logging.info('slideshow has ended')

        # Callback if anyone was listening
        if self.cbStopped is not None:
            logging.debug('Stop required notification, so call them')
            tmp = self.cbStopped
            self.cbStopped = None
            tmp()
Ejemplo n.º 5
0
  def presentation(self):
    self.services.getServices(readyOnly=True)

    # Make sure we have network
    if not helper.hasNetwork() and self.settings.getUser('offline-behavior') == 'wait':
      self.waitForNetwork()

    if not slideshow.SHOWN_IP:
      self.startupScreen()

    logging.info('Starting presentation')
    i = 0
    result = None
    lastCfg = self.services.getConfigChange()
    while self.running:
      i += 1
      time_process = time.time()

      if (i % 10) == 0:
        self.cacheMgr.garbageCollect()

      displaySize = {'width': self.settings.getUser('width'), 'height': self.settings.getUser('height'), 'force_orientation': self.settings.getUser('force_orientation')}
      randomize = self.settings.getUser('randomize_images')

      try:
        if self.historyIndex == -1:
          result = self.services.servicePrepareNextItem(self.settings.get('tempfolder'), self.supportedFormats, displaySize, randomize)
          self.remember(result)
        else:
          logging.info('Fetching history image %d of %d', self.historyIndex, self.history.getAvailable())
          result = self.history.getByIndex(self.historyIndex)
          self.historyIndex = max(-1, self.historyIndex-1)
      except RequestNoNetwork:
        offline = self.settings.getUser('offline-behavior')
        if offline == 'wait':
          self.waitForNetwork()
          continue
        elif offline == 'ignore':
          pass

      if not self.handleErrors(result):
        filenameProcessed = self.process(result)
        result = result.copy().setFilename(filenameProcessed)
      else:
        result = None

      time_process = time.time() - time_process
      logging.debug('Took %f seconds to process, next image is %s', time_process, result.filename if result is not None else "None")
      self.delayNextImage(time_process)

      showNextImage = self.handleEvents()

      # Handle changes to config to avoid showing an image which is unexpected
      if self.services.getConfigChange() != lastCfg:
        logging.debug('Services have changed, skip next photo and get fresh one')
        self.skipPreloadedImage = True
        lastCfg = self.services.getConfigChange()

      if self.running and result is not None:
        # Skip this section if we were killed while waiting around
        if showNextImage and not self.skipPreloadedImage:
          self.showPreloadedImage(result)
        else:
          self.imageCurrent = None
          self.skipPreloadedImage = False
        logging.debug('Deleting temp file "%s"' % result.filename)
        os.unlink(result.filename)

    self.thread = None
    logging.info('slideshow has ended')

    # Callback if anyone was listening
    if self.cbStopped is not None:
      logging.debug('Stop required notification, so call them')
      tmp = self.cbStopped
      self.cbStopped = None
      tmp()