Advertisement
Guest User

Untitled

a guest
May 31st, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import subprocess
  2. import re
  3. from dateutil import parser
  4.  
  5. class History(object):
  6. def __init__(self, commits):
  7. self._commits = ['%s' % n for n in commits if n.ot]
  8.  
  9. def __iter__(self):
  10. return iter()
  11.  
  12. def __str__(self):
  13. return '\n\n'.join(self._commits)
  14.  
  15. class Commit(object):
  16. _ot = False
  17. _quittingTime = 16
  18.  
  19. def __init__(self, raw):
  20. self._pieces = [x.strip() for x in raw.split('\\n') if x != ''][:4]
  21.  
  22. if (len(self._pieces) >=4):
  23. self._pieces = [re.sub(r'^([A-Z].*:\ )', '', x) for x in self._pieces]
  24. dateObj = parser.parse(self._pieces[2])
  25. self._pieces[2] = dateObj.strftime('%A %B %d %I:%M %p')
  26.  
  27. if (dateObj.hour >= self._quittingTime or dateObj.weekday() >= 5):
  28. self._ot = True
  29.  
  30. def __str__(self):
  31. return '\n'.join(self._pieces)
  32.  
  33. @property
  34. def ot(self):
  35. return self._ot
  36.  
  37. def runSubProc(args):
  38. subp = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  39. return str(subp.stdout.read())
  40.  
  41. def getHistory(user):
  42. logs = runSubProc(["git", "log", '--author=%s' % user, "--no-merges"])
  43. return History([Commit(x) for x in logs.split("commit")])
  44.  
  45. def main():
  46. user = runSubProc(["git", "config", "user.email"]).strip("b'")[:-2]
  47. logs = getHistory(user)
  48. print(logs)
  49.  
  50. if __name__ == '__main__':
  51. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement