示例#1
0
def asset_loop(scheduler):
    check_update()
    asset = scheduler.get_next_asset()

    if asset is None:
        logging.info('Playlist is empty. Sleeping for %s seconds', EMPTY_PL_DELAY)
        view_image(HOME + LOAD_SCREEN)
        sleep(EMPTY_PL_DELAY)

    elif path.isfile(asset['uri']) or not url_fails(asset['uri']):
        name, mime, uri = asset['name'], asset['mimetype'], asset['uri']
        logging.info('Showing asset %s (%s)', name, mime)
        logging.debug('Asset URI %s', uri)
        watchdog()

        if 'image' in mime:
            view_image(uri)
        elif 'web' in mime:
            # FIXME If we want to force periodic reloads of repeated web assets, force=True could be used here.
            # See e38e6fef3a70906e7f8739294ffd523af6ce66be.
            browser_url(uri)
        elif 'video' in mime:
            view_video(uri, asset['duration'])
        else:
            logging.error('Unknown MimeType %s', mime)

        if 'image' in mime or 'web' in mime:
            duration = int(asset['duration'])
            logging.info('Sleeping for %s', duration)
            sleep(duration)
    else:
        logging.info('Asset %s at %s is not available, skipping.', asset['name'], asset['uri'])
        sleep(0.5)
示例#2
0
def asset_loop(scheduler):
    check_update()
    asset = scheduler.get_next_asset()

    if asset is None:
        logging.info("Playlist is empty. Sleeping for %s seconds", EMPTY_PL_DELAY)
        view_image(HOME + LOAD_SCREEN)
        sleep(EMPTY_PL_DELAY)

    elif path.isfile(asset["uri"]) or not url_fails(asset["uri"]):
        name, mime, uri = asset["name"], asset["mimetype"], asset["uri"]
        logging.info("Showing asset %s (%s)", name, mime)
        logging.debug("Asset URI %s", uri)
        watchdog()

        if "image" in mime:
            view_image(uri)
        elif "web" in mime:
            # FIXME If we want to force periodic reloads of repeated web assets, force=True could be used here.
            # See e38e6fef3a70906e7f8739294ffd523af6ce66be.
            browser_url(uri)
        elif "video" in mime:
            view_video(uri, asset["duration"])
        else:
            logging.error("Unknown MimeType %s", mime)

        if "image" in mime or "web" in mime:
            duration = int(asset["duration"])
            logging.info("Sleeping for %s", duration)
            sleep(duration)
    else:
        logging.info("Asset %s at %s is not available, skipping.", asset["name"], asset["uri"])
        sleep(0.5)
示例#3
0
def check_update():
    """
    Check if there is a later version of Screenly-OSE
    available. Only do this update once per day.
    Return True if up to date was written to disk,
    False if no update needed and None if unable to check.
    """

    sha_file = path.join(settings.get_configdir(), 'latest_screenly_sha')

    if path.isfile(sha_file):
        sha_file_mtime = path.getmtime(sha_file)
        last_update = datetime.fromtimestamp(sha_file_mtime)
    else:
        last_update = None

    logging.debug('Last update: %s' % str(last_update))

    if last_update is None or last_update < (datetime.now() - timedelta(days=1)):

        if not url_fails('http://stats.screenlyapp.com'):
            latest_sha = req_get('http://stats.screenlyapp.com/latest')

            if latest_sha.status_code == 200:
                with open(sha_file, 'w') as f:
                    f.write(latest_sha.content.strip())
                return True
            else:
                logging.debug('Received non 200-status')
                return
        else:
            logging.debug('Unable to retreive latest SHA')
            return
    else:
        return False
示例#4
0
    def post(self):
        asset = prepare_asset_v1_2(request)
        if url_fails(asset['uri']):
            raise Exception("Could not retrieve file. Check the asset URL.")
        with db.conn(settings['database']) as conn:
            assets = assets_helper.read(conn)
            ids_of_active_assets = [x['asset_id'] for x in assets if x['is_active']]

            asset = assets_helper.create(conn, asset)

            if asset['is_active']:
                ids_of_active_assets.insert(asset['play_order'], asset['asset_id'])
            assets_helper.save_ordering(conn, ids_of_active_assets)
            return assets_helper.read(conn, asset['asset_id']), 201
示例#5
0
def check_update():
    """
    Check if there is a later version of Screenly-OSE
    available. Only do this update once per day.

    Return True if up to date was written to disk,
    False if no update needed and None if unable to check.
    """
    # No update check in FSG edition
    return True

    sha_file = path.join(settings.get_configdir(), "latest_screenly_sha")

    if path.isfile(sha_file):
        sha_file_mtime = path.getmtime(sha_file)
        last_update = datetime.fromtimestamp(sha_file_mtime)
    else:
        last_update = None

    logging.debug("Last update: %s" % str(last_update))

    git_branch = sh.git("rev-parse", "--abbrev-ref", "HEAD")
    if last_update is None or last_update < (datetime.now() - timedelta(days=1)):

        if not url_fails("http://stats.screenlyapp.com"):
            latest_sha = req_get("http://stats.screenlyapp.com/latest/{}".format(git_branch))

            if latest_sha.status_code == 200:
                with open(sha_file, "w") as f:
                    f.write(latest_sha.content.strip())
                return True
            else:
                logging.debug("Received non 200-status")
                return
        else:
            logging.debug("Unable to retrieve latest SHA")
            return
    else:
        return False
示例#6
0
 def post(self):
     asset = prepare_asset(request, unique_name=True)
     if url_fails(asset['uri']):
         raise Exception("Could not retrieve file. Check the asset URL.")
     with db.conn(settings['database']) as conn:
         return assets_helper.create(conn, asset), 201
示例#7
0
def add_asset():
    asset = prepare_asset(request)
    if url_fails(asset['uri']):
        raise Exception("Could not retrieve file. Check the asset URL.")
    return assets_helper.create(db_conn, asset)
示例#8
0
 def post(self):
     asset = prepare_asset(request)
     if url_fails(asset['uri']):
         raise Exception("Could not retrieve file. Check the asset URL.")
     with db.conn(settings['database']) as conn:
         return assets_helper.create(conn, asset), 201
示例#9
0
def add_asset():
    asset = prepare_asset(request)
    if url_fails(asset['uri']):
        raise Exception("Could not retrieve file. Check the asset URL.")
    return assets_helper.create(db_conn, asset)