Skip to content

Commit 7105b79

Browse files
committed
Added Commit logging
1 parent 9bff3ae commit 7105b79

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

Main.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
DEPOT = ""
88
parser = optparse.OptionParser()
99
parser.add_option("-o", dest="output", default ="Gource.log",help="Where to store the output file")
10+
parser.add_option("-c", dest="captions", default = "", help="Caption file (if any)\nCaptions will be the commit messages")
1011
(options, args) = parser.parse_args()
1112

1213
if not len(args)==1:
@@ -23,6 +24,13 @@
2324
except:
2425
print(colorama.Fore.RED+"Check if {} is a correct accessible path, and that I have perms to write to it..".format(options.output)+colorama.Fore.RESET)
2526
sys.exit(1)
27+
if(options.captions):
28+
try: #Idiot Proofing..
29+
a = open(options.captions, 'w')
30+
a.close()
31+
except:
32+
print(colorama.Fore.RED+"Check if {} is a correct accessible path, and that I have perms to write to it..".format(options.captions)+colorama.Fore.RESET)
33+
sys.exit(1)
2634

2735

2836
def FetchChanges(depot:str)->typing.List[str]:
@@ -44,37 +52,42 @@ def FetchChanges(depot:str)->typing.List[str]:
4452
sys.exit(1)
4553

4654

47-
def ParseChanges(changes:typing.List[str])->typing.List[str]:
55+
def ParseChanges(changes:typing.List[str])->typing.List[typing.List[str]]:
4856

4957
result = []
58+
resultCaptions = []
5059

51-
getChange = re.compile(r"Change (\d+)", re.RegexFlag.IGNORECASE)
60+
getChangeNumDesc = re.compile(r"Change (\d+).*'(.*)'", re.RegexFlag.IGNORECASE)
5261
nameDate = re.compile(r".*\s(\w*)@.*(\d{4,}\/\d{2}\/\d{2}\s.*)\s.*")
5362
fileAction = re.compile(r"\.\.\. (.*)#\d+\s(\w*).*", re.RegexFlag.MULTILINE)
63+
description = re.compile(r"^\t((?:.|\n|\r)+)\nAffected", re.RegexFlag.MULTILINE)
5464

5565
parsed = 1
5666
for change in changes:
57-
changeNum = int(re.match(getChange, change)[1]) #TODO: Checks..
67+
match = re.match(getChangeNumDesc, change)
68+
changeNum = int(match[1]) #TODO: Checks..
5869

5970
# multiplier = int(parsed/(len(changes)*.01))
6071
# print('['+'█'*multiplier+' '*(100-multiplier)+']'+'\r') #Boi, I suck at ascii art
6172
print("Parsing ChangeNums [{}/{}]".format(parsed, len(changes)), end='\r')
6273
parsed+=1
6374

6475
try:
65-
description = subprocess.check_output("p4 describe -s {}".format(changeNum), stderr=subprocess.PIPE)
76+
descResult = subprocess.check_output("p4 describe -s {}".format(changeNum), stderr=subprocess.PIPE)
6677
except subprocess.CalledProcessError as e:
6778
print(colorama.Fore.RED+e.stderr.decode("utf-8", errors ="ignore")+colorama.Fore.RESET)
6879
sys.exit(1)
6980
else:
70-
description = description.decode("utf-8", errors ="ignore")
81+
descResult = descResult.decode("utf-8", errors ="ignore")
82+
desc = re.search(description, descResult[:descResult.rfind("Affected files ...\r")+20])[1].replace('\n', '').replace('\r', '')
7183

72-
name = re.match(nameDate, description)
84+
name = re.match(nameDate, descResult)
7385
date = name[2] ; name = name[1]
7486
date = int(datetime.datetime.strptime(date, "%Y/%m/%d %H:%M:%S\r").timestamp())
87+
resultCaptions.append("{}|{}".format(date, desc))
7588

76-
description = description[description.rfind("Affected files ...\r\n\r\n")+len("Affected files ...\r\n\r\n"):] #Anti Injection
77-
fileActionMatches = re.findall(fileAction, description)
89+
descResult = descResult[descResult.rfind("Affected files ...\r\n\r\n")+len("Affected files ...\r\n\r\n"):] #Anti Injection
90+
fileActionMatches = re.findall(fileAction, descResult)
7891
for match in fileActionMatches:
7992
if match[1] not in "add edit delete branch integrate" : continue
8093

@@ -87,15 +100,23 @@ def ParseChanges(changes:typing.List[str])->typing.List[str]:
87100

88101
print('')
89102
result.reverse()
90-
return result
103+
resultCaptions.reverse()
104+
return [result, resultCaptions]
91105

92106

93-
def Serialize(gourceChanges:typing.List[str]):
94-
print(colorama.Fore.LIGHTBLACK_EX+"Serializing..", end='')
107+
def Serialize(gourceChanges:typing.List[typing.List[str]]):
108+
print(colorama.Fore.LIGHTBLACK_EX+"Serializing log..", end='')
95109
with open(options.output, 'w') as file:
96-
for change in gourceChanges:
110+
for change in gourceChanges[0]:
97111
file.write(change+'\n')
98112
print("DONE"+colorama.Fore.RESET)
99113

114+
if(options.captions):
115+
print(colorama.Fore.LIGHTBLACK_EX + "Serializing captions..", end='')
116+
with open(options.captions, 'w') as file:
117+
for change in gourceChanges[1]:
118+
file.write(change + '\n')
119+
print("DONE"+colorama.Fore.RESET)
120+
100121
Serialize(ParseChanges(FetchChanges(DEPOT))) #Yeah, functions aren't really necessary for this, but meh
101122
print(colorama.Fore.GREEN+"All went well it seems, Now you can simple add the log to the gource command line.\ngource.exe {}\n\no/".format(options.output)+colorama.Fore.RESET)

0 commit comments

Comments
 (0)