Create a nice header in the form of a list of strings using the information that has been filled in. All arguments except 'width' and 'tunings' should be strings. 'width' should be an integer and 'tunings' a list of tunings representing the instruments.
(
width=80,
title="Untitled",
subtitle="",
author="",
email="",
description="",
tunings=None,
)
| 44 | |
| 45 | |
| 46 | def add_headers( |
| 47 | width=80, |
| 48 | title="Untitled", |
| 49 | subtitle="", |
| 50 | author="", |
| 51 | email="", |
| 52 | description="", |
| 53 | tunings=None, |
| 54 | ): |
| 55 | """Create a nice header in the form of a list of strings using the |
| 56 | information that has been filled in. |
| 57 | |
| 58 | All arguments except 'width' and 'tunings' should be strings. 'width' |
| 59 | should be an integer and 'tunings' a list of tunings representing the |
| 60 | instruments. |
| 61 | """ |
| 62 | if tunings is None: |
| 63 | tunings = [] |
| 64 | result = [""] |
| 65 | title = str.upper(title) |
| 66 | result += [str.center(" ".join(title), width)] |
| 67 | if subtitle != "": |
| 68 | result += ["", str.center(str.title(subtitle), width)] |
| 69 | if author != "" or email != "": |
| 70 | result += ["", ""] |
| 71 | if email != "": |
| 72 | result += [str.center("Written by: %s <%s>" % (author, email), width)] |
| 73 | else: |
| 74 | result += [str.center("Written by: %s" % author, width)] |
| 75 | if description != "": |
| 76 | result += ["", ""] |
| 77 | words = description.split() |
| 78 | lines = [] |
| 79 | line = [] |
| 80 | last = 0 |
| 81 | for word in words: |
| 82 | if len(word) + last < width - 10: |
| 83 | line.append(word) |
| 84 | last += len(word) + 1 |
| 85 | else: |
| 86 | lines.append(line) |
| 87 | line = [word] |
| 88 | last = len(word) + 1 |
| 89 | lines.append(line) |
| 90 | for line in lines: |
| 91 | result += [str.center(" ".join(line), width)] |
| 92 | if tunings != []: |
| 93 | result += ["", "", str.center("Instruments", width)] |
| 94 | for (i, tuning) in enumerate(tunings): |
| 95 | result += [ |
| 96 | "", |
| 97 | str.center("%d. %s" % (i + 1, tuning.instrument), width), |
| 98 | str.center(tuning.description, width), |
| 99 | ] |
| 100 | result += ["", ""] |
| 101 | return result |
| 102 | |
| 103 |
no outgoing calls
no test coverage detected