|
28 | 28 |
|
29 | 29 |
|
30 | 30 | def engine_gui(repository, hardware, version): |
31 | | - hardware = deepcopy(hardware) |
32 | | - del hardware['Serial Number'] |
| 31 | + # Prepare hardware information, marking missing values |
| 32 | + hardware = {k: v or "**MISSING**" for k, v in deepcopy(hardware).items() if k != 'Serial Number'} |
33 | 33 | module = hardware['Module'] |
34 | | - # Title |
35 | | - title = "GUI compact engine page missing for [{module}]".format(module=module) |
36 | | - # Template |
| 34 | + |
| 35 | + # Create issue title and template |
| 36 | + title = f"GUI compact engine page missing for [{module}]" |
37 | 37 | template = "engine-gui.md" |
38 | | - # body |
39 | | - body = "Please add a new jtop engine compact page for\n\n" |
40 | | - body += "### Board\n\n" |
41 | | - for name, value in hardware.items(): |
42 | | - if not value: |
43 | | - value = "**MISSING**" |
44 | | - body += " - {name}: {value}\n".format(name=name, value=value) |
45 | | - body += "\n### jetson-stats\n\n" |
46 | | - body += " - Version: " + version + "\n" |
47 | | - # Print all raw output |
48 | | - body += "\n<!-- Please attach a screenshot page from jtop Engine page -->\n" |
49 | | - body += "### Screenshot engine page\n\n" |
50 | | - body += "Screenshot page from jtop engine page attached" |
51 | | - # Make url |
| 38 | + |
| 39 | + # Create issue body |
| 40 | + body = ( |
| 41 | + "Please add a new jtop engine compact page for\n\n### Board\n\n" |
| 42 | + + "\n".join( |
| 43 | + [f" - {name}: {value}" for name, value in hardware.items()] |
| 44 | + ) |
| 45 | + ) |
| 46 | + body += f"\n\n### jetson-stats\n\n - Version: {version}\n" |
| 47 | + body += "\n<!-- Please attach a screenshot page from jtop Engine page -->\n### Screenshot engine page\n\nScreenshot page from jtop engine page attached" |
| 48 | + |
| 49 | + # Generate issue URL |
52 | 50 | url = make_issue(repository, title, body=body, labels="GUI,missing", template=template) |
53 | | - # message shell |
54 | | - message = "Module \"{module}\" missing in jtop GUI".format(module=module) |
55 | | - hyperlink(message, url, "open a Github issue & {attach} a engine page screenshot".format(attach=bcolors.bold('attach'))) |
| 51 | + |
| 52 | + # Print message with hyperlink |
| 53 | + message = f"Module \"{module}\" missing in jtop GUI" |
| 54 | + hyperlink(message, url, f"open a Github issue & {bcolors.bold('attach')} a engine page screenshot") |
56 | 55 |
|
57 | 56 |
|
58 | 57 | def jetpack_missing(repository, hardware, version): |
| 58 | + # Prepare L4T information |
59 | 59 | l4t = hardware['L4T'] |
60 | | - # Title |
61 | | - title = "jetson-stats not supported for [L4T {l4t}]".format(l4t=l4t) |
62 | | - # Template |
| 60 | + |
| 61 | + # Create issue title and template |
| 62 | + title = f"jetson-stats not supported for [L4T {l4t}]" |
63 | 63 | template = "jetpack-missing.md" |
64 | | - # Body |
65 | | - body = "Please update jetson-stats with new jetpack\n\n" |
66 | | - body += "### Linux for Tegra\n\n" |
67 | | - body += " - L4T: " + l4t + "\n\n" |
68 | | - body += "### Jetson-Stats\n\n" |
69 | | - body += " - Version: " + version + "\n" |
70 | | - # Make url |
| 64 | + |
| 65 | + # Create issue body |
| 66 | + body = f"Please update jetson-stats with new jetpack\n\n### Linux for Tegra\n\n - L4T: {l4t}\n\n### Jetson-Stats\n\n - Version: {version}\n" |
| 67 | + |
| 68 | + # Generate issue URL |
71 | 69 | url = make_issue(repository, title, body=body, labels="Jetpack,missing", template=template) |
72 | | - # message shell |
73 | | - message = "jetson-stats not supported for [L4T {l4t}]".format(l4t=hardware['L4T']) |
| 70 | + |
| 71 | + # Print message with hyperlink |
| 72 | + message = f"jetson-stats not supported for [L4T {l4t}]" |
74 | 73 | hyperlink(message, url, "open a Github issue") |
75 | 74 |
|
76 | 75 |
|
77 | 76 | def get_hardware_log(): |
78 | | - # Print platform |
| 77 | + # Collect platform and raw output information |
79 | 78 | platform = get_platform_variables() |
80 | | - body = "--------------------- PLATFORM -------------------------\n" |
81 | | - for name, value in platform.items(): |
82 | | - body += "{name}: {value}\n".format(name=name, value=value) |
83 | | - # Print all jetson raw output |
84 | 79 | raw_output = get_jetson_raw_output() |
85 | | - body += "-------------------- JETSON RAW OUTPUT -----------------\n" |
86 | | - for name, value in raw_output.items(): |
87 | | - body += "------------------\n" |
88 | | - body += "Path: {name}\n{value}\n".format(name=name, value=value) |
89 | | - # Print device list |
90 | | - raw_output = get_raw_igpu_devices() |
| 80 | + igpu_output = get_raw_igpu_devices() |
| 81 | + |
| 82 | + # Create log body |
| 83 | + body = ( |
| 84 | + "--------------------- PLATFORM -------------------------\n" |
| 85 | + + "\n".join([f"{name}: {value}" for name, value in platform.items()]) |
| 86 | + ) |
| 87 | + body += "\n-------------------- JETSON RAW OUTPUT -----------------\n" |
| 88 | + body += "\n".join([f"------------------\nPath: {name}\n{value}" for name, value in raw_output.items()]) |
91 | 89 | body += "\n-------------------- IGPU OUTPUT ---------------------\n" |
92 | | - for path, value in raw_output.items(): |
93 | | - body += "------------------\n" |
94 | | - body += "Path: {path}\n{value}\n".format(path=path, value=value) |
| 90 | + body += "\n".join([f"------------------\nPath: {path}\n{value}" for path, value in igpu_output.items()]) |
| 91 | + |
95 | 92 | return body |
96 | 93 |
|
97 | 94 |
|
98 | 95 | def hardware_missing(repository, hardware, version): |
99 | | - hardware = deepcopy(hardware) |
100 | | - del hardware['Serial Number'] |
101 | | - # Title |
102 | | - if 'P-Number' in hardware: |
103 | | - title = "Hardware Missing: {pnumber}".format(pnumber=hardware.get('P-Number', '')) |
104 | | - else: |
105 | | - title = "Hardware Missing".format() |
106 | | - # Template |
| 96 | + # Prepare hardware information, marking missing values |
| 97 | + hardware = {k: v or "**MISSING**" for k, v in deepcopy(hardware).items() if k != 'Serial Number'} |
| 98 | + |
| 99 | + # Create issue title and template |
| 100 | + title = f"Hardware Missing: {hardware.get('P-Number', '')}" if 'P-Number' in hardware else "Hardware Missing" |
107 | 101 | template = "hardware-missing.md" |
108 | | - # Body |
109 | | - body = "Please update jetson-stats with this board\n\n" |
110 | | - body += "### Board\n\n" |
111 | | - for name, value in hardware.items(): |
112 | | - if not value: |
113 | | - value = "**MISSING**" |
114 | | - body += " - {name}: {value}\n".format(name=name, value=value) |
115 | | - body += "\n### Jetson-Stats\n\n" |
116 | | - body += " - Version: " + version + "\n" |
117 | | - # Print all raw output |
118 | | - body += "\n<!-- Please attach the output from: jtop --error-log -->\n" |
119 | | - body += "### RAW Data\n\n" |
120 | | - body += "File from `--error-log` attached" |
121 | | - # Make url |
| 102 | + |
| 103 | + # Create issue body |
| 104 | + body = ( |
| 105 | + "Please update jetson-stats with this board\n\n### Board\n\n" |
| 106 | + + "\n".join( |
| 107 | + [f" - {name}: {value}" for name, value in hardware.items()] |
| 108 | + ) |
| 109 | + ) |
| 110 | + body += f"\n\n### Jetson-Stats\n\n - Version: {version}\n" |
| 111 | + body += "\n<!-- Please attach the output from: jtop --error-log -->\n### RAW Data\n\nFile from `--error-log` attached" |
| 112 | + |
| 113 | + # Generate issue URL |
122 | 114 | url = make_issue(repository, title, body=body, labels="Hardware,missing", template=template) |
123 | | - # message shell |
| 115 | + |
| 116 | + # Print message with hyperlink |
124 | 117 | message = "jtop not support this hardware" |
125 | | - hyperlink(message, url, "open a Github issue & {attach} file from: jtop --error-log".format(attach=bcolors.bold('attach'))) |
| 118 | + hyperlink(message, url, f"open a Github issue & {bcolors.bold('attach')} file from: jtop --error-log") |
126 | 119 |
|
127 | 120 |
|
128 | 121 | def hyperlink(message, url, text): |
129 | | - # Reference: |
130 | | - # 1. http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html |
131 | | - # 2. https://stackoverflow.com/questions/40419276/python-how-to-print-text-to-console-as-hyperlink |
132 | | - # 3. https://purpleidea.com/blog/2018/06/29/hyperlinks-in-gnome-terminal/ |
133 | | - # 4. https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda |
134 | | - # 5. https://stackoverflow.com/questions/44078888/clickable-html-links-in-python-3-6-shell |
135 | 122 | # Print starting message |
136 | | - print("[{status}] {message}".format(status=bcolors.warning(), message=message)) |
137 | | - print(" Please, try: {bold}sudo pip3 install -U jetson-stats{reset} or".format(bold=bcolors.BOLD, reset=bcolors.ENDC)) |
| 123 | + print(f"[{bcolors.warning()}] {message}") |
| 124 | + print(f" Please, try: {bcolors.BOLD}sudo pip3 install -U jetson-stats{bcolors.ENDC} or") |
| 125 | + |
138 | 126 | # Generate hyperlink for shell |
139 | | - # Check type of shell |
140 | 127 | try: |
141 | | - link = u'\u001b]8;;{url}\u001b\\{text}\u001b]8;;\u001b\\ (press CTRL + Click)'.format(url=url, text=text) |
| 128 | + link = f'\u001b]8;;{url}\u001b\\{text}\u001b]8;;\u001b\\ (press CTRL + Click)' |
142 | 129 | except UnicodeDecodeError: |
143 | | - link = "{text}".format(text=text) |
144 | | - print(" {link}".format(link=link)) |
| 130 | + link = f"{text}" |
| 131 | + print(f" {link}") |
145 | 132 |
|
146 | 133 |
|
147 | 134 | def make_issue(repository, title, body="", labels="", template=""): |
148 | | - # Reference |
149 | | - # https://help.github.com/en/enterprise/2.17/user/github/managing-your-work-on-github/about-automation-for-issues-and-pull-requests-with-query-parameters |
150 | | - # https://krypted.com/utilities/html-encoding-reference/ |
| 135 | + # Encode title and body for URL |
151 | 136 | title = title.replace(" ", "+").replace("[", "%5B").replace("]", "%5D") |
152 | | - url = "{repository}/new?title={title}".format(repository=repository, title=title) |
| 137 | + url = f"{repository}/new?title={title}" |
153 | 138 | if labels: |
154 | | - url += "&labels=" + labels |
| 139 | + url += f"&labels={labels}" |
155 | 140 | if template: |
156 | | - url += "&template=" + template |
| 141 | + url += f"&template={template}" |
157 | 142 | if body: |
158 | 143 | body = body.replace(" ", "+").replace("#", "%23").replace("\n", "%0A").replace("*", "%2A") |
159 | | - url += "&body=" + body |
| 144 | + url += f"&body={body}" |
160 | 145 | return url |
161 | 146 | # EOF |
0 commit comments