~fkfd/sophon

c7bea98e82bd675b9c4cb822e94846e9cb414d44 — Frederick Yin 3 years ago cbc6dab
Demo client: fix interaction
1 files changed, 29 insertions(+), 28 deletions(-)

M test/demo_client.py
M test/demo_client.py => test/demo_client.py +29 -28
@@ 58,9 58,8 @@ while not selected_part:
        selected_part = True
        session = resp.meta

# m = more edits, a = abort, c = commit, p = preview page
action = "m"
while action == "m":

def make_edit():
    # preview stage
    resp = req(session + "preview")
    if resp.status != 20:


@@ 92,35 91,37 @@ while action == "m":
        raise SystemExit

    resp = req(session + "diff?" + urllib.parse.quote(unidiff))
    action = (
        input(
            "Action: m to make more edits, p to preview page, c to commit, a to abort (default m): "
        ).lower()
        or "m"
    )

    if action == "a":
        # abort
        resp = req(session + "abort")
        if resp.status == 30:
            print("Aborted")
    elif action == "c":
        # commit changes
        msg = ""
        while not msg:
            msg = input("Please enter a brief description of your edit: ")
        resp = req(session + "commit?" + urllib.parse.quote(msg))
        if resp.status == 30:
            print("Committed")

# m = more edits, a = abort, c = commit, p = preview page
action = "m"
while action not in ("a", "c"):
    if action == "m":
        make_edit()
    elif action == "p":
        # preview page
        resp = preq(session + "preview?page")
        if resp.status != 20:
            print("Fatal: Preview failed")
            raise SystemExit
        action = (
            input(
                "Action: m to make more edits, c to commit, a to abort (default m): "
            ).lower()
            or "m"
        )

    action = (
        input(
            "Action: m to make more edits, p to preview page, c to commit, a to abort (default m): "
        ).lower()
        or "m"
    )

if action == "a":
    # abort
    resp = req(session + "abort")
    if resp.status == 30:
        print("Aborted")
elif action == "c":
    # commit changes
    msg = ""
    while not msg:
        msg = input("Please enter a brief description of your edit: ")
    resp = req(session + "commit?" + urllib.parse.quote(msg))
    if resp.status == 30:
        print("Committed")
\ No newline at end of file