예제 #1
0
def process_connection(conn):
    #console.print('Connected by', addr)

    sys.stdout = StdoutRedirectToConnection(conn)
    cmd_started = time.time()
    # reset timing info for new cmd or client
    # utils.set_timing_data(time.time(), True)
    # console.diag("utils.init_timing() call")

    while True:
        data = conn.recv(16000)
        if not data:
            break

        # decode command
        text = data.decode()
        cmd = json.loads(text)
        cmd_text = cmd["text"]
        cwd = cmd["cwd"]

        if orig_stdout:
            orig_stdout.write("cwd: " + cwd + ", cmd: " + cmd_text + "\n")

        # RUN command
        os.chdir(cwd)
        fb.reset_feedback()

        xt_cmds.main(cmd_text, cmd_started)
        break
예제 #2
0
def test_cmd(cmd):
    global cmd_count
    print("-------------------------------")
    print("downloadTests: testing ({}): ".format(1 + cmd_count, cmd))
    xt_cmds.main(cmd)

    cmd_count += 1
예제 #3
0
    def test_cmd(self, cmd):
        print("-----------------------")
        print("plotTests: testing ({}/{}): {}".format(1 + self.cmd_count,
                                                      self.count, cmd))

        xt_cmds.main(cmd)
        self.cmd_count += 1
예제 #4
0
def test_cmd(cmd, name):
    global cmd_count
    print("-------------------------------")
    print(name)
    print("deleteTests: testing ({}): ".format(1+cmd_count, cmd))
    xt_cmds.main(cmd)

    cmd_count += 1
예제 #5
0
def init():

    # bring over *.yaml file to put everything relative to quick-test
    shutil.copyfile("../xt_config.yaml", "./xt_config.yaml")

    # generate some files
    generate(3, ".py", "./")
    generate(2, ".txt", "./")
    generate(3, ".py", "./myapps/")
    generate(2, ".txt", "./myapps/")
    xt_cmds.main("xt create share sharetest")
예제 #6
0
    def test_cmd(self, i, cmd, logs_dir, fake):
        self.cmd_count += 1        

        if not fake:
            cmd = cmd.replace("--fake-submit=True", "--fake-submit=False")

        print("-------------------------------------")
        print("runTests: testing (# {}, errors: {}/{}): {}".format(i, self.file_compare_errors, self.file_count, cmd))
        #console.set_level("diagnostics")

        file_utils.ensure_dir_exists(logs_dir)

        xt_cmds.main(cmd)

        if self.compare:
            self.compare_submit_logs(logs_dir)
예제 #7
0
def main():
    started = time.time()
    dir = "upload_testing"
    file_utils.ensure_dir_clean(dir)

    # move to a directory with a the set of files to upload

    with DirChange(dir):
        init()

        single_blob_tests()
        multiple_blob_tests()
        
        # single_file_tests()
        # multiple_file_tests()

    elapsed = time.time() - started
    print("\nend of uploadTests, elapsed={:.0f} secs".format(elapsed))
    xt_cmds.main("xt delete share sharetest --response sharetest")

    return cmd_count
예제 #8
0
def test_show_controller_linux():
    """
    This tests that setting show-controller to true will spawn a new Gnome
    terminal at location ~/.xt/cwd
    """
    global cmd_count

    p = subprocess.Popen((
        "bash -c 'if xset q &> /dev/null; then "
        "xdotool search --onlyvisible -class gnome-terminal getwindowname %@ | "
        "wc -l; else echo 0; fi'"),
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE,
                         shell=True)
    gnome_terminal_before_count = int(p.stdout.read().decode())

    cmd = "xt run --monitor=new code/miniMnist.py"
    xt_cmds.main(cmd)

    # We need to wait long enough for the gnome terminal to show up in the
    # list of open windows.
    time.sleep(5)
    p = subprocess.Popen((
        "bash -c 'if xset q &> /dev/null; then "
        "xdotool search --onlyvisible -class gnome-terminal getwindowname %@ | "
        "wc -l; else echo 0; fi'"),
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE,
                         shell=True)
    gnome_terminal_after_count = int(p.stdout.read().decode())

    # We should have one additional gnome terminal open with location ~/.xt/cwd
    print("Spawned {} additional gnome-terminals.".format(
        (gnome_terminal_after_count - gnome_terminal_before_count)))
    assert ((gnome_terminal_after_count - gnome_terminal_before_count) == 1)
    cmd_count = cmd_count + 1
예제 #9
0
def test_cmd(cmd):
    global cmd_count
    print("uploadtests: testing ({}): ".format(1+cmd_count, cmd))
    xt_cmds.main(cmd)

    cmd_count += 1
예제 #10
0
def main(cmd=None, disable_quickstart=False, capture_output=False, mini=False):

    utils.init_logging(constants.FN_XT_EVENTS, logger, "XT session")

    # fix artifact if no args passed, we end up with python's first arg
    if cmd:
        # treat as if it came from the shell (for consistent debugging/support)
        console.diag("orig cmd={}".format(cmd))

        # shlex and linux loses single quotes around strings, but windows does not
        orig_args = shlex.split(cmd)
        console.diag("shlex args={}".format(orig_args))
    else:
        orig_args = sys.argv[1:]
        console.diag("orig_args={}".format(orig_args))

    cmd = " ".join(orig_args)
    cmd = cmd.strip()

    use_server = "--quic" in cmd
    if not use_server:
        from .helpers.xt_config import XTConfig
        config = XTConfig(create_if_needed=True)
        use_server = config.get("general", "quick-start")

    mid_elapsed = time.time() - xt_start_time
    #console.print("mid_elapsed={:.2f}".format(mid_elapsed))

    if not use_server or disable_quickstart:
        # NORMAL start-up mode
        from xtlib import xt_cmds
        output = xt_cmds.main(cmd,
                              capture_output=capture_output,
                              mini=mini,
                              raise_syntax_exception=False)
    else:
        # QUICK-START mode
        output = None
        log.info("using xt_server")

        import psutil

        need_start = True

        for proc in psutil.process_iter():
            try:
                # Check if process name contains the given name string.
                ptext = str(proc.cmdline())

                # if "python" in ptext:
                #     console.print(ptext)

                if "python" in ptext and "xt_server.py" in ptext:
                    need_start = False
                    break
            except BaseException as ex:
                logger.exception(
                    "Error while enumerating processes looking for xt_server, ex={}"
                    .format(ex))
                pass

        if need_start:
            from .cmd_core import CmdCore
            CmdCore.start_xt_server()

        # for now, always turn on stack traces for server-run cmd
        cmd = "--stack-trace " + cmd

        cmd_dict = {"text": cmd, "cwd": os.getcwd()}

        # retry up to 5 secs (to handle case where xt_server is being restarted)
        retry_count = 0

        for i in range(5):
            try:
                run_cmd_on_server(cmd_dict, retry_count)
                break
            except BaseException as ex:
                logger.exception(
                    "Error retry exceeded sending cmd to xt_server.  Last ex={}"
                    .format(ex))
                console.print(".", end="", flush=True)
                #console.print(ex)
                time.sleep(1)
                retry_count += 1

    elapsed = time.time() - xt_start_time
    #console.print("(elapsed: {:.2f} secs)".format(elapsed))

    # add adjustment for average exit time
    console.diag("end of xt_run (includes exit time={:.2f})".format(EXIT_TIME),
                 exit_time=EXIT_TIME)

    # don't return output if we were called from xt.exe (it will console.print a confusing "[]" to output)
    return output if capture_output else None
예제 #11
0
def navigate(cmds, auto_mode, steps):
    pc_utils.enable_ansi_escape_chars_on_windows_10()
    
    index = 0
    while True:

        if index < 0:
            # keep in range (in response to user 'back')
            index = 0

        if not (1+index) in steps:
            index += 1
            if index >= len(cmds):
                break
            continue

        # show title, cmd
        cmd = cmds[index]
        cmd_text = cmd["xt_cmd"]
        silent = cmd["silent"]

        if silent:
            # don't show cmd; just execute it
            error_code = os.system(cmd_text)
            if error_code:
                errors.general_error("error code {} returned from running cmd: {}".format(error_code, cmd_text))
            index += 1
            continue

        is_windows = (os.name == "nt")

        # clear screen
        if auto_mode:
            print("======================================")
        elif is_windows:
            # windows
            os.system("cls")
        else:
            # linux - screen is inconsistent (SSH screen drawing?)
            os.system('clear')
            
        if auto_mode:
            # adjust some commands for auto mode
            if cmd_text.startswith("xt rerun"):
                cmd_text += " --response=$cmd"
            elif cmd_text.startswith("xt extract"):
                cmd_text += " --response=y"
            elif cmd_text.startswith("xt explore"):
                cmd_text += " --timeout=5"
            # elif "--open" in cmd_text:
            #     cmd_text = cmd_text.replace("--open", "")

        print("xt demo {}/{}: {}".format(index+1, len(cmds), cmd["title"]))
        print(" > " + cmd_text + " ", end="", flush=True)

        response = wait_for_nav_key(auto_mode)
        #print("response=", response, 'b"q"=', b"q", response == b"q")

        if response in ["\r", "\n"]:
            # ---- RUN COMMAND ---- 
            if cmd_text.startswith("xt "):
                # run XT cmd internally
                fb.reset_feedback()
                xt_cmds.main(cmd_text)
            elif cmd_text.startswith("!"):
                os_cmd = cmd_text[1:]
                # treat as OS cmd
                error_code = os.system(os_cmd)
                if error_code:
                    errors.general_error("error code {} returned from running cmd: {}".format(error_code, os_cmd))
            else:
                raise Exception("internal error: unexpected cmd=", cmd_text)
            
            global cmd_count
            cmd_count += 1
            index += 1
        elif response == "s":
            print("[skip]")
            index += 1
            continue
        elif response == "b":
            print("[back]")
            index -= 1
            continue
        elif response == "q":
            print("[quit]")
            break
        else:
            print("unrecognized choice: press ENTER to run, 'q' to quit, 's' for skip, or 'b' for back")

        if index >= len(cmds):
            break

        print()
        print("hit any key to continue: ", end="", flush=True)
        response = wait_for_any_key(auto_mode)
        if response == "q":
            break