-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitcobyreporthead.py
executable file
·59 lines (49 loc) · 1.34 KB
/
gitcobyreporthead.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os
import re
import subprocess
def cd(thePath):
os.chdir(thePath)
def runAndReturnRETURNCODE(theCmd):
child = subprocess.Popen(theCmd, stdout=subprocess.PIPE)
streamdata = child.communicate()[0]
returncode = child.returncode
print (streamdata)
return returncode
def parseDirAndGenCmd(dirAndVersionFile):
# Current Working DIR
cwd = os.getcwd()
# Open file
theFile = open(dirAndVersionFile, "r")
# Split Columns of one record
regexSplitor = re.compile('[ \t\n\r]+')
# Constants
cdcmd = "cd"
gitcmd = "git"
gitcheckoutcmd = "checkout"
gitforceoption = "-f"
# while Read line by line
for line in theFile.readlines():
data = regexSplitor.split(line)
# CD to there and
targetdir = data[0]
print ("cd to " + targetdir)
cd(targetdir)
# git checkout -f $version
cocmd = []
cocmd.extend([gitcmd, gitcheckoutcmd, gitforceoption])
cocmd.append(data[1])
print (cocmd)
runAndReturnRETURNCODE(cocmd)
# CD back to root
print ("cd to " + cwd)
cd(cwd)
parseDirAndGenCmd(sys.argv[1])
def testCD():
originalcwd = os.getcwd()
cd(os.getcwd() + "/" + "vendor")
print os.getcwd()
cd(originalcwd)
print os.getcwd()