Python: Regex & group(0) errors parsing Git History -
the goal here capture git log information following code functional except capturing files added or modified (see section 'for j in commit'):
import re import git import time import datetime repo = git.repo('/path/to/repo') data = repo.git.log('--name-status') data = "\n" + data data=re.split("\ncommit ",data) data.pop(0) commits_list = list(repo.iter_commits()) mm = [] in data: commit = i.split('\n') chash = commit[0] author = re.search('author:.*\n', i).group(0) author = re.sub(r'\<.*\>\n','',author) author = author.strip() email = re.search(('<.*>'),i).group(0) email = re.sub(r'[\<\>]','',email) date = re.search('date:.*\n', i).group(0) date = re.sub(r'[\n]','',date) tzone = re.search('-.*', date).group(0) tzone = re.sub(r'[\n]','',tzone) date = re.sub(r'-.*','',date) date = re.sub(r'date: ','',date.strip()) date = datetime.datetime.strptime(date, "%c") date = date.strftime('%s') files = [] j in commit: k = (re.search(r'a\t.*$|m\t.*$', i)).group(0) if k: files.append(k) l = [chash,author,email,date,tzone,files] print l mm.append(l) this results in attributeerror: 'nonetype' object has no attribute 'group' if move grouping if statement (ie, files.append(k.group(0))) repeat of same file if loop in executing each line. attempted try/except in loop similar results. not getting?
update
changed/corrected loop to:
for j in commit: try: k = (re.search(r'a\t.*$|m\t.*$', j)).group(0) files.append(k) except: none i repeat of same file name each file committed.
in line, should i j ?
k = (re.search(r'a\t.*$|m\t.*$', i)).group(0)
Comments
Post a Comment