def assemble_code(self, filename, output, assembler): assembler_output_raw = "" assembler_output = [] assembler_command_temp = assembler[:] if platform.system() == "Linux": if os.uname()[4] == 'x86_64': assembler_command_temp.append("-f") assembler_command_temp.append("elf64") elif os.uname()[4] == 'i686': assembler_command_temp.append("-f") assembler_command_temp.appent("elf32") assembler_command_temp.append(filename) assembler_command_temp.append("-o%s.o" % output) assembler_process_data = easyprocess.EasyProcess( assembler_command_temp).call(timeout=30) assembler_output_raw = (assembler_process_data.stdout + assembler_process_data.stderr) if assembler_output_raw: assembler_output = assembler_output_raw.split("\n") for i in range(len(assembler_output)): assembler_output[i] = assembler_output[i].split(" ", 1)[1] raise CompilerException("Assembler error: " + assembler_output[0]) return False else: return True
def runCommand(command, env=None, cwd=None, timeout=None): """returns triple (returncode, stdout, stderr, exitstatus)""" if env is None: env = os.environ tmpenv = {} for k, v in env.items(): tmpenv[str(k)] = str(v) env = tmpenv if len(cwd) == 0: cwd = None p = easyprocess.EasyProcess(command, cwd=cwd, env=env, universal_newlines=False) p.call(timeout) exitstatus = EXIT_ON_FAILURE if p.timeout_happened: exitstatus = EXIT_ON_TIMEOUT elif p.return_code == 0: exitstatus = EXIT_ON_SUCCESS elif p.return_code in (134, -signal.SIGABRT): exitstatus = EXIT_ON_ABORT elif p.return_code in (139, -signal.SIGSEGV): exitstatus = EXIT_ON_SEGFAULT return (p.return_code, p.stdout, p.stderr, exitstatus)
def start(attempt_id, results_log): last_len = 0 same_cnt = 0 with pyvirtualdisplay.smartdisplay.SmartDisplay(visible=False, size=(1300, 900)) as v_display: if DEBUG: print(v_display) print(v_display.display) env = os.environ env["GOLLY_ATTEMPT_ID"] = attempt_id env["PATH"] = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" env["TERM"] = "xterm" env["PWD"] = "/" env["HOME"] = "/home/rrx" print(env["GOLLY_ATTEMPT_ID"]) sys.stdout.flush() open(results_log, "a").write("Starting up lifebooox\n") with easyprocess.EasyProcess(GOLLY_BINARY, env=env) as golly: for x in range(0, 500): results = open(results_log).read() if results.find("WINNER") > -1: break if results.find("GAME OVER") > -1: break if results.find("#100") > -1: golly.sendstop() break if last_len == len(results): same_cnt += 1 else: same_cnt = 0 # if the process has not logged anything new for 120 secs then kill it. if same_cnt > 10: with open(results_log, "a") as log: log.write( "The game of life went too long without update, check the format of the uploaded pattern.\n" ) log.write("GAME OVER\n") golly.sendstop() break last_len = len(results) time.sleep(3)
def _runcmd(self, cmd): """ Execute a given external <cmd> and log the results. The command must succeed (status=0) in order to count execution as an success. """ self._log('*' * 80) self._log(cmd) proc = easyprocess.EasyProcess(cmd) result = proc.call() status = result.return_code stdout = result.stdout.strip() stderr = result.stderr.strip() self._log('Status: {}'.format(status)) if stdout: self._log(stdout) if stderr: self._log(stderr) if status != 0: raise RuntimeError('Execution of "{}" failed\n\nOutput:\n{}'.format(cmd, stdout + stderr))
def link(self, data, output): linker = "gcc" if "_start" in data["command"]: linker = "ld" elif "main" in data["command"]: linker = "gcc" linker_command = [linker, "%s.o" % output, "-o", output] linker_process_data = easyprocess.EasyProcess(linker_command).call( timeout=30) linker_output_raw = (linker_process_data.stdout + linker_process_data.stderr) if linker_output_raw: linker_output = linker_output_raw.split("\n") raise CompilerException("Linker error:" + linker_output[0]) return False else: return True
def start_ns(url): # First, create the copy of the hard drive if DEBUG: print "creating the HD" # kill any previous binaries for proc in psutil.process_iter(): if proc.name() == "previous": proc.kill() tar = tarfile.open(PRISTINE_HARD_DISK, 'r:gz') tar.extractall(ACTUAL_HARD_DISK_DIR) if DEBUG: print "done creating the HD" with pyvirtualdisplay.smartdisplay.SmartDisplay(visible=0, size=(1300, 900)) as v_display: if DEBUG: print v_display print v_display.display with easyprocess.EasyProcess(PREVIOUS_BINARY) as previous: time.sleep(.50) xdo = Xdo() done = False while not done: wins = xdo.search_windows('Previous') # check if alive if not previous.is_alive(): print "Error, couldn't boot emulator" return if wins: done = True window = wins[0] else: time.sleep(.50) # Get the relative X and Y for the window loc = xdo.get_window_location(window) print "Booting up" # wait until we get to the login screen wait_until_login_screen(xdo, loc, window, v_display) print "Finally booted" current_image = v_display.waitgrab() send_screen_shot(current_image) log_into_ns(xdo, window) print "Waiting to log in" # wait for the screen to load wait_until_login_desktop(xdo, loc, window, v_display) print "Logged in" current_image = v_display.waitgrab() send_screen_shot(current_image) # Send the data send_url_to_ns(url) send_copy_command(xdo, window) time.sleep(.50) current_image = v_display.waitgrab() send_screen_shot(current_image) print "Starting the old dog" send_start_www_command(xdo, window) # Wait until WWW is ready wait_until_www_ready(xdo, loc, window, v_display) print "That old dog is ready" current_image = v_display.waitgrab() send_screen_shot(current_image) # Close out the terminal # Command-q is the keyboard shortcut to quit xdo.send_keysequence_window(window, "Super_L+q") time.sleep(.50) select_open_document(xdo, loc, window) # Wait until Document Inspector is open print "Sending your input" wait_until_document_inspector_open(xdo, loc, window, v_display) current_image = v_display.waitgrab() send_screen_shot(current_image) move_to_address_field(xdo, loc, v_display) time.sleep(.50) xdo.click_window(window, 1) current_image = v_display.waitgrab() send_screen_shot(current_image) # Paste that shit! # Command-v is the keyboard shortcut xdo.send_keysequence_window(window, "Super_L+v") time.sleep(.50) current_image = v_display.waitgrab() send_screen_shot(current_image) print "That old dog can still visit URLs!" # if DEBUG: # input("Wait for debugging") # Open it! xdo.send_keysequence_window(window, "Return") print "tbl would be proud" # Wait for 5 seconds, taking screenshots for i in xrange(5): time.sleep(1) current_image = v_display.waitgrab() send_screen_shot(current_image) # Crazy hack b/c something is sending an error message: # "XIO: fatal IO error 0 (Success) on X server ":1001"" # Which is freaking crazy, doesn't make any devnull = open(os.devnull, 'w') os.dup2(devnull.fileno(), 2)