-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonUtils.py
50 lines (42 loc) · 1.96 KB
/
jsonUtils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'''
json data related class
extract git log in json from
transfer json into Commit
write git-stein recipe
'''
import json
import os
from typing import List
from commitProcess.Commit import Commit
class JsonUtils:
def __init__(self):
self.repoPath = None
self.jsonPath = None
def setRepoPath(self, repoPath):
self.repoPath = repoPath
def setJsonPath(self, path):
self.jsonPath = path
'Get json format git commit info'
def gitJson(self):
if self.jsonPath == None:
self.setJsonPath(self.repoPath + "/gitLog.json")
# prettyFormat = "--pretty=format:\'{%n \"commit\": \"%H\",%n \"tree\": \"%T\",%n \"parent\": \"%P\",%n \"commit_notes\": \"%N\",%n \"author\": {%n \"name\": \"%aN\",%n \"email\": \"%aE\",%n \"date\": \"%aD\"%n },%n \"commiter\": {%n \"name\": \"%cN\",%n \"email\": \"%cE\",%n \"date\": \"%cD\"%n }%n},\'| sed \"$ s/,$//\""
prettyFormat = "--pretty=format:\'{%n \"commit\": \"%H\",%n \"tree\": \"%T\",%n \"parent\": \"%P\",%n \"author\": {%n \"name\": \"%aN\",%n \"email\": \"%aE\",%n \"date\": \"%aD\"%n },%n \"commiter\": {%n \"name\": \"%cN\",%n \"email\": \"%cE\",%n \"date\": \"%cD\"%n }%n},\'| sed \"$ s/,$//\""
os.system('git -C ' + self.repoPath + ' log ' + prettyFormat + " >" + self.jsonPath)
'Read json file and return commit list'
def jsonToCommit(self) -> list:
with open(self.jsonPath, errors="ignore") as f:
print(self.jsonPath)
data = json.loads("[" + f.read() + "]")
commits = []
for each in data:
commits.append(Commit(each))
return commits
'write recipe in json format'
def writeRecipe(self, lists:List[List[str]], path):
recipe = {}
recipe["forcedClusters"] = []
for each in lists:
recipe["forcedClusters"].append(each)
with open(path, 'w') as output:
json.dump(recipe, output)