Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to f-string #580

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions scripts/boxes
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def run_generator(name, args):
box.render()
box.close()
else:
msg = ('Unknown generator \'{}\'. Use boxes --list to get a list of '
'available commands.\n').format(name)
msg = f'Unknown generator \'{name}\'. Use boxes --list to get a list of available commands.\n'
sys.stderr.write(msg)


Expand Down
49 changes: 21 additions & 28 deletions scripts/boxes2inkscape
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class Boxes2INX:
self.groups_by_name = boxes.generators.ui_groups_by_name

for name, box in self.boxes.items():
self.groups_by_name.get(box.ui_group,
self.groups_by_name["Misc"]).add(box)
self.groups_by_name.get(box.ui_group, self.groups_by_name["Misc"]).add(box)

def arg2inx(self, a, prefix):
name = a.option_strings[0].replace("-", "")
Expand All @@ -50,17 +49,15 @@ class Boxes2INX:
return a.type.inx(name, viewname, a) # see boxes.__init__.py
elif a.dest == "layout":
return ""
val = a.default.split("\n")
input = """<textarea name="%s" cols="%s" rows="%s">%s</textarea>""" % \
(name, max(len(l) for l in val) + 10, len(val) + 1, a.default)
# val = a.default.split("\n")
# input = f"""<textarea name="{name}" cols="{max(len(l) for l in val) + 10}" rows="{len(val) + 1}">{a.default}</textarea>"""
elif a.choices:
uniqueChoices = []
for e in a.choices:
if e not in uniqueChoices:
uniqueChoices.append(e)
return (''' <param name="%s" type="optiongroup" appearance="combo" gui-text="%s" gui-description=%s>\n'''
% (name, viewname, quoteattr(a.help or viewname)) +
"".join(' <option value="%s">%s</option>\n' % (e, e) for e in uniqueChoices) + ' </param>\n')
return (f'''<param name="{name}" type="optiongroup" appearance="combo" gui-text="{viewname}" gui-description={quoteattr(a.help or viewname)}>\n''' +
"".join(f'<option value="{e}">{e}</option>\n' for e in uniqueChoices) + ' </param>\n')
else:
default = a.default
if isinstance(a.type, boxes.BoolArg):
Expand All @@ -77,18 +74,18 @@ class Boxes2INX:
}.get(a.type, '"string"')

if t == '"int"' or t == '"float" precision="2"':
return ''' <param name="%s" type=%s max="9999" gui-text="%s" gui-description=%s>%s</param>\n''' % (name, t, viewname, quoteattr(a.help or viewname), default)
return f'''<param name="{name}" type={t} max="9999" gui-text="{viewname}" gui-description={quoteattr(a.help or viewname)}>{default}</param>\n'''

else:
return ''' <param name="%s" type=%s gui-text="%s" gui-description=%s>%s</param>\n''' % (name, t, viewname, quoteattr(a.help or viewname), default)
return f'''<param name="{name}" type={t} gui-text="{viewname}" gui-description={quoteattr(a.help or viewname)}>{default}</param>\n'''

def generator2inx(self, name, box):
result = ["""<?xml version="1.0" encoding="UTF-8"?>
result = [f"""<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>%s</name>
<id>info.festi.boxes.py.%s</id>
<param name="generator" type="string" gui-hidden="true">%s</param>
<param name="tab" type="notebook">""" % (name, name, name.lower())]
<name>{name}</name>
<id>info.festi.boxes.py.{name}</id>
<param name="generator" type="string" gui-hidden="true">{name.lower()}</param>
<param name="tab" type="notebook">"""]
groupid = 0
for group in box.argparser._action_groups:
if not group._group_actions:
Expand All @@ -107,32 +104,28 @@ class Boxes2INX:
if self.arg2inx(a, prefix) != "":
pageParams.append(self.arg2inx(a, prefix))
if len(pageParams) > 0:
result.append("""
<page name="tab_%s" gui-text="%s">
""" % (groupid, title))
result.append(f"""<page name="tab_{groupid}" gui-text="{title}">""")
result.extend(pageParams)
result.append(" </page>")
result.append("</page>\n")

groupid += 1
result.append("""
<page name="tab_%s" gui-text="Example">
""" % (groupid))
result.append(" <image>./" + name + "-thumb.jpg</image>\n")
result.append(" </page>\n")
result.append("""</param>
<label appearance="url">https://www.festi.info/boxes.py/""" + name + """</label>
result.append(f"""<page name="tab_{groupid}" gui-text="Example">\n""")
result.append(f"""<image>./{name}-thumb.jpg</image>\n""")
result.append("</page>\n")
result.append(f"""</param>
<label appearance="url">https://www.festi.info/boxes.py/{name}</label>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu name="Boxes.py">
<submenu name="%s"/>
<submenu name="{self.groups_by_name[box.ui_group].title}"/>
</submenu>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">boxes_proxy.py</command>
</script>
</inkscape-extension>""" % self.groups_by_name[box.ui_group].title)
</inkscape-extension>""")
return b''.join(s.encode("utf-8") for s in result)

def writeINX(self, name, box, path):
Expand Down
3 changes: 1 addition & 2 deletions scripts/boxes2pot
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class Boxes2pot:
def _readEdgeDescriptions(self):
for char, descr in edges.getDescriptions().items():
self.add(descr, f"{char} edge description", "boxes/edges.py")
self.add(f"{char} {descr}", f"{char} edge description",
"boxes/edges.py")
self.add(f"{char} {descr}", f"{char} edge description", "boxes/edges.py")

def addBoxParams(self, name, box, location=None):
for group in box.argparser._action_groups:
Expand Down
2 changes: 1 addition & 1 deletion scripts/boxesserver
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ class BServer:
http_headers = [('Content-type', 'image/png')]
http_headers.append(('X-Robots-Tag', 'noindex,nofollow'))
qr_format = "png"
fn = (box.__class__.__name__)
fn = box.__class__.__name__
start_response(status, http_headers)
qrcode = get_qrcode(box.metadata["url_short"], qr_format)
return (qrcode,)
Expand Down