github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/bin/update-authors.py (about) 1 #!/usr/bin/env python3 2 """ 3 Update the authors.md file with the authors from the git log 4 """ 5 6 import re 7 import subprocess 8 9 AUTHORS = "docs/content/authors.md" 10 IGNORE = "bin/.ignore-emails" 11 12 def load(filename): 13 """ 14 returns a set of emails already in the file 15 """ 16 with open(filename) as fd: 17 authors = fd.read() 18 return set(re.findall(r"<(.*?)>", authors)) 19 20 def add_email(name, email): 21 """ 22 adds the email passed in to the end of authors.md 23 """ 24 print("Adding %s <%s>" % (name, email)) 25 with open(AUTHORS, "a+") as fd: 26 print(" * %s <%s>" % (name, email), file=fd) 27 subprocess.check_call(["git", "commit", "-m", "Add %s to contributors" % name, AUTHORS]) 28 29 def main(): 30 out = subprocess.check_output(["git", "log", '--reverse', '--format=%an|%ae', "master"]) 31 out = out.decode("utf-8") 32 33 ignored = load(IGNORE) 34 previous = load(AUTHORS) 35 previous.update(ignored) 36 for line in out.split("\n"): 37 line = line.strip() 38 if line == "": 39 continue 40 name, email = line.split("|") 41 if email in previous: 42 continue 43 previous.add(email) 44 add_email(name, email) 45 46 if __name__ == "__main__": 47 main()