-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcipy.py
executable file
·95 lines (80 loc) · 2.38 KB
/
cipy.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python
import git, os, shutil, sys, yaml
def main():
execGitIfNeeded()
openPipelineFile()
def execGitIfNeeded():
if hasArgs(2):
if not os.path.exists('repo'):
gitclone()
else:
repo = git.Repo('repo')
print('remote url: ' + repo.remotes.origin.url)
if getRepoUrl() == repo.remotes.origin.url:
gitfech(repo)
else:
shutil.rmtree('repo')
gitclone()
def gitclone():
repo = git.Repo.clone_from(getRepoUrl(), 'repo', branch='master')
gitfech(repo)
def gitfech(repo):
print('Fetching repository: ' + getRepoUrl())
for remote in repo.remotes:
remote.fetch()
def getRepoUrl():
if hasArgs(2):
return sys.argv[2]
return ""
def getFolder():
if hasArgs(2):
return "repo"
return "."
def getPipelineName():
if hasArgs():
return sys.argv[1]
return "all"
def hasArgs(numArgs=1):
return len(sys.argv) > numArgs
def openPipelineFile():
with open(getFolder() + '/pipeline.yml', 'r') as stream:
try:
ppyml = yaml.load(stream)
tasks = ppyml['tasks']
pipelines = ppyml['pipelines']
if pipelineWasChoosen(pipelines):
choosenPipeline = pipelines[getPipelineName()]
runPipeline(choosenPipeline, tasks)
else:
runAllPipelines(pipelines, tasks)
except yaml.YAMLError as exc:
print(exc)
def pipelineWasChoosen(pipelines):
return getPipelineName() in pipelines
def runAllPipelines(pipelines, tasks):
for pipeline in(pipelines):
runPipeline(pipeline, tasks)
def runPipeline(pipeline, tasks):
print('')
print('-------------------------------------------------------------------------------------')
print('')
print('Running pipeline: ' + pipeline['name'])
print('')
print('-------------------------------------------------------------------------------------')
print('')
for task in(pipeline['tasks']):
print('')
print('-------------------------------------------------------------------------------------')
print('')
print('Running task: ' + task + ': ' + tasks[task] + '. From pipeline: ' + pipeline['name'])
print('')
print('-------------------------------------------------------------------------------------')
print('')
if not runTask(getFolder(), tasks[task]):
exit()
def runTask(repoDir, command):
try:
return os.system('cd ' + repoDir + ' && ' + command) == 0
except:
return False
main()