|
|
@ -7,7 +7,9 @@ |
|
|
|
import json |
|
|
|
import os |
|
|
|
import datetime |
|
|
|
import re |
|
|
|
import subprocess |
|
|
|
import traceback |
|
|
|
|
|
|
|
import yaml |
|
|
|
|
|
|
@ -22,6 +24,11 @@ PROGRAM_NAME = "install_workspace" |
|
|
|
CONFIG_FORMAT = "yml" |
|
|
|
BASIS_FORMAT = "json" |
|
|
|
|
|
|
|
REPO_NAME = "_name" |
|
|
|
REPO_URL = "url" |
|
|
|
REPO_BRANCH = "_branch" |
|
|
|
|
|
|
|
|
|
|
|
job = None |
|
|
|
# ----------------------------------------------------------------------------------------- |
|
|
|
# Miniimplementierung des Programmeahmens |
|
|
@ -48,6 +55,8 @@ class Logger: |
|
|
|
|
|
|
|
def logInfo(self, text): |
|
|
|
self.logfile.write(text + "\n") |
|
|
|
def setMsg(self, text): |
|
|
|
self.logfile.write(text + "\n") |
|
|
|
def logError(self, text): |
|
|
|
self.logfile.write("ERROR:" + text + "\n") |
|
|
|
print("ERROR:" + text) |
|
|
@ -66,6 +75,8 @@ class ActJob: |
|
|
|
self.program = program |
|
|
|
self.start = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") |
|
|
|
self.jobid = 100000 |
|
|
|
self.conf = {} |
|
|
|
self.par = {} |
|
|
|
|
|
|
|
def startJob(self): |
|
|
|
self.m = Logger(self, "info", self.start, None) # job, level, logTime, componente |
|
|
@ -80,10 +91,17 @@ class ActJob: |
|
|
|
self.m.closeLog() |
|
|
|
print(text) |
|
|
|
|
|
|
|
def getDebugLevel(self, tool): |
|
|
|
return 0 |
|
|
|
|
|
|
|
def debug(self, verify, text): |
|
|
|
self.m.logInfo(text) |
|
|
|
|
|
|
|
def setParameter(self, args): |
|
|
|
for k in args: |
|
|
|
setattr(self, k, args[k]) |
|
|
|
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------------------- |
|
|
|
# Standardsteuerung Hauptverarbeitung |
|
|
|
def startPyJob(job): |
|
|
@ -99,8 +117,13 @@ def startPyJob(job): |
|
|
|
createFolders(job) |
|
|
|
createGit(job) |
|
|
|
createBasisConfig(job) |
|
|
|
createDb(job) |
|
|
|
except Exception as e: |
|
|
|
job.m.logError("+++++++++++++++++++++++++++++++++++++++++++++") |
|
|
|
job.m.logError(str(e)) |
|
|
|
job.m.logError("+++++++++++++++++++++++++++++++++++++++++++++") |
|
|
|
job.m.logError("execpt "+traceback.format_exc()) |
|
|
|
job.m.logError("+++++++++++++++++++++++++++++++++++++++++++++") |
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------------------- |
|
|
|
# konkrete Verarbeitungsroutinen |
|
|
@ -125,6 +148,10 @@ def readConfig(job): |
|
|
|
file.close() |
|
|
|
for k in doc: |
|
|
|
args[k] = doc[k] |
|
|
|
job.conf[k] = doc[k] |
|
|
|
home = getHome() |
|
|
|
for k in job.conf["paths"]: |
|
|
|
job.conf["paths"][k] = os.path.join(home, job.conf["paths"][k]) |
|
|
|
job.setParameter(args) |
|
|
|
|
|
|
|
def createFolders(job): |
|
|
@ -142,13 +169,17 @@ def createFolder(job, path): |
|
|
|
else: |
|
|
|
job.m.logInfo("Verzeichnis existiert: " + path) |
|
|
|
|
|
|
|
# -------------------------------------------------------------------------------------- |
|
|
|
# git_tool |
|
|
|
# -------------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
def createGit(job): |
|
|
|
job.m.logInfo("--- erstelle und aktualisiere git-Repos ") |
|
|
|
repos = {} |
|
|
|
local = {} |
|
|
|
attr = { |
|
|
|
"_name": "", |
|
|
|
"_branch": "" |
|
|
|
REPO_NAME: "", |
|
|
|
REPO_BRANCH: "" |
|
|
|
} |
|
|
|
# erstelle Repoliste mit den Attributen: name, branch, url |
|
|
|
for r in job.repos: |
|
|
@ -160,7 +191,7 @@ def createGit(job): |
|
|
|
repo[a] = job.repos[r][a] |
|
|
|
repos[r] = repo |
|
|
|
for k in attr: |
|
|
|
a = k[1:] |
|
|
|
a = k |
|
|
|
for r in repos: |
|
|
|
if a not in repos[r]: |
|
|
|
repos[r][a] = attr[k] |
|
|
@ -168,9 +199,10 @@ def createGit(job): |
|
|
|
repo = repos[r] |
|
|
|
path = os.path.join(job.home, job.paths[r]) |
|
|
|
if os.path.exists(path): |
|
|
|
local["url"] = os.path.join(job.home, job.paths[r]) |
|
|
|
local["branch"] = repo["branch"] |
|
|
|
rpath = os.path.join(local["url"], ".git") |
|
|
|
local[REPO_URL] = os.path.join(job.home, job.paths[r]) |
|
|
|
local[REPO_BRANCH] = repo[REPO_BRANCH] |
|
|
|
local[REPO_NAME] = repo[REPO_NAME] |
|
|
|
rpath = os.path.join(local[REPO_URL], ".git") |
|
|
|
if os.path.exists(rpath): |
|
|
|
job.m.logInfo("Repo existiert bereits "+r) |
|
|
|
else: |
|
|
@ -182,42 +214,52 @@ def createGit(job): |
|
|
|
|
|
|
|
def initGit(job, local, repo, bare=False): |
|
|
|
job.m.logInfo("--- initialisiere git-Repo "+str(repo)+","+str(local)) |
|
|
|
os.chdir(local["url"]) |
|
|
|
os.chdir(local[REPO_URL]) |
|
|
|
cmd = "git init " |
|
|
|
if bare: |
|
|
|
cmd += " --bare" |
|
|
|
execCmd(job, cmd) |
|
|
|
cmd = "git checkout " + local["branch"] |
|
|
|
cmd = "git checkout " + local[REPO_BRANCH] |
|
|
|
execCmd(job, cmd) |
|
|
|
cmd = "git remote add " + repo["name"] + " " + repo["url"] |
|
|
|
cmd = "git remote add " + repo[REPO_NAME] + " " + repo[REPO_URL] |
|
|
|
execCmd(job, cmd) |
|
|
|
os.chdir(job.home) |
|
|
|
|
|
|
|
def execCmd(job, cmd): |
|
|
|
job.m.logInfo(cmd) |
|
|
|
text = "" |
|
|
|
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) |
|
|
|
btext = process.communicate()[0] |
|
|
|
text = btext.decode('utf-8') |
|
|
|
job.m.logInfo(text) |
|
|
|
return text |
|
|
|
|
|
|
|
def switchLocal(job, local): |
|
|
|
os.chdir(local["url"]) |
|
|
|
cmd = "git checkout " + local["branch"] |
|
|
|
execCmd(job, cmd) |
|
|
|
def checkoutLocal(job, local): |
|
|
|
os.chdir(local[REPO_URL]) |
|
|
|
cmd = "git checkout " + local[REPO_BRANCH] |
|
|
|
text = execCmd(job, cmd) |
|
|
|
return text |
|
|
|
|
|
|
|
def updateLocal(job, local, repo): |
|
|
|
job.m.logInfo("--- aktualisiere git-Repo "+str(repo)+","+str(local)) |
|
|
|
switchLocal(job, local) |
|
|
|
cmd = "git pull " + repo["name"] + " " + repo["branch"] |
|
|
|
execCmd(job, cmd) |
|
|
|
text = checkoutLocal(job, local) |
|
|
|
# if len(text) > 0 and re.match(r"[MA]\s\w+", text): |
|
|
|
match = re.search(r"([DMA])\s(\S+)", text) |
|
|
|
if match is not None: |
|
|
|
os.chdir(job.home) |
|
|
|
job.m.logError("ERROR: lokales Repo " + local[REPO_URL] + ", " + local[REPO_BRANCH] + " hat uncommited Aenderungen") |
|
|
|
print("regex gefunden") |
|
|
|
return |
|
|
|
cmd = "git pull " + repo[REPO_NAME] + " " + repo[REPO_BRANCH] |
|
|
|
text = execCmd(job, cmd) |
|
|
|
job.m.logInfo(text) |
|
|
|
os.chdir(job.home) |
|
|
|
|
|
|
|
def updateRemote(job, local, repo): |
|
|
|
job.m.logInfo("--- aktualisiere git-Repo "+str(repo)+","+str(local)) |
|
|
|
switchLocal(job, local) |
|
|
|
cmd = "git push " + repo["name"] + " " + repo["branch"] |
|
|
|
execCmd(job, cmd) |
|
|
|
text = checkoutLocal(job, local) |
|
|
|
cmd = "git push " + repo[REPO_NAME] + " " + repo[REPO_BRANCH] |
|
|
|
text = execCmd(job, cmd) |
|
|
|
os.chdir(job.home) |
|
|
|
|
|
|
|
def createBasisConfig(job): |
|
|
@ -246,6 +288,13 @@ def createBasisConfig(job): |
|
|
|
file.write(doc) |
|
|
|
file.close() |
|
|
|
|
|
|
|
def createDb(job): |
|
|
|
if "db" in job.conf: |
|
|
|
import basic.connection |
|
|
|
import basic.Testserver |
|
|
|
|
|
|
|
testserver = basic.Testserver.Testserver(job) |
|
|
|
testserver.createDBTables(job) |
|
|
|
|
|
|
|
def getHome(): |
|
|
|
home = os.getcwd() |
|
|
@ -253,6 +302,7 @@ def getHome(): |
|
|
|
home = home[0:-8] |
|
|
|
return home |
|
|
|
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------------------- |
|
|
|
# Pythonstandard Programmaufruf |
|
|
|
# Job-Objekt erzeugen und beenden |
|
|
|