-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_6_gitFlow.py
More file actions
100 lines (82 loc) · 3.6 KB
/
example_6_gitFlow.py
File metadata and controls
100 lines (82 loc) · 3.6 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import subprocess, os, platform, logging
from datetime import datetime
try:
#Python 2.x
import ConfigParser as ConfigParser
except:
#Python 3.x
import configparser as ConfigParser
config = ConfigParser.RawConfigParser(allow_no_value=True)
config.read('settings/settings.ini')
CREATE_NEW_PROCESS_GROUP = 512
class gitController:
def __init__(self, *args, **kwargs):
self.platform = platform.system()
self.preamble = []
self.trailers = []
if self.platform == 'Windows':
self.exe = config.get('git', 'exePath') + ' '
self.preamble.append(self.exe)
self.trailers.append(' & exit')
else:
self.exe = ''
self.projectName = kwargs.get('projectName','')
self.outputPath = config.get('git', 'outputPath') + '/' + self.projectName
self.absoluteOutputPath = os.path.abspath(self.outputPath)
self.branch = kwargs.get('branch','master')
self.deployMessage = kwargs.get('deployMessage','LookML Automated Deployment @' + datetime.now().strftime('%a %y-%m-%d %I:%M%p'))
if not os.path.exists(self.absoluteOutputPath):
os.mkdir(self.absoluteOutputPath,0o777)
if self.projectName:
self.gitDir = ' --git-dir="' + os.path.abspath(config.get('git', 'outputPath') + '/' + self.projectName + '/.git') + '" '
else:
self.gitDir = ' --git-dir="' + os.path.abspath(config.get('git', 'outputPath') + '/.git') + '" '
self.includeGitDir = kwargs.get('includeGitDir', False)
if self.includeGitDir:
preamble.append(self.includeGitDir)
def call(self, command, gitDir=True):
if gitDir:
tmp = ' '.join(self.preamble) + 'git ' + self.gitDir + ' ' + command + ' '.join(self.trailers)
else:
tmp = ' '.join(self.preamble) + 'git ' + command + ' '.join(self.trailers)
# logging.info(tmp)
print(tmp)
# if self.platform == 'Windows':
proc = subprocess.Popen(
tmp
,shell=True
,env=os.environ
,cwd=self.absoluteOutputPath
# ,creationflags=CREATE_NEW_PROCESS_GROUP
# ,stdout=subprocess.PIPE
# ,stderr=subprocess.PIPE
)
# else:
# proc = subprocess.Popen(
# tmp
# ,shell=False
# ,env=os.environ
# ,cwd=self.absoluteOutputPath
# ,stdout=subprocess.PIPE
# ,stderr=subprocess.PIPE
# )
try:
outs, errs = proc.communicate(timeout=15)
except subprocess.TimeoutExpired:
proc.kill()
outs, errs = proc.communicate()
return self
def pull(self):
return self.call(' pull origin ' + self.branch + ' ')
def clone(self, repoLocation):
self.call(' clone ' + repoLocation + ' ' + self.absoluteOutputPath, gitDir=False)
return self.pull()
def add(self):
return self.call(' add .')
def commit(self, message=''):
if message:
return self.call(' commit -m "' + message + ' ' + self.deployMessage + '"')
else:
return self.call(' commit -m "' + self.deployMessage + '"')
def pushRemote(self):
return self.call(' push origin ' + self.branch + ' ')