def load_browser(): logging.info('Loading browser...') global is_pro_init is_pro_init = get_is_pro_init() if not is_pro_init: logging.debug('Detected Pro initiation cycle.') # Wait for the intro file to exist (if it doesn't) intro_file = '/home/pi/.screenly/intro.html' while not path.isfile(intro_file): logging.debug('intro.html missing. Going to sleep.') sleep(0.5) browser_load_url = 'file://' + intro_file elif settings['show_splash']: browser_load_url = "http://%s:%s/splash_page" % (settings.get_listen_ip(), settings.get_listen_port()) else: browser_load_url = black_page browser = sh.Command('uzbl-browser')(uri=browser_load_url, _bg=True) logging.info('Browser loaded. Running as PID %d.' % browser.pid) if settings['show_splash']: # Show splash screen for 60 seconds. sleep(60) else: # Give browser some time to start (we have seen multiple uzbl running without this) sleep(10) return browser
def load_browser(): logging.info('Loading browser...') global is_pro_init, current_browser_url is_pro_init = get_is_pro_init() if not is_pro_init: logging.debug('Detected Pro initiation cycle.') # Wait for the intro file to exist (if it doesn't) intro_file = path.join(settings.get_configdir(), 'intro.html') while not path.isfile(intro_file): logging.debug('intro.html missing. Going to sleep.') sleep(0.5) browser_load_url = 'file://' + intro_file elif settings['show_splash']: browser_load_url = "http://%s:%s/splash_page" % (settings.get_listen_ip(), settings.get_listen_port()) else: browser_load_url = black_page geom = [l for l in sh.xwininfo('-root').split("\n") if 'geometry' in l][0].split('y ')[1] browser = sh.Command('uzbl-browser')(g=geom, uri=browser_load_url, _bg=True) current_browser_url = browser_load_url logging.info('Browser loaded. Running as PID %d.' % browser.pid) if settings['show_splash']: # Show splash screen for 60 seconds. sleep(60) else: # Give browser some time to start (we have seen multiple uzbl running without this) sleep(10) return browser
def splash_page(): my_ip = get_node_ip() if my_ip: ip_lookup = True url = "http://{}:{}".format(my_ip, settings.get_listen_port()) else: ip_lookup = False url = "Unable to look up your installation's IP address." return template('splash_page', ip_lookup=ip_lookup, url=url)
def main(): setup() url = 'http://{0}:{1}/splash_page'.format(settings.get_listen_ip(), settings.get_listen_port()) if settings['show_splash'] else 'file://' + BLACK_PAGE load_browser(url=url) if settings['show_splash']: sleep(SPLASH_DELAY) scheduler = Scheduler() logging.debug('Entering infinite loop.') while True: asset_loop(scheduler)
def splash_page(): my_ip = get_node_ip() if my_ip: ip_lookup = True # If we bind on 127.0.0.1, `enable_ssl.sh` has most likely been # executed and we should access over SSL. if settings.get_listen_ip() == '127.0.0.1': url = 'https://{}'.format(my_ip) else: url = "http://{}:{}".format(my_ip, settings.get_listen_port()) else: ip_lookup = False url = "Unable to look up your installation's IP address." return template('splash_page', ip_lookup=ip_lookup, url=url)
def main(): setup() url = ( "http://{0}:{1}/splash_page".format(settings.get_listen_ip(), settings.get_listen_port()) if settings["show_splash"] else "file://" + BLACK_PAGE ) load_browser(url=url) if settings["show_splash"]: sleep(SPLASH_DELAY) scheduler = Scheduler() logging.debug("Entering infinite loop.") while True: asset_loop(scheduler)
def splash_page(): try: my_ip = get_node_ip() except Exception as e: ip_lookup = False error_msg = e else: ip_lookup = True # If we bind on 127.0.0.1, `enable_ssl.sh` has most likely been # executed and we should access over SSL. if settings.get_listen_ip() == '127.0.0.1': url = 'https://{}'.format(my_ip) else: url = "http://{}:{}".format(my_ip, settings.get_listen_port()) msg = url if url else error_msg return template('splash_page', ip_lookup=ip_lookup, msg=msg)
def __init__(self): global home home = getenv('HOME', '/home/pi') self.currentId = None self.currentDirectory = None self.worker = None signal(SIGUSR1, sigusr1) signal(SIGUSR2, sigusr2) settings.load() logging.getLogger().setLevel(logging.INFO) try: sh.mkdir(SCREENLY_HTML) except: pass html_templates.black_page(BLACK_PAGE) load_browser(url='http://{0}:{1}/splash_page'.format( settings.get_listen_ip(), settings.get_listen_port())) sleep(30)
def load_browser(): logging.info('Loading browser...') browser_bin = "uzbl-browser" browser_resolution = settings['resolution'] if settings['show_splash']: browser_load_url = "http://%s:%s/splash_page" % (settings.get_listen_ip(), settings.get_listen_port()) else: browser_load_url = black_page browser_args = [browser_bin, "--geometry=" + browser_resolution, "--uri=" + browser_load_url] browser = Popen(browser_args) logging.info('Browser loaded. Running as PID %d.' % browser.pid) if settings['show_splash']: # Show splash screen for 60 seconds. sleep(60) else: # Give browser some time to start (we have seen multiple uzbl running without this) sleep(10) return browser
def load_browser(): logging.info('Loading browser...') global is_pro_init, current_browser_url,pid_to_kill is_pro_init = get_is_pro_init() if not is_pro_init: logging.debug('Detected Pro initiation cycle.') # Wait for the intro file to exist (if it doesn't) intro_file = path.join(settings.get_configdir(), 'intro.html') while not path.isfile(intro_file): logging.debug('intro.html missing. Going to sleep.') sleep(0.5) browser_load_url = 'file://' + intro_file elif settings['show_splash']: browser_load_url = "http://%s:%s/splash_page" % (settings.get_listen_ip(), settings.get_listen_port()) else: browser_load_url = black_page browser = sh.Command('chromium-browser')(browser_load_url,disable_restore_background_contents=True,disable_restore_session_state=False,kiosk=True,_bg=True) current_browser_url = browser_load_url logging.info('Browser loaded. Running as PID %d.' % browser.pid) if settings['show_splash']: # Show splash screen for 60 seconds. sleep(60) else: # Give browser some time to start (we have seen multiple uzbl running without this) sleep(10) pid_to_kill=browser.pid logging.info('Done') return browser
api.add_resource(FileAsset, '/api/v1/file_asset') api.add_resource(PlaylistOrder, '/api/v1/assets/order') api.add_resource(Backup, '/api/v1/backup') api.add_resource(Recover, '/api/v1/recover') api.add_resource(AssetsControl, '/api/v1/assets/control/<command>') try: my_ip = get_node_ip() except: pass else: SWAGGER_URL = '/api/docs' swagger_address = getenv("SWAGGER_HOST", my_ip) if swagger_address == my_ip: swagger_address += ":{}".format(settings.get_listen_port()) if settings.get_listen_ip() == '127.0.0.1': API_URL = 'https://{}/api/swagger.json'.format(swagger_address) else: API_URL = "http://{}/api/swagger.json".format(swagger_address) swaggerui_blueprint = get_swaggerui_blueprint( SWAGGER_URL, API_URL, config={'app_name': "Screenly API"}) app.register_blueprint(swaggerui_blueprint, url_prefix=SWAGGER_URL) ################################ # Views ################################
return 'Sorry, this page does not exist!' ################################ # Static ################################ @route('/static/:path#.+#', name='static') def static(path): return static_file(path, root='static') if __name__ == "__main__": # Make sure the asset folder exist. If not, create it if not path.isdir(settings['assetdir']): mkdir(settings['assetdir']) # Create config dir if it doesn't exist if not path.isdir(settings.get_configdir()): makedirs(settings.get_configdir()) with db.conn(settings['database']) as conn: global db_conn db_conn = conn with db.cursor(db_conn) as c: c.execute(queries.exists_table) if c.fetchone() is None: c.execute(assets_helper.create_assets_table) run(host=settings.get_listen_ip(), port=settings.get_listen_port(), fast=True, reloader=True)
def match_details(): my_ip = get_node_ip() url = "http://{}:{}".format(my_ip, settings.get_listen_port()) return template('match_details', url=url)
api.add_resource(PlaylistOrder, '/api/v1/assets/order') api.add_resource(Backup, '/api/v1/backup') api.add_resource(Recover, '/api/v1/recover') api.add_resource(AssetsControl, '/api/v1/assets/control/<command>') api.add_resource(Info, '/api/v1/info') try: my_ip = get_node_ip() except: pass else: SWAGGER_URL = '/api/docs' swagger_address = getenv("SWAGGER_HOST", my_ip) if swagger_address == my_ip: swagger_address += ":{}".format(settings.get_listen_port()) if settings.get_listen_ip() == '127.0.0.1': API_URL = 'https://{}/api/swagger.json'.format(swagger_address) else: API_URL = "http://{}/api/swagger.json".format(swagger_address) swaggerui_blueprint = get_swaggerui_blueprint( SWAGGER_URL, API_URL, config={ 'app_name': "Screenly API" } ) app.register_blueprint(swaggerui_blueprint, url_prefix=SWAGGER_URL)
if __name__ == "__main__": # Make sure the asset folder exist. If not, create it if not path.isdir(settings['assetdir']): mkdir(settings['assetdir']) # Create config dir if it doesn't exist if not path.isdir(settings.get_configdir()): makedirs(settings.get_configdir()) with db.conn(settings['database']) as conn: with db.cursor(conn) as cursor: cursor.execute(queries.exists_table) if cursor.fetchone() is None: cursor.execute(assets_helper.create_assets_table) config = { 'bind': '{}:{}'.format(settings.get_listen_ip(), int(settings.get_listen_port())), 'threads': 2, 'timeout': 20 } class GunicornApplication(Application): def init(self, parser, opts, args): return config def load(self): return app GunicornApplication().run()
################################ # Static ################################ @route('/static/:path#.+#', name='static') def static(path): return static_file(path, root='static') if __name__ == "__main__": # Make sure the asset folder exist. If not, create it if not path.isdir(settings['assetdir']): mkdir(settings['assetdir']) # Create config dir if it doesn't exist if not path.isdir(settings.get_configdir()): makedirs(settings.get_configdir()) with db.conn(settings['database']) as conn: global db_conn db_conn = conn with db.cursor(db_conn) as c: c.execute(queries.exists_table) if c.fetchone() is None: c.execute(assets_helper.create_assets_table) run(host=settings.get_listen_ip(), port=settings.get_listen_port(), fast=True, reloader=True)
@error(403) def mistake403(code): return "The parameter you passed has the wrong format!" @error(404) def mistake404(code): return "Sorry, this page does not exist!" ################################ # Static ################################ @route("/static/:path#.+#", name="static") def static(path): return static_file(path, root="static") if __name__ == "__main__": # Make sure the asset folder exist. If not, create it if not path.isdir(settings.get_asset_folder()): mkdir(settings.get_asset_folder()) initiate_db() run(host=settings.get_listen_ip(), port=settings.get_listen_port(), reloader=True)
# Static ################################ @route('/static/:path#.+#', name='static') def static(path): return static_file(path, root='static') if __name__ == "__main__": # Make sure the asset folder exist. If not, create it if not path.isdir(settings['assetdir']): mkdir(settings['assetdir']) # Create config dir if it doesn't exist if not path.isdir(settings.get_configdir()): makedirs(settings.get_configdir()) with db.conn(settings['database']) as conn: global db_conn db_conn = conn with db.cursor(db_conn) as c: c.execute(queries.exists_table) if c.fetchone() is None: c.execute(assets_helper.create_assets_table) run( host=settings.get_listen_ip(), port=settings.get_listen_port(), server='gunicorn', timeout=240, )
def run(self): directory = self.entry.directory files = [ path.join(directory, f) for f in os.listdir(directory) if path.isfile(path.join(directory, f)) ] num_files = len(files) if num_files == 0: load_browser(url='http://{0}:{1}/splash_page'.format( settings.get_listen_ip(), settings.get_listen_port() ) if settings['show_splash'] else 'file://' + BLACK_PAGE) while not self.__stop.isSet(): sleep(self.loopTime) else: num = 0 currentEntryDuration = 0 mime = None file = None isNew = True while not self.__stop.isSet(): logging.info("worker still waiting %d seconds for %s" % (currentEntryDuration, file)) if currentEntryDuration <= 0: kill_player() file = files[num] mime = get_mimetype(file) num = (num + 1) % num_files if mime is not None: if 'image' in mime: currentEntryDuration = get_setting( 'image_duration', DEFAULT_DURATION, cast=int) view_image(file, force=isNew) isNew = False elif 'text' in mime: currentEntryDuration = get_setting( 'webpage_duration', DEFAULT_DURATION, cast=int) with open(file, 'r') as urlfile: try: line = urlfile.readlines()[0].replace( '\n', '') prefix = line[:5] if prefix == "live:": currentEntryDuration = 24 * 60 * 60 # large number of seconds VideoThread(line[5:]).start() else: view_url(line, force=isNew) except Exception as e: currentEntryDuration = 0 logging.error( 'cannot show text file: %s, error: %s' % (file, e)) isNew = False elif 'video' in mime: currentEntryDuration = get_video_duration(file) VideoThread(file).start() else: # cannot show this entry, so skip logging.info( 'mimetype (%s) of file (%s) not supported.' % (mime, file)) mime = None currentEntryDuration = 0 else: logging.info('cannot show suspect file: %s' % file) sleep(self.loopTime) currentEntryDuration -= self.loopTime