Skip to content

Instantly share code, notes, and snippets.

@mdyzma
Last active June 30, 2020 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdyzma/13d588a0cdf48eab78ba2cb047fbc8e2 to your computer and use it in GitHub Desktop.
Save mdyzma/13d588a0cdf48eab78ba2cb047fbc8e2 to your computer and use it in GitHub Desktop.
import os
import glob
from typing import List
preamble = """
Copyright 2020 (c) Netguru S.A.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License."""
def get_file_list(data_dir: str) -> List[str]:
files_list = glob.glob(os.path.join(
data_dir, "**", "*.py"), recursive=True)
files_list = [file for file in files_list if "__init__" not in file]
return files_list
def prepend_preamble(filename: str, preamble: str) -> None:
with open(filename, "r+") as f:
content = f.read()
f.seek(0, 0)
f.write(preamble + "\n\n" + content)
def add_preamble_to_files(preamble: str, files_list: List[str]) -> None:
for file in files_list:
prepend_preamble(file, preamble)
if __name__ == "__main__":
files = get_file_list(".")
preamble = ["# " + line for line in preamble.split("\n")]
preamble = "\n".join(preamble)
add_preamble_to_files(preamble, files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment