Skip to content

Instantly share code, notes, and snippets.

@johnnieskywalker
Created May 11, 2023 10:39
Show Gist options
  • Save johnnieskywalker/8ab96276b9afd0e8a5ee0030030f92ab to your computer and use it in GitHub Desktop.
Save johnnieskywalker/8ab96276b9afd0e8a5ee0030030f92ab to your computer and use it in GitHub Desktop.
Script for sleaning spdx from flat .sol files, except the first one
import os
flattened_dir = "./flattened"
for filename in os.listdir(flattened_dir):
file_path = os.path.join(flattened_dir, filename)
if os.path.isfile(file_path) and filename.endswith("_flattened.sol"):
with open(file_path, "r") as f:
lines = f.readlines()
first_spdx_line = next((line for line in lines if "SPDX-License-Identifier" in line), None)
updated_lines = [first_spdx_line] + [line for line in lines if "SPDX-License-Identifier" not in line]
with open(file_path, "w") as f:
f.writelines(updated_lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment