summaryrefslogtreecommitdiff
path: root/doc/tools
diff options
context:
space:
mode:
Diffstat (limited to 'doc/tools')
-rw-r--r--doc/tools/doc_status.py31
1 files changed, 22 insertions, 9 deletions
diff --git a/doc/tools/doc_status.py b/doc/tools/doc_status.py
index 6b6b794f11..75e18bbe81 100644
--- a/doc/tools/doc_status.py
+++ b/doc/tools/doc_status.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
+import fnmatch
import os
import sys
import re
@@ -91,7 +92,7 @@ def validate_tag(elem, tag):
def color(color, string):
- if flags['c']:
+ if flags['c'] and terminal_supports_color():
color_format = ''
for code in colors[color]:
color_format += '\033[' + str(code) + 'm'
@@ -105,6 +106,15 @@ ansi_escape = re.compile(r'\x1b[^m]*m')
def nonescape_len(s):
return len(ansi_escape.sub('', s))
+def terminal_supports_color():
+ p = sys.platform
+ supported_platform = p != 'Pocket PC' and (p != 'win32' or
+ 'ANSICON' in os.environ)
+
+ is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
+ if not supported_platform or not is_a_tty:
+ return False
+ return True
################################################################################
# Classes #
@@ -134,8 +144,8 @@ class ClassStatusProgress:
return self.to_colored_string()
def to_colored_string(self, format='{has}/{total}', pad_format='{pad_described}{s}{pad_total}'):
- ratio = self.described / self.total if self.total != 0 else 1
- percent = round(100 * ratio)
+ ratio = float(self.described) / float(self.total) if self.total != 0 else 1
+ percent = int(round(100 * ratio))
s = format.format(has=str(self.described), total=str(self.total), percent=str(percent))
if self.described >= self.total:
s = color('part_good', s)
@@ -218,6 +228,7 @@ class ClassStatus:
return output
+ @staticmethod
def generate_for_class(c):
status = ClassStatus()
status.name = c.attrib['name']
@@ -356,8 +367,13 @@ for file in input_file_list:
class_names.sort()
if len(input_class_list) < 1:
- input_class_list = class_names
+ input_class_list = ['*']
+filtered_classes = set()
+for pattern in input_class_list:
+ filtered_classes |= set(fnmatch.filter(class_names, pattern))
+filtered_classes = list(filtered_classes)
+filtered_classes.sort()
################################################################################
# Make output table #
@@ -369,10 +385,7 @@ table_column_chars = '|'
total_status = ClassStatus('Total')
-for cn in input_class_list:
- if not cn in classes:
- print('Cannot find class ' + cn + '!')
- sys.exit(255)
+for cn in filtered_classes:
c = classes[cn]
validate_tag(c, 'class')
@@ -436,7 +449,7 @@ for row_i, row in enumerate(table):
if cell_i == 0:
row_string += table_row_chars[3] + cell + table_row_chars[3] * (padding_needed - 1)
else:
- row_string += table_row_chars[3] * math.floor(padding_needed / 2) + cell + table_row_chars[3] * math.ceil((padding_needed / 2))
+ row_string += table_row_chars[3] * int(math.floor(float(padding_needed) / 2)) + cell + table_row_chars[3] * int(math.ceil(float(padding_needed) / 2))
row_string += table_column_chars
print(row_string)