Last active
September 2, 2021 22:32
-
-
Save nori26/4a217659d4886603244d65387600dd62 to your computer and use it in GitHub Desktop.
add_42header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
from datetime import datetime | |
def main(): | |
name = "unko" | |
mail = f"{name}@student.42tokyo.jp" | |
files = sys.argv[1:] | |
start = '/* ************************************************************************** */' | |
for file in files: | |
s = None | |
now = time(datetime.now()) | |
filename = os.path.basename(file) | |
with open(file, 'r') as f: | |
s = f.read() | |
if s[:len(start)] == start: | |
continue | |
with open(file, 'w') as f: | |
f.write(f'''\ | |
/* ************************************************************************** */ | |
/* */ | |
/* ::: :::::::: */ | |
/* {filename.ljust(51) }:+: :+: :+: */ | |
/* +:+ +:+ +:+ */ | |
/* By: {adjust(f"{name} <{mail}>", 43) }+#+ +:+ +#+ */ | |
/* +#+#+#+#+#+ +#+ */ | |
/* Created: {now} by {adjust(name, 17) } #+# #+# */ | |
/* Updated: {now} by {adjust(name, 17) }### ########.fr */ | |
/* */ | |
/* ************************************************************************** */ | |
''' + s) | |
def time(time): | |
return time.strftime("%Y/%m/%d %H:%M:%S") | |
def adjust(str, size): | |
return str.ljust(size)[:size] | |
if __name__ == "__main__": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find `pwd` -type f -name "*.c" -o -type f -name "*.h" | xargs python3 ~/42header.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment