def finish_if_server_ready(other_condition): server_busy = is_server_busy() debugger("server_busy = {}".format(server_busy)) debugger('other_condition = {}'.format(other_condition)) will_finish = (not server_busy and other_condition) debugger('will finish = {}'.format(will_finish)) return will_finish
def ls(real_loc, line): ''' Prints out the coloured output of the ls command. Args: real_loc (str): the filepath of the current location of the user. line (str): line that the user entered in the terminal excluding ls. Returns: str of the output printed to the terminal. ''' new_loc = real_loc get_all_info = False new_lines = False args = ["ls"] line = line.replace('~', tq_file_system) if line: args = line.split(" ") for a in args: # flags if a.startswith('-'): # break back up into new lines # long format if a.find("l") != -1: get_all_info = True pass if a.find("1") != -1: new_lines = True pass # directory else: new_loc = os.path.join(new_loc, a) args = ["ls"] + args debugger("args = {}".format(args)) p = subprocess.Popen(args, cwd=real_loc, stdout=subprocess.PIPE, stderr=subprocess.PIPE) orig_output, err = p.communicate() # The error will need to be edited if it contains info about the edited # filename if err: err = err.replace(tq_file_system, '~') print err return err # Need to filter output files = orig_output.split('\n') coloured_files = [] coloured_output = "" output = " ".join(files) if get_all_info: for f in files: info = f.split(" ") i = info[-1] info.pop() path = os.path.join(new_loc, i) info.append(colour_file_dir(path, i)) f = " ".join(info) coloured_files.append(f) coloured_output = "\n".join(coloured_files) else: for f in files: path = os.path.join(new_loc, f) coloured_files.append(colour_file_dir(path, f)) if new_lines: coloured_output = "\n".join(coloured_files) else: coloured_output = " ".join(coloured_files) print coloured_output return output
def ls(real_loc, line, has_access=True): ''' Prints out the coloured output of the ls command. Args: real_loc (str): the filepath of the current location of the user. line (str): line that the user entered in the terminal excluding ls. Returns: str of the output printed to the terminal. ''' if not has_access: print "ls: cannot open directory {}: Permission denied".format(line) return new_loc = real_loc get_all_info = False new_lines = False args = ["ls"] line = line.replace('~', fake_home_dir) if line: args = line.split(" ") for a in args: # flags if a.startswith('-'): # break back up into new lines # long format if a.find("l") != -1: get_all_info = True pass if a.find("1") != -1: new_lines = True pass # directory else: new_loc = os.path.join(new_loc, a) args = ["ls"] + args debugger("args = {}".format(args)) p = subprocess.Popen(args, cwd=real_loc, stdout=subprocess.PIPE, stderr=subprocess.PIPE) orig_output, err = p.communicate() # The error will need to be edited if it contains info about the edited # filename if err: err = err.replace(tq_file_system, '~') print err return err # Need to filter output files = orig_output.split('\n') coloured_files = [] output = " ".join(files) if get_all_info: for f in files: info = f.split(" ") i = info[-1] info.pop() path = os.path.join(new_loc, i) info.append(colour_file_dir(path, i)) f = " ".join(info) coloured_files.append(f) coloured_output = "\n".join(coloured_files) else: for f in files: path = os.path.join(new_loc, f) coloured_files.append(colour_file_dir(path, f)) if new_lines: coloured_output = "\n".join(coloured_files) else: coloured_output = " ".join(coloured_files) print coloured_output return output