Skip to content

Commit a54526b

Browse files
authored
Remove unnecessaries (#44)
Signed-off-by: Ethan Lee <[email protected]>
1 parent 7ed49a6 commit a54526b

File tree

8 files changed

+106
-116
lines changed

8 files changed

+106
-116
lines changed

.github/workflows/pull-request.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ jobs:
2929
pip install tox
3030
- name: Run Tox
3131
run: |
32+
tox -e release_flake8
3233
tox -e release
3334
reuse:
3435
runs-on: ubuntu-latest
35-
steps:
36+
steps:
3637
- uses: actions/checkout@v3
3738
- name: REUSE Compliance Check
3839
uses: fsfe/reuse-action@v1

script/copy_notice_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ def copy_and_create_dir(input_dir):
2929
if not os.path.exists(os.path.join(dist_path, file)):
3030
shutil.copy2(src_file, dist_path)
3131

32-
except Exception as e:
32+
except Exception:
3333
pass

script/generate-notice-files.py

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@
3939
'"': "&quot;",
4040
"'": "&apos;",
4141
">": "&gt;",
42-
"<": "&lt;",
43-
}
42+
"<": "&lt;"}
43+
4444

4545
def hexify(s):
46-
return ("%02x"*len(s)) % tuple(map(ord, s))
46+
return ("%02x" * len(s)) % tuple(map(ord, s))
47+
4748

4849
def md5sum(filename):
4950
"""Calculate an MD5 of the file given by FILENAME,
@@ -63,9 +64,10 @@ def md5sum(filename):
6364

6465
def html_escape(text):
6566
"""Produce entities within text."""
66-
return "".join(HTML_ESCAPE_TABLE.get(c,c) for c in text)
67+
return "".join(HTML_ESCAPE_TABLE.get(c, c) for c in text)
68+
6769

68-
HTML_OUTPUT_CSS="""
70+
HTML_OUTPUT_CSS = """
6971
<style type="text/css">
7072
body { padding: 0; font-family: sans-serif; }
7173
.same-license { background-color: #eeeeee; border-top: 20px solid white; padding: 10px; }
@@ -74,6 +76,7 @@ def html_escape(text):
7476
</style>
7577
"""
7678

79+
7780
def combine_notice_files_html(file_hash, input_dirs, output_filename):
7881
"""Combine notice files in FILE_HASH and output a HTML version to OUTPUT_FILENAME."""
7982

@@ -85,68 +88,70 @@ def combine_notice_files_html(file_hash, input_dirs, output_filename):
8588
id_count = 0
8689
for value in file_hash:
8790
for filename in value:
88-
id_table[filename] = id_count
91+
id_table[filename] = id_count
8992
id_count += 1
9093

9194
# Open the output file, and output the header pieces
9295
output_file = open(output_filename, "wb")
9396

94-
print >> output_file, "<html><head>"
95-
print >> output_file, HTML_OUTPUT_CSS
96-
print >> output_file, '</head><body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">'
97+
print("<html><head>", file=output_file)
98+
print(HTML_OUTPUT_CSS, file=output_file)
99+
print('</head><body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">', file=output_file)
97100

98101
# Output our table of contents
99-
print >> output_file, '<div class="toc">'
100-
print >> output_file, "<ul>"
102+
print('<div class="toc">', file=output_file)
103+
print("<ul>", file=output_file)
101104

102105
# Flatten the list of lists into a single list of filenames
103106
sorted_filenames = sorted(itertools.chain.from_iterable(file_hash))
104107

105108
# Print out a nice table of contents
106109
for filename in sorted_filenames:
107110
stripped_filename = SRC_DIR_STRIP_RE.sub(r"\1", filename)
108-
print >> output_file, '<li><a href="#id%d">%s</a></li>' % (id_table.get(filename), stripped_filename)
111+
print('<li><a href="#id%d">%s</a></li>' % (id_table.get(filename), stripped_filename), file=output_file)
109112

110-
print >> output_file, "</ul>"
111-
print >> output_file, "</div><!-- table of contents -->"
113+
print("<ul>", file=output_file)
114+
print("</div><!-- table of contents -->", file=output_file)
112115
# Output the individual notice file lists
113-
print >>output_file, '<table cellpadding="0" cellspacing="0" border="0">'
116+
print('<table cellpadding="0" cellspacing="0" border="0">', file=output_file)
114117
for value in file_hash:
115-
print >> output_file, '<tr id="id%d"><td class="same-license">' % id_table.get(value[0])
116-
print >> output_file, '<div class="label">Notices for file(s):</div>'
117-
print >> output_file, '<div class="file-list">'
118+
print('<tr id="id%d"><td class="same-license">' % id_table.get(value[0]), file=output_file)
119+
print('<div class="label">Notices for file(s):</div>', file=output_file)
118120
for filename in value:
119-
print >> output_file, "%s <br/>" % (SRC_DIR_STRIP_RE.sub(r"\1", filename))
120-
print >> output_file, "</div><!-- file-list -->"
121-
print >> output_file
122-
print >> output_file, '<pre class="license-text">'
123-
print >> output_file, html_escape(open(value[0]).read())
124-
print >> output_file, "</pre><!-- license-text -->"
125-
print >> output_file, "</td></tr><!-- same-license -->"
126-
print >> output_file
127-
print >> output_file
128-
print >> output_file
121+
print("%s <br/>" % (SRC_DIR_STRIP_RE.sub(r"\1", filename)), file=output_file)
122+
print("</div><!-- file-list -->", file=output_file)
123+
print(file=output_file)
124+
print('<pre class="license-text">', file=output_file)
125+
print(html_escape(open(value[0]).read()), file=output_file)
126+
print("</pre><!-- license-text -->", file=output_file)
127+
print("</td></tr><!-- same-license -->", file=output_file)
128+
print(file=output_file)
129+
print(file=output_file)
130+
print(file=output_file)
129131

130132
# Finish off the file output
131-
print >> output_file, "</table>"
132-
print >> output_file, "</body></html>"
133+
print("</table>", file=output_file)
134+
print("</body></html>", file=output_file)
133135
output_file.close()
134136

137+
135138
def combine_notice_files_text(file_hash, input_dirs, output_filename, file_title):
136139
"""Combine notice files in FILE_HASH and output a text version to OUTPUT_FILENAME."""
137140

138141
SRC_DIR_STRIP_RE = re.compile("(?:" + "|".join(re.escape(input_dirs)) + ")(/.*).txt")
139142
output_file = open(output_filename, "wb")
140-
print >> output_file, file_title
143+
print(file_title, file=output_file)
141144
for value in file_hash:
142-
print >> output_file, "============================================================"
143-
print >> output_file, "Notices for file(s):"
144-
for filename in value:
145-
print >> output_file, SRC_DIR_STRIP_RE.sub(r"\1", filename)
146-
print >> output_file, "------------------------------------------------------------"
147-
print >> output_file, open(value[0]).read()
145+
print("============================================================", file=output_file)
146+
print("Notices for file(s):", file=output_file)
147+
148+
for filename in value:
149+
print(SRC_DIR_STRIP_RE.sub(r"\1", filename), file=output_file)
150+
print("------------------------------------------------------------", file=output_file)
151+
print(open(value[0]).read(), file=output_file)
148152
output_file.close()
149153

154+
150155
def combine_notice_files_xml(files_with_same_hash, input_dirs, output_filename):
151156
"""Combine notice files in FILE_HASH and output a XML version to OUTPUT_FILENAME."""
152157

@@ -157,24 +162,24 @@ def combine_notice_files_xml(files_with_same_hash, input_dirs, output_filename):
157162
id_table = {}
158163
for file_key in files_with_same_hash.keys():
159164
for filename in files_with_same_hash[file_key]:
160-
id_table[filename] = file_key
165+
id_table[filename] = file_key
161166

162167
# Open the output file, and output the header pieces
163168
output_file = open(output_filename, "wb")
164169

165-
print >> output_file, '<?xml version="1.0" encoding="utf-8"?>'
166-
print >> output_file, "<licenses>"
170+
print('<?xml version="1.0" encoding="utf-8"?>', file=output_file)
171+
print("<licenses>", file=output_file)
167172

168173
# Flatten the list of lists into a single list of filenames
169174
sorted_filenames = sorted(id_table.keys())
170175

171176
# Print out a nice table of contents
172177
for filename in sorted_filenames:
173178
stripped_filename = SRC_DIR_STRIP_RE.sub(r"\1", filename)
174-
print >> output_file, '<file-name contentId="%s">%s</file-name>' % (id_table.get(filename), stripped_filename)
179+
print('<file-name contentId="%s">%s</file-name>' % (id_table.get(filename), stripped_filename), file=output_file)
175180

176-
print >> output_file
177-
print >> output_file
181+
print(file=output_file)
182+
print(file=output_file)
178183

179184
processed_file_keys = []
180185
# Output the individual notice file lists
@@ -184,13 +189,14 @@ def combine_notice_files_xml(files_with_same_hash, input_dirs, output_filename):
184189
continue
185190
processed_file_keys.append(file_key)
186191

187-
print >> output_file, '<file-content contentId="%s"><![CDATA[%s]]></file-content>' % (file_key, html_escape(open(filename).read()))
188-
print >> output_file
192+
print('<file-content contentId="%s"><![CDATA[%s]]></file-content>' % (file_key, html_escape(open(filename).read())), file=output_file)
193+
print(file=output_file)
189194

190195
# Finish off the file output
191-
print >> output_file, "</licenses>"
196+
print("</licenses>", file=output_file)
192197
output_file.close()
193198

199+
194200
def get_args():
195201
parser = argparse.ArgumentParser()
196202
parser.add_argument(
@@ -216,6 +222,7 @@ def get_args():
216222
help='The sub directories which should be excluded.')
217223
return parser.parse_args()
218224

225+
219226
def main(argv):
220227
args = get_args()
221228

@@ -229,7 +236,7 @@ def main(argv):
229236
included_subdirs = args.included_subdirs
230237
if args.excluded_subdirs is not None:
231238
excluded_subdirs = args.excluded_subdirs
232-
239+
233240
notice_files_to_append = os.path.join(args.source_dir[0], "notice")
234241
copy_notice_files.copy_and_create_dir(notice_files_to_append)
235242
input_dirs = [os.path.normpath(source_dir) for source_dir in args.source_dir]
@@ -242,14 +249,16 @@ def main(argv):
242249
if len(included_subdirs) > 0:
243250
matched = False
244251
for subdir in included_subdirs:
245-
if (root == (input_dir + '/' + subdir) or
246-
root.startswith(input_dir + '/' + subdir + '/')):
252+
matches_subdir = root == (input_dir + '/' + subdir)
253+
starts_with_subdir = root.startswith(input_dir + '/' + subdir + '/')
254+
if matches_subdir or starts_with_subdir:
247255
matched = True
248256
break
249257
elif len(excluded_subdirs) > 0:
250258
for subdir in excluded_subdirs:
251-
if (root == (input_dir + '/' + subdir) or
252-
root.startswith(input_dir + '/' + subdir + '/')):
259+
matches_subdir = root == (input_dir + '/' + subdir)
260+
starts_with_subdir = root.startswith(input_dir + '/' + subdir + '/')
261+
if matches_subdir or starts_with_subdir:
253262
matched = False
254263
break
255264
if root.startswith(notice_files_to_append):
@@ -268,5 +277,6 @@ def main(argv):
268277
if xml_output_file is not None:
269278
combine_notice_files_xml(files_with_same_hash, input_dirs, xml_output_file)
270279

280+
271281
if __name__ == "__main__":
272282
main(sys.argv)

src/fosslight_android/_help.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
-m\t\t\t\t Analyze the source code for the path where the license could not be found.
2222
-e <path1> <path2..>\t Path to exclude from source analysis.
2323
-p\t\t\t\t Check files that should not be included in the Packaging file.
24-
-f\t\t\t\t Print result of Find Command for binary that can not find Source Code Path.
24+
-f\t\t\t\t Print result of Find Command for binary that can not find Source Code Path.
2525
-i\t\t\t\t Disable the function to automatically convert OSS names based on AOSP.
2626
-r <result.txt>\t\t result.txt file with a list of binaries to remove."""
2727

0 commit comments

Comments
 (0)