def test_align_predefined(): pbar.update(1) return rapidtables.make_table( table, align=(rapidtables.ALIGN_RIGHT, rapidtables.ALIGN_LEFT, rapidtables.ALIGN_LEFT, rapidtables.ALIGN_RIGHT, rapidtables.ALIGN_LEFT))
def history(args): print("ARGS : " + str(args)) # If no arguments typed if len(args) == 0: print("HOWTO") elif str(args[0]) == "list": # List history in order print("List history") with open(CONFIG_PATH + 'alpsh_history.json', 'r') as history_list: data = json.load(history_list) count = 0 table = [] for item in range(len(data["history"])): table.append({ 'Index': str(count), 'Command': data['history'][count]['command'], "Timestamp": data['history'][count]['timestamp'], 'Success': data['history'][count]['success'], 'Ran from directory': data['history'][count]['dir_when_ran'] }) count += 1 tables = make_table(table, tablefmt='md') print(tables) print() elif str(args[0] == "clear"): print( config.get_setting('text', 'danger') + "-=-=-=-=-=-=-=-WARNING-=-=-=-=-=-=-=\n" + COLORS.CLEAR + "You are about to remove your command history.\n" + "This is generally not necessary and is not recommended to do without reason.\n" + config.get_setting('text', 'danger') + "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" + COLORS.CLEAR) response = input("Are you sure you want to continue? [y/N] ") if response == "y": # Remove history history_listener.create(reset=True) print( config.get_setting('text', 'warning') + "History cleared!\n" + COLORS.CLEAR) else: # Don't remove history print( config.get_setting('text', 'warning') + "Aborted!\n" + COLORS.CLEAR) return SHELL_STATUS_RUN
def rtm_builder(prefix: str, root: str = None, sort_key: str = None, csv_path: str = None) -> str: """Generate a traceability matrix, and output to either stdout or csv. Args: prefix: The prefix for Doorstop requirements. root: The root path to search for Doorstop documents. sort_key: If the RTM should be sorted, sort by this key. Should be one of 'UID', 'Has Test', 'Tests', or None. Defaults to None. csv_path: If the RTM should be written to file, write to this path. If omitted, the RTM will be returned. Defaults to None. """ tree = doorstop.build(root=root) reqs_doc = tree.find_document(prefix) table_data = [{ "UID": str(item), "Has Test": bool(item.child_links), "Need Test": bool(item.normative), "Tests": " ".join([str(child) for child in item.child_links]), } for item in reqs_doc.items] if sort_key: table_data = sorted(table_data, key=lambda x: x[sort_key]) table = rapidtables.make_table(table_data, tablefmt="md") if csv_path: with open(csv_path, "w", newline="") as csvfile: fieldnames = ["UID", "Has Test", "Need Test", "Tests"] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() for row in table_data: writer.writerow(row) return f"Successfully wrote traceability matrix to {csv_path}" else: return table
def print_table(directory): table = [] for link in os.listdir(directory): if not link.startswith('.'): full_path = directory + "/" + link size = os.path.getsize(full_path) if os.path.isdir(full_path): file_type = "Directory" elif os.path.isfile(full_path): file_type = "File" else: file_type = "Unknown" table.append({ 'Name': link, 'Size': utils.convert_byte_size(size), "Type": file_type }) tables = make_table(table, tablefmt='md') print(tables) print()
def show_table(title, table): """Show table nicely.""" show_title(title) for line in make_table(table).split("\n"): print(" " + line)
def test_rapidtables(): return rapidtables.make_table(table)
def test_rapidtables(): pbar.update(1) return rapidtables.make_table(table)
def test_all_fixed(): pbar.update(1) return rapidtables.make_table(table, align=rapidtables.ALIGN_LEFT, column_width=(20, 20, 20, 20, 20))
def test_align_numbers_h_cols_h(): pbar.update(1) return rapidtables.make_table( table, align=rapidtables.ALIGN_HOMOGENEOUS_NUMBERS_RIGHT, column_width=rapidtables.COLUMN_HOMOGENEOUS_WIDTH_CALC)
def test_align_numbers_h(): pbar.update(1) return rapidtables.make_table( table, align=rapidtables.ALIGN_HOMOGENEOUS_NUMBERS_RIGHT)
def test_fixed_align(): pbar.update(1) return rapidtables.make_table(table, align=rapidtables.ALIGN_LEFT)