This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
forked from ashutoshshanker/reltools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildInfoGen.py
executable file
·76 lines (65 loc) · 2.22 KB
/
buildInfoGen.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import subprocess
from optparse import OptionParser
from heapq import merge
import sys
import json
SNAP_ROUTE_SRC = '/snaproute/src/'
BUILD_INFO_FILE = 'buildInfo.json'
SRC_INFO_FILE = 'setupInfo.json'
def executeCommand (command) :
out = ''
if type(command) != list:
command = [ command]
for cmd in command:
process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
out,err = process.communicate()
return out
class repo (object):
def __init__ (self, base, repoName):
self.name = repoName
self.base = base
self.repoDir = base + '/snaproute/src/'
def writeRepoInfo (self) :
os.chdir(self.repoDir + self.name)
op = executeCommand('git show')
gitHash = ''
timeStamp = ''
branch = ''
for line in op.split('\n'):
if 'commit' in line.split():
gitHash = line.split()[1]
elif 'Date:' in line.split():
timeStamp = ' '.join(line.split()[1:])
branch = executeCommand('git rev-parse --abbrev-ref HEAD')
repoInfo = {'Name' : self.name,
'Sha1' : gitHash,
'Time' : timeStamp,
'Branch' : branch.rstrip('\n')
}
return repoInfo
if __name__ == '__main__':
repos = []
baseDir = os.getenv('SR_CODE_BASE',None)
if not baseDir:
print 'Environment variable SR_CODE_BASE is not set'
srcFile = baseDir + '/reltools/' + SRC_INFO_FILE
repoPublicList = []
repoPrivateList = []
with open(srcFile) as infoFd:
info = json.load(infoFd)
for rp in info['PublicRepos']:
repoPublicList.append(rp)
with open(srcFile) as infoFd:
info = json.load(infoFd)
for rp in info['PrivateRepos']:
repoPrivateList.append(rp)
repoList = list(set(repoPrivateList + repoPublicList))
for rp in repoList:
if os.path.isdir(baseDir + "/snaproute/src/" + rp):
repos.append(repo(baseDir, rp))
reposInfoList = []
with open(baseDir + "/reltools/" + BUILD_INFO_FILE, 'w') as bldFile:
for rp in repos:
reposInfoList.append(rp.writeRepoInfo())
json.dump(reposInfoList, bldFile, indent=4, separators=(',', ': '), sort_keys=False)