#!/usr/bin/env python # -*- coding: utf8 -*- from datetime import datetime from os import path, getenv from sys import exit import ConfigParser import logging def str_to_bol(string): return 'true' in string.lower() # Initiate logging logging.basicConfig(level=logging.INFO, filename='/tmp/screenly_viewer.log', format='%(asctime)s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S') # Silence urllib info messages ('Starting new HTTP connection') # that are triggered by the remote url availability check in view_web requests_log = logging.getLogger("requests") requests_log.setLevel(logging.WARNING) logging.debug('Starting viewer.py') # Get config file config = ConfigParser.ConfigParser() conf_file = path.join(getenv('HOME'), '.screenly', 'screenly.conf') if not path.isfile(conf_file): print 'Config-file missing.' logging.error('Config-file missing.') exit(1) else: logging.debug('Reading config-file...') config.read(conf_file) # Get config values configdir = path.join(getenv('HOME'), config.get('main', 'configdir')) database = path.join(getenv('HOME'), config.get('main', 'database')) nodetype = config.get('main', 'nodetype') show_splash = str_to_bol(config.get('viewer', 'show_splash')) audio_output = config.get('viewer', 'audio_output') shuffle_playlist = str_to_bol(config.get('viewer', 'shuffle_playlist')) asset_folder = path.join(getenv('HOME'), 'screenly_assets') try: resolution = config.get('viewer', 'resolution') except: resolution = '1920x1080' try: # Expect the string in format: ip:port listen = config.get('main', 'listen').split(':') listen_ip = listen[0] listen_port = listen[1] except: listen_ip = '0.0.0.0' listen_port = '8080' # This assumes nodetype never changes from "standalone" to "managed" during a run. get_current_time = datetime.now if nodetype == "standalone" else datetime.utcnow