Guest User

Untitled

a guest
Apr 19th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import os
  4. import os.path
  5. import re
  6. import sys
  7. import string
  8.  
  9. from datetime import datetime
  10.  
  11. def git_repos(directory):
  12. for elem in os.listdir(directory):
  13. entry = os.path.join(directory, elem)
  14. if os.path.isdir(entry):
  15. yield entry
  16.  
  17. def git_log(repo, args = "--format='%an,%ad'"):
  18. return os.popen("git --git-dir='%s' log %s" % (repo, args))
  19.  
  20. input_fields = [ "name", "date" ]
  21.  
  22. def parse_rfc822_date(date):
  23. try:
  24. d = datetime.strptime(date, "%c +0000").date()
  25. return "%d-%02d" % (d.year, d.month)
  26. except ValueError:
  27. d = datetime.strptime(date, "%c -0400").date()
  28. return "%d-%02d" % (d.year, d.month)
  29.  
  30. data_fields = ( 'Date', 'Adinath', 'David', 'John', 'Fabian', 'Ramen' )
  31.  
  32. def add_to_table(table, entry):
  33. if re.search('(afshin|david)', entry['name'], re.IGNORECASE):
  34. name = data_fields[2]
  35. elif re.search('(john)', entry['name'], re.IGNORECASE):
  36. name = data_fields[3]
  37. elif re.search('(adi)', entry['name'], re.IGNORECASE):
  38. name = data_fields[1]
  39. elif re.search('fab', entry['name'], re.IGNORECASE):
  40. name = data_fields[4]
  41. elif re.search('ram', entry['name'], re.IGNORECASE):
  42. name = data_fields[5]
  43. else:
  44. return
  45.  
  46. if entry['date'] not in table:
  47. table[entry['date']] = {}
  48.  
  49. if name not in table[entry['date']]:
  50. table[entry['date']][name] = 1
  51. else:
  52. table[entry['date']][name] += 1
  53.  
  54. def field_map(dictseq, name, func):
  55. for d in dictseq:
  56. d[name] = func(d[name])
  57. yield d
  58.  
  59. def gen_cat(sources):
  60. for s in sources:
  61. for item in s:
  62. yield item
  63.  
  64. logs = (git_log(repo) for repo in git_repos(os.path.abspath(sys.argv[1])))
  65. lines = gen_cat(logs)
  66. lines = (dict(zip(input_fields, string.split(line[:-1], ','))) for line in lines)
  67. lines = field_map(lines, 'date', lambda x: parse_rfc822_date(x))
  68.  
  69. table = {}
  70. for x in lines: add_to_table(table, x)
  71.  
  72. keys = table.keys()
  73. keys.sort()
  74.  
  75. print 'COMMITS BY MONTH -*- mode: org -*-'
  76. print '#+PLOT: title:"Commits" ind:1 deps:(2 3 4 5 6) type:2d with:lines set:"yrange [0:]"'
  77. print '|%s|%s|%s|%s|%s|%s|' % data_fields
  78. print '|------------------+---------+-------+------+--------+-------|'
  79. for date in keys:
  80. for f in data_fields:
  81. if f not in table[date]:
  82. table[date][f] = 0
  83. print '|[%s-01 Mon]|%d|%d|%d|%d|%d|' % (date, table[date][data_fields[1]],
  84. table[date][data_fields[2]],
  85. table[date][data_fields[3]],
  86. table[date][data_fields[4]],
  87. table[date][data_fields[5]])
Add Comment
Please, Sign In to add comment