Beispiel #1
0
def set_params(new_version: bool, failed_count: int,
               exception: Optional[str]) -> None:
    params = Params()

    params.put("UpdateFailedCount", str(failed_count))
    if failed_count == 0:
        t = datetime.datetime.utcnow().isoformat()
        params.put("LastUpdateTime", t.encode('utf8'))

    if exception is None:
        params.delete("LastUpdateException")
    else:
        params.put("LastUpdateException", exception)

    if new_version:
        try:
            with open(os.path.join(FINALIZED, "RELEASES.md"), "rb") as f:
                r = f.read().split(b'\n\n', 1)[0]  # Slice latest release notes
            try:
                params.put("ReleaseNotes", parse_markdown(r.decode("utf-8")))
            except Exception:
                params.put("ReleaseNotes", r + b"\n")
        except Exception:
            params.put("ReleaseNotes", "")
        params.put_bool("UpdateAvailable", True)
Beispiel #2
0
def set_params(new_version: bool, failed_count: int,
               exception: Optional[str]) -> None:
    params = Params()

    params.put("UpdateFailedCount", str(failed_count))

    last_update = datetime.datetime.utcnow()
    if failed_count == 0:
        t = last_update.isoformat()
        params.put("LastUpdateTime", t.encode('utf8'))
    else:
        try:
            t = params.get("LastUpdateTime", encoding='utf8')
            last_update = datetime.datetime.fromisoformat(t)
        except (TypeError, ValueError):
            pass

    if exception is None:
        params.delete("LastUpdateException")
    else:
        params.put("LastUpdateException", exception)

    # Write out release notes for new versions
    if new_version:
        try:
            with open(os.path.join(FINALIZED, "RELEASES.md"), "rb") as f:
                r = f.read().split(b'\n\n', 1)[0]  # Slice latest release notes
            try:
                params.put("ReleaseNotes", parse_markdown(r.decode("utf-8")))
            except Exception:
                params.put("ReleaseNotes", r + b"\n")
        except Exception:
            params.put("ReleaseNotes", "")
        params.put_bool("UpdateAvailable", True)

    # Handle user prompt
    for alert in ("Offroad_UpdateFailed", "Offroad_ConnectivityNeeded",
                  "Offroad_ConnectivityNeededPrompt"):
        set_offroad_alert(alert, False)

    now = datetime.datetime.utcnow()
    dt = now - last_update
    if failed_count > 15 and exception is not None:
        if get_tested_branch():
            extra_text = "Ensure the software is correctly installed"
        else:
            extra_text = exception
        set_offroad_alert("Offroad_UpdateFailed", True, extra_text=extra_text)
    elif dt.days > DAYS_NO_CONNECTIVITY_MAX and failed_count > 1:
        set_offroad_alert("Offroad_ConnectivityNeeded", True)
    elif dt.days > DAYS_NO_CONNECTIVITY_PROMPT:
        remaining = max(DAYS_NO_CONNECTIVITY_MAX - dt.days, 1)
        set_offroad_alert(
            "Offroad_ConnectivityNeededPrompt",
            True,
            extra_text=f"{remaining} day{'' if remaining == 1 else 's'}.")
    def test_current_release_notes(self):
        self.maxDiff = None

        with open(os.path.join(BASEDIR, "RELEASES.md")) as f:
            for r in f.read().split("\n\n"):

                # No hyperlink support is ok
                if '[' in r:
                    continue

                self.assertEqual(MarkdownIt().render(r), parse_markdown(r))