aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/scripts/linux_system_error_list.py
diff options
context:
space:
mode:
Diffstat (limited to 'dotfiles/scripts/linux_system_error_list.py')
-rwxr-xr-xdotfiles/scripts/linux_system_error_list.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/dotfiles/scripts/linux_system_error_list.py b/dotfiles/scripts/linux_system_error_list.py
new file mode 100755
index 0000000..ee1a7a6
--- /dev/null
+++ b/dotfiles/scripts/linux_system_error_list.py
@@ -0,0 +1,46 @@
+#!/bin/python
+
+import re, sys
+from terminaltables import DoubleTable
+
+data = []
+data.append(['Error', 'Code', 'Comment'])
+
+def get_content(file):
+
+ with open(file) as f:
+ content = f.readlines()
+
+ content = [x.strip() for x in content]
+
+ for line in content:
+ if re.search('define',line):
+ line = re.sub('#define\t', '', line)
+ line = re.sub('(?m)^#define .*\n?', '', line)
+ line = re.sub('\t\t', '\t', line)
+ line = re.sub('(/\*|\*/)', '', line)
+ if line != '':
+ data.append(re.split(r'\t',line))
+
+get_content("/usr/include/asm-generic/errno-base.h")
+get_content("/usr/include/asm-generic/errno.h")
+
+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 <search_string> # You can send regex following re.search python function")
+else:
+ print("search <search_string> # You can send regex following re.search python function")
+ print("list # Return list of all error from errno.h and errno-base.h")