Data-Test-Executer Framework speziell zum Test von Datenverarbeitungen mit Datengenerierung, Systemvorbereitungen, Einspielungen, ganzheitlicher diversifizierender Vergleich
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.8 KiB

2 years ago
#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import os
import re
import subprocess
import sys
import basic.toolHandling
import tools.data_const as D
2 years ago
import basic.constants as B
import basic.text_const as T
import tools.date_tool
2 years ago
DEFAULT_CNT_COMMITS = 10
COMMIT_ID = "commit"
COMMIT_AUTHOR = "author"
COMMIT_DATE = "date"
COMMIT_COMMENT = "comment"
REPO_NAME = "name"
REPO_URL = "url"
REPO_BRANCH = "branch"
def execCmd(job, repo, cmd):
"""
executes the command on the repository
:param job:
:param repo:
:param cmd:
:return:
"""
2 years ago
cdpath = ""
if os.path.isdir(repo):
cdpath = repo
elif repo in job.conf[B.SUBJECT_PATH]:
cdpath = job.conf[B.SUBJECT_PATH][repo]
2 years ago
else:
raise Exception(T.EXP_PATH_MISSING, repo)
print("execCmd on " + cdpath + ": " + cmd)
2 years ago
os.chdir(cdpath)
text = ""
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
btext = process.communicate()[0]
text = btext.decode('utf-8')
return text
def gitStatus(job, repo):
text = execCmd(job, repo, "git status")
return text
2 years ago
def gitLog(job, repo, arg="", cnt=DEFAULT_CNT_COMMITS):
"""
extracts the last cnt commits into th structure
:param job:
:param repo:
:param cnt:
:return: [ {commit: "", author: ]
"""
if len(arg) > 1:
arg = " -- "+arg
else:
arg = ""
text = execCmd(job, repo, "git log -n "+str(cnt)+" --pretty=format:\"%H | %cn | %cd | %s\""+arg)
print(text+"\n\n")
2 years ago
logs = []
i = 0
2 years ago
for l in text.split("\n"):
if i == cnt:
break
2 years ago
res = {}
a = l.split("|")
print(str(a))
if len(a) < 2:
continue
2 years ago
res[COMMIT_ID] = a[0].strip()
res[COMMIT_AUTHOR] = a[1].strip()
cdate = utils.date_tool.parseDate(a[2].strip())
res[COMMIT_DATE] = utils.date_tool.getFormatDatetupel(cdate, utils.date_tool.F_TIME_DEFAULT)
2 years ago
res[COMMIT_COMMENT] = a[3].strip()
logs.append(res)
i += 1
2 years ago
print(str(logs))
return logs
2 years ago
def gitCommits(job, repo, arg=""):
if len(arg) > 1:
arg = " -- "+arg
else:
arg = ""
text = execCmd(job, repo, "git log --pretty=format:\"%H | %cn | %cd | %s\""+arg)
2 years ago
print(text)
def checkoutLocal(job, local):
os.chdir(local["url"])
cmd = "git checkout " + local["branch"]
execCmd(job, cmd)
def updateLocal(job, local, repo):
job.m.logInfo("--- aktualisiere git-Repo "+str(repo)+","+str(local))
checkoutLocal(job, local)
cmd = "git pull " + repo["name"] + " " + repo["branch"]
execCmd(job, cmd)
os.chdir(job.home)
def updateRemote(job, local, repo):
job.m.logInfo("--- aktualisiere git-Repo "+str(repo)+","+str(local))
checkoutLocal(job, local)
cmd = "git push " + repo["name"] + " " + repo["branch"]
execCmd(job, cmd)
os.chdir(job.home)
2 years ago
def gitPull(job, repo):
if "git" not in job.conf[B.SUBJECT_TOOL] or repo not in job.conf[B.SUBJECT_TOOL]["git"]:
2 years ago
raise Exception(T.EXP_CONFIG_MISSING, "tool.git."+repo)
#print(str(job.conf[B.SUBJECT_TOOL]["git"][repo]))
master = job.conf[B.SUBJECT_TOOL]["git"][repo]["master"]
remote = job.conf[B.SUBJECT_TOOL]["git"][repo]["remote"]
text = execCmd(job, repo, "git status")
2 years ago
if "Commit vor" in text:
print("Das Repository "+repo+" bitte zuerst pushen \n")
#print(text+"\"-------------------------------------\n")
else:
2 years ago
print("Repository "+repo+" kann gepullt werden.")
#execCmd(job, repo, "git pull "+remote+" "+master)