Пример #1
0
def download(url, target, expected_hash):
    if filesystem.calculate_hash(target) == expected_hash:
        return
    count = 0

    while filesystem.calculate_hash(TEMP_FILE) != expected_hash:
        count += 1
        if count > 5:
            os.remove(TEMP_FILE)
            raise OSError("Aborting download of %s after 5 unsuccessful attempts" % url)
        http_client.get(url).raise_for_status().download_to(TEMP_FILE)

    os.rename(TEMP_FILE, target)
Пример #2
0
def download(url, target, expected_hash):
    if filesystem.calculate_hash(target) == expected_hash:
        return
    count = 0

    while filesystem.calculate_hash(TEMP_FILE) != expected_hash:
        count += 1
        if count > 5:
            os.remove(TEMP_FILE)
            raise OSError("Aborting download of %s after 5 unsuccessful attempts" % url)
        http_client.get(url).raise_for_status().download_to(TEMP_FILE)

    os.rename(TEMP_FILE, target)
Пример #3
0
def update():
    clear()
    connect()

    with dialogs.WaitingMessage(text="Downloading full list of library files", title="TiLDA App Library") as message:
        message.text="Downloading full list of library files"
        master = http_client.get("http://api.badge.emfcamp.org/firmware/master-lib.json").raise_for_status().json()
        libs_to_update = []
        for lib, expected_hash in master.items():
            if expected_hash != filesystem.calculate_hash("lib/" + lib):
                libs_to_update.append({
                    "url": "http://api.badge.emfcamp.org/firmware/master/lib/" + lib,
                    "target": "lib/" + lib,
                    "expected_hash": expected_hash,
                    "title": lib
                })
        download_list(libs_to_update, message)

        apps = get_local_apps()
        for i, app in enumerate(apps):
            message.text = "Updating app %s" % app
            if app.fetch_api_information():
                download_app(app, message)

    dialogs.notice("Everything is up-to-date")

    main_menu()
Пример #4
0
def update():
    clear()
    connect()

    with dialogs.WaitingMessage(text="Downloading full list of library files", title="TiLDA App Library") as message:
        message.text="Downloading full list of library files"
        master = http_client.get("http://api.badge.emfcamp.org/firmware/master-lib.json").raise_for_status().json()
        libs_to_update = []
        for lib, expected_hash in master.items():
            if expected_hash != filesystem.calculate_hash("lib/" + lib):
                libs_to_update.append({
                    "url": "http://api.badge.emfcamp.org/firmware/master/lib/" + lib,
                    "target": "lib/" + lib,
                    "expected_hash": expected_hash,
                    "title": lib
                })
        download_list(libs_to_update, message)

        apps = get_local_apps()
        for i, app in enumerate(apps):
            message.text = "Updating app %s" % app
            if app.fetch_api_information():
                download_app(app, message)

    dialogs.notice("Everything is up-to-date")
Пример #5
0
def download(url, target, expected_hash):
    if filesystem.calculate_hash(target) == expected_hash:
        return
    count = 0

    while filesystem.calculate_hash(TEMP_FILE) != expected_hash:
        count += 1
        if count > 5:
            os.remove(TEMP_FILE)
            raise OSError("Aborting download of %s after 5 unsuccessful attempts" % url)
        try:
            http_client.get(url).raise_for_status().download_to(TEMP_FILE)
        except OSError:
            pass

    # If it already exists the rename will fail
    try:
        os.remove(target)
    except OSError:
        pass
    os.rename(TEMP_FILE, target)
Пример #6
0
def download_app(app, message_dialog):
    files_to_update = []
    for file in app.files:
        file_path = "%s/%s" % (app.folder_path, file["file"])
        if file["hash"] != filesystem.calculate_hash(file_path):
            data = {
                "url": file["link"],
                "target": file_path,
                "expected_hash": file["hash"],
                "title": app.folder_name + "/" + file["file"]
            }

            if file["file"] == "main.py": # Make sure the main.py is the last file we load
                files_to_update.append(data)
            else:
                files_to_update.insert(0, data)

    download_list(files_to_update, message_dialog)
Пример #7
0
def download_app(app, message_dialog):
    files_to_update = []
    for file in app.files:
        file_path = "%s/%s" % (app.folder_path, file["file"])
        if file["hash"] != filesystem.calculate_hash(file_path):
            data = {
                "url": file["link"],
                "target": file_path,
                "expected_hash": file["hash"],
                "title": app.folder_name + "/" + file["file"]
            }

            if file["file"] == "main.py": # Make sure the main.py is the last file we load
                files_to_update.append(data)
            else:
                files_to_update.insert(0, data)

    download_list(files_to_update, message_dialog)