From b5f86deb375795c26b1041982237f2518aa3aa88 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sun, 5 Nov 2017 15:09:26 +0100 Subject: Add abilty to search for error code --- scripts/.scripts/linux_system_error_list.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/scripts/.scripts/linux_system_error_list.py b/scripts/.scripts/linux_system_error_list.py index 43f1cb5..ee1a7a6 100755 --- a/scripts/.scripts/linux_system_error_list.py +++ b/scripts/.scripts/linux_system_error_list.py @@ -1,6 +1,6 @@ #!/bin/python -import re +import re, sys from terminaltables import DoubleTable data = [] @@ -25,6 +25,22 @@ def get_content(file): get_content("/usr/include/asm-generic/errno-base.h") get_content("/usr/include/asm-generic/errno.h") -table = DoubleTable(data, "Error code") -table.justify_columns = {0: 'right', 1: 'center', 2: 'left'} -print(table.table) +if len(sys.argv) == 2 and sys.argv[1] == "list": + table = DoubleTable(data, "Error code") + table.justify_columns = {0: 'right', 1: 'center', 2: 'left'} + print(table.table) +elif (len(sys.argv) == 2 or len(sys.argv) == 3) and sys.argv[1] == "search": + if len(sys.argv) == 3: + data_searched = [] + data_searched.append(['Error', 'Code', 'Comment']) + for line in data: + if re.search(sys.argv[2],str(line)): + data_searched.append(line) + table = DoubleTable(data_searched, "Error code") + table.justify_columns = {0: 'right', 1: 'center', 2: 'left'} + print(table.table) + else: + print("search # You can send regex following re.search python function") +else: + print("search # You can send regex following re.search python function") + print("list # Return list of all error from errno.h and errno-base.h") -- cgit v1.2.1