Beispiel #1
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')
    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
Beispiel #2
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')
    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
Beispiel #3
0
def chrootConfig():
  try:
    UI.logEntering()
    shutil.copy("/usr/bin/qemu-arm-static", Utils.getPath("mnt/usr/bin/qemu-arm-static"))
    Utils.touch("mnt/usr/sbin/policy-rc.d.lock")
    if os.path.isfile(Utils.getPath("mnt/usr/sbin/policy-rc.d")):
      shutil.move(Utils.getPath("mnt/usr/sbin/policy-rc.d"), Utils.getPath("mnt/usr/sbin/policy-rc.d_save"))
    f = open(Utils.getPath("mnt/usr/sbin/policy-rc.d"), 'w')
    f.write("exit 101\n")
    f.close()
    os.chmod(Utils.getPath("mnt/usr/sbin/policy-rc.d"), 0o755 )
    Disk.doMount(Device = "/proc", Path = "mnt/proc", Bind = True)
    Disk.doMount(Device = "/sys", Path = "mnt/sys", Bind = True)
    Disk.doMount(Device = "/dev/pts", Path = "mnt/dev/pts", Bind = True)
    UI.logExiting()
    return True
  except SystemExit:
    pass
  except:
    logging.exception("Caught Exception")
    sys.exit(os.EX_IOERR)
Beispiel #4
0
def __home_exists() -> None:
    """Make sure that SPATH exists"""
    utils.dir_exists(SPATH)
    utils.touch(os.path.join(SPATH, '.gitkeep'))
Beispiel #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.
    """

    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
Beispiel #6
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")
    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