github.com/xhghs/rclone@v1.51.1-0.20200430155106-e186a28cced8/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 = [ "nick@raig-wood.com" ]
    11  
    12  def load():
    13      """
    14      returns a set of emails already in authors.md
    15      """
    16      with open(AUTHORS) as fd:
    17          authors = fd.read()
    18      emails = set(re.findall(r"<(.*?)>", authors))
    19      emails.update(IGNORE)
    20      return emails
    21  
    22  def add_email(name, email):
    23      """
    24      adds the email passed in to the end of authors.md
    25      """
    26      print("Adding %s <%s>" % (name, email))
    27      with open(AUTHORS, "a+") as fd:
    28          print("  * %s <%s>" % (name, email), file=fd)
    29      subprocess.check_call(["git", "commit", "-m", "Add %s to contributors" % name, AUTHORS])
    30      
    31  def main():
    32      out = subprocess.check_output(["git", "log", '--reverse', '--format=%an|%ae', "master"])
    33      out = out.decode("utf-8")
    34  
    35      previous = load()
    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()