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') device_id_file = path.join(settings.get_configdir(), 'device_id') if path.isfile(sha_file): sha_file_mtime = path.getmtime(sha_file) last_update = datetime.fromtimestamp(sha_file_mtime) else: last_update = None if not path.isfile(device_id_file): device_id = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(15)) with open(device_id_file, 'w') as f: f.write(device_id) else: with open(device_id_file, 'r') as f: device_id = f.read() logging.debug('Last update: %s' % str(last_update)) git_branch = sh.git('rev-parse', '--abbrev-ref', 'HEAD').strip() git_hash = sh.git('rev-parse', '--short', 'HEAD').strip() if last_update is None or last_update < (datetime.now() - timedelta(days=1)): if not settings['analytics_opt_out'] and not is_ci(): mp = Mixpanel('d18d9143e39ffdb2a4ee9dcc5ed16c56') try: mp.track(device_id, 'Version', { 'Branch': str(git_branch), 'Hash': str(git_hash), }) except MixpanelException: pass except AttributeError: pass if remote_branch_available(git_branch): latest_sha = fetch_remote_hash(git_branch) if latest_sha: with open(sha_file, 'w') as f: f.write(latest_sha) return True else: logging.debug('Unable to fetch latest hash.') return else: touch(sha_file) logging.debug('Unable to check if branch exist. Checking again tomorrow.') return else: return False
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') device_id_file = path.join(settings.get_configdir(), 'device_id') if path.isfile(sha_file): sha_file_mtime = path.getmtime(sha_file) last_update = datetime.fromtimestamp(sha_file_mtime) else: last_update = None if not path.isfile(device_id_file): device_id = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(15)) with open(device_id_file, 'w') as f: f.write(device_id) else: with open(device_id_file, 'r') as f: device_id = f.read() logging.debug('Last update: %s' % str(last_update)) git_branch = sh.git('rev-parse', '--abbrev-ref', 'HEAD').strip() git_hash = sh.git('rev-parse', '--short', 'HEAD').strip() if last_update is None or last_update < (datetime.now() - timedelta(days=1)): if not settings['analytics_opt_out'] and not is_ci(): mp = Mixpanel('d18d9143e39ffdb2a4ee9dcc5ed16c56') try: mp.track(device_id, 'Version', { 'Branch': str(git_branch), 'Hash': str(git_hash), }) except MixpanelException: pass except AttributeError: pass if remote_branch_available(git_branch): latest_sha = fetch_remote_hash(git_branch) if latest_sha: with open(sha_file, 'w') as f: f.write(latest_sha) return True else: logging.debug('Unable to fetch latest hash.') return else: touch(sha_file) logging.debug('Unable to check if branch exist. Checking again tomorrow.') return else: return False
def is_up_to_date(): """ Primitive update check. Checks local hash against GitHub hash for branch. Returns True if the player is up to date. """ latest_sha, retrieved_update = fetch_remote_hash() git_branch = get_git_branch() git_hash = get_git_hash() git_short_hash = get_git_short_hash() get_device_id = r.get('device_id') if not latest_sha: logging.error('Unable to get latest version from GitHub') return True if not get_device_id: device_id = ''.join( random.choice(string.ascii_lowercase + string.digits) for _ in range(15)) r.set('device_id', device_id) else: device_id = get_device_id if retrieved_update: if not settings['analytics_opt_out'] and not is_ci(): mp = Mixpanel('d18d9143e39ffdb2a4ee9dcc5ed16c56') try: mp.track( device_id, 'Version', { 'Branch': str(git_branch), 'Hash': str(git_short_hash), 'NOOBS': os.path.isfile('/boot/os_config.json'), 'Balena': is_balena_app(), 'Docker': is_docker(), 'Pi_Version': lookup_raspberry_pi_revision( parse_cpu_info()['revision'])['model'] }) except MixpanelException: pass except AttributeError: pass return latest_sha == git_hash
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') # device_id_file = path.join(settings.get_configdir(), 'device_id') if path.isfile(sha_file): sha_file_mtime = path.getmtime(sha_file) last_update = datetime.fromtimestamp(sha_file_mtime) else: last_update = None # We want to change the device_id each time an asset # is played on the viewer namechars = string.ascii_lowercase + string.digits device_id = ''.join(random_choice(namechars) for _ in range(15)) logging.debug('Last update: %s' % str(last_update)) git_branch = sh.git('rev-parse', '--abbrev-ref', 'HEAD').strip() hexchars = 'abcdef' + string.digits # FIXME do random_choice from git rev-list --all git_hash = ''.join(random_choice(hexchars) for _ in range(7)) # git_hash = sh.git('rev-parse', '--short', 'HEAD').strip() yesterday = datetime.now() - timedelta(days=1) # use analytics more often for better tracking, ... if not settings['analytics_opt_out'] and not is_ci(): mp = Mixpanel('d18d9143e39ffdb2a4ee9dcc5ed16c56') try: mp.track(device_id, 'Version', { 'Branch': str(git_branch), 'Hash': str(git_hash), }) except MixpanelException: pass except AttributeError: pass # but we want to actually do the update check daily. if last_update is None or last_update < yesterday: if remote_branch_available(git_branch): latest_sha = fetch_remote_hash(git_branch) if latest_sha: with open(sha_file, 'w') as f: f.write(latest_sha) return True else: logging.debug('Unable to fetch latest hash.') return else: touch(sha_file) logging.debug( 'Unable to check if branch exist. Checking again tomorrow.') return else: return False
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") device_id_file = path.join(settings.get_configdir(), "device_id") if path.isfile(sha_file): sha_file_mtime = path.getmtime(sha_file) last_update = datetime.fromtimestamp(sha_file_mtime) else: last_update = None if not path.isfile(device_id_file): device_id = "".join( random.choice(string.ascii_lowercase + string.digits) for _ in range(15)) with open(device_id_file, "w") as f: f.write(device_id) else: with open(device_id_file, "r") as f: device_id = f.read() logging.debug("Last update: %s" % str(last_update)) git_branch = get_git_branch() git_hash = get_git_short_hash() if last_update is None or last_update < (datetime.now() - timedelta(days=1)): if not settings["analytics_opt_out"] and not is_ci(): mp = Mixpanel("d18d9143e39ffdb2a4ee9dcc5ed16c56") try: mp.track( device_id, "Version", { "Branch": str(git_branch), "Hash": str(git_hash), "NOOBS": path.isfile("/boot/os_config.json"), "Balena": is_balena_app(), }, ) except MixpanelException: pass except AttributeError: pass if remote_branch_available(git_branch): latest_sha = fetch_remote_hash(git_branch) if latest_sha: with open(sha_file, "w") as f: f.write(latest_sha) return True else: logging.debug("Unable to fetch latest hash.") return else: touch(sha_file) logging.debug( "Unable to check if branch exist. Checking again tomorrow.") return else: return False