Xqt submitted this change.

View Change


Approvals: Xqt: Verified; Looks good to me, approved
[IMPR] use pywikibot.info() instead of pywikibot.output()

Also use f-strings.

Change-Id: Ie12b700437ea90f21ec5156e368aea2fb5aa0332
---
M scripts/category_graph.py
M pywikibot/scripts/generate_user_files.py
2 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/pywikibot/scripts/generate_user_files.py b/pywikibot/scripts/generate_user_files.py
index 6e532e3..3df1530 100755
--- a/pywikibot/scripts/generate_user_files.py
+++ b/pywikibot/scripts/generate_user_files.py
@@ -318,7 +318,7 @@
pywikibot.info(
f'The following {variant} setting sections are provided:')
for item in filter(skip, sections):
- pywikibot.output(item.head)
+ pywikibot.info(item.head)

copies = []
# Now ask for a single section of the given variant
diff --git a/scripts/category_graph.py b/scripts/category_graph.py
index 97c3f0a..42cca2d 100755
--- a/scripts/category_graph.py
+++ b/scripts/category_graph.py
@@ -70,7 +70,8 @@
if cat_title == '?':
cat_title = pywikibot.input(
'For which category do you want to create a graph?')
- pywikibot.output('Scanning "{}"'.format(cat_title))
+
+ pywikibot.info('Scanning {cat_title!r}')
self.cat = pywikibot.Category(self.site, cat_title)
self.to = args.to
if self.to == '?':
@@ -85,13 +86,12 @@
self.leaves = set()
self.counter = 0
font = 'fontname="Helvetica,Arial,sans-serif"'
- style = 'graph [rankdir=LR ranksep=2 concentrate=true %s] ' \
- 'node [newrank=true shape=plaintext %s] ' \
- 'edge [arrowhead=open labeldistance=3 ' \
- 'labelfontcolor="#00000080" %s] ' \
- % (font, font, font) + args.style
- self.dot = pydot.graph_from_dot_data('digraph {' + style + '}')[0]
- self.dot.set_name('"' + cat_title + '"')
+ style = f'graph [rankdir=LR ranksep=2 concentrate=true {font}] ' \
+ f'node [newrank=true shape=plaintext {font}] ' \
+ f'edge [arrowhead=open labeldistance=3 ' \
+ f'labelfontcolor="#00000080" {font}] ' + args.style
+ self.dot = pydot.graph_from_dot_data(f'digraph {style}')[0]
+ self.dot.set_name(f'"{cat_title}"')

def scan_level(self, cat, level, hue=None) -> str:
"""Recursive function to fill dot graph.
@@ -108,8 +108,7 @@
subs = ', '.join([c.title(with_ns=False).replace(' ', ' ')
for c in subcats])
n = pydot.Node(title,
- label=r'"{}\n{} C"'.
- format(title, len(subcats)),
+ label=rf'"{title}\n{len(subcats)} C"',
tooltip=title + '\n\n' + subs,
URL=cat.full_url(),
fontsize=int(10 * size))
@@ -132,7 +131,8 @@
return e

if config.verbose_output:
- pywikibot.output('Adding ' + cat.title(with_ns=False))
+ pywikibot.info('Adding ' + cat.title(with_ns=False))
+
node = node()
self.dot.add_node(node)
self.counter += 1
@@ -142,6 +142,7 @@
pywikibot.warning('Number of nodes reached limit')
self.leaves.add(node.get_name())
return
+
columns = len(subcats) // 5 + 1
for n, subcat in enumerate(subcats):
# generating different hue for color per each root branch
@@ -164,19 +165,22 @@
for n in self.leaves:
while len(self.rev[n]) == 1:
if config.verbose_output:
- pywikibot.output('Removing ' + n)
+ pywikibot.info('Removing ' + n)
+
self.dot.del_edge(self.rev[n][0], n)
self.dot.del_node(n)
self.fw[self.rev[n][0]].remove(n)
if self.fw[self.rev[n][0]]:
break
n = self.rev[n][0]
- pywikibot.output('Saving results')
- pywikibot.output(self.to + '.gv')
+
+ pywikibot.info('Saving results')
+ pywikibot.info(self.to + '.gv')
self.dot.write(self.to + '.gv', encoding='utf-8')
- pywikibot.output(self.to + '.svg')
+ pywikibot.info(self.to + '.svg')
self.dot.write_svg(self.to + '.svg', encoding='utf-8')
- pywikibot.output(self.to + '.html')
+ pywikibot.info(self.to + '.html')
+
header = ('<head><meta charset="UTF-8"/>'
'<title>' + self.cat.title(with_ns=False)
+ '</title> </head>\n'

To view, visit change 874426. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ie12b700437ea90f21ec5156e368aea2fb5aa0332
Gerrit-Change-Number: 874426
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged