|
|
@ -14,6 +14,7 @@ import utils.file_tool |
|
|
|
import utils.git_tool |
|
|
|
|
|
|
|
TABLE_NAMES = ["application", "ap_project", "ap_component"] |
|
|
|
DEFAULT_SYNC = basic.entity.SYNC_FULL_GIT2DB |
|
|
|
|
|
|
|
def getProjects(job): |
|
|
|
""" |
|
|
@ -101,44 +102,105 @@ def searchApplications(job, projectList, appl): |
|
|
|
appList[app] = appl[B.SUBJECT_APPS][app] |
|
|
|
return appList |
|
|
|
|
|
|
|
def syncApplications(job): |
|
|
|
|
|
|
|
def syncEnitity(job, elem): |
|
|
|
return syncEnitities(job) |
|
|
|
|
|
|
|
def syncEnitities(job): |
|
|
|
""" |
|
|
|
synchronize the configuration with the database |
|
|
|
:param job: |
|
|
|
:return: |
|
|
|
""" |
|
|
|
syncMethod = DEFAULT_SYNC |
|
|
|
if B.SUBJECT_ENTITY in job.conf.confs: |
|
|
|
syncMethod = job.conf.confs["entity"][TABLE_NAMES[0]]["storage"] |
|
|
|
if syncMethod.count("-") < 2: |
|
|
|
return |
|
|
|
fileTime = basic.entity.VAL_ZERO_TIME |
|
|
|
dbTime = basic.entity.VAL_ZERO_TIME |
|
|
|
# get git-commit |
|
|
|
apppath = utils.config_tool.getConfigPath(job, P.KEY_BASIC, B.SUBJECT_APPS, "") |
|
|
|
repopath = apppath[len(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_COMPS]) + 1:] |
|
|
|
gitresult = utils.git_tool.gitLog(job, B.ATTR_PATH_COMPS, repopath, 1) |
|
|
|
if B.TOPIC_NODE_DB in job.conf.confs: |
|
|
|
dbi = basic.toolHandling.getDbTool(job, job.testserver, job.conf.confs[B.TOPIC_NODE_DB][B.ATTR_TYPE]) |
|
|
|
else: |
|
|
|
return "No DB in job-config" |
|
|
|
data = dbi.selectRows(TABLE_NAMES[0], job) |
|
|
|
print(str(gitresult)) |
|
|
|
print(str(data[B.DATA_NODE_DATA])) |
|
|
|
if gitresult[0]["date"] == data[B.DATA_NODE_DATA][0]["updtime"]: |
|
|
|
if "git" in syncMethod: |
|
|
|
apppath = utils.config_tool.getConfigPath(job, P.KEY_BASIC, B.SUBJECT_APPS, "") |
|
|
|
repopath = apppath[len(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_COMPS]) + 1:] |
|
|
|
gitresult = utils.git_tool.gitLog(job, B.ATTR_PATH_COMPS, repopath, 1) |
|
|
|
fileTime = gitresult[0]["date"] |
|
|
|
print(str(gitresult)) |
|
|
|
if "db" in syncMethod: |
|
|
|
if B.TOPIC_NODE_DB in job.conf.confs: |
|
|
|
dbi = basic.toolHandling.getDbTool(job, job.testserver, job.conf.confs[B.TOPIC_NODE_DB][B.ATTR_TYPE]) |
|
|
|
else: |
|
|
|
return "No DB in job-config" |
|
|
|
data = dbi.selectRows(TABLE_NAMES[0], job) |
|
|
|
print(str(data[B.DATA_NODE_DATA])) |
|
|
|
if len(data[B.DATA_NODE_DATA]) > 0: |
|
|
|
dbTime = data[B.DATA_NODE_DATA][0]["updtime"] |
|
|
|
|
|
|
|
if fileTime == dbTime: |
|
|
|
print("gleich") |
|
|
|
if len(gitresult) > 0: |
|
|
|
return |
|
|
|
if len(data[B.DATA_NODE_DATA]) > 0: |
|
|
|
for t in TABLE_NAMES: |
|
|
|
dbi.deleteRows(t, job) |
|
|
|
# insertRows |
|
|
|
# get list of application |
|
|
|
applData = utils.config_tool.getConfig(job, P.KEY_BASIC, B.SUBJECT_APPS) |
|
|
|
elif fileTime < dbTime: |
|
|
|
print("db vorne") |
|
|
|
(appObjects, appDict) = selectEntities(job, dbi) |
|
|
|
print(str(appDict)) |
|
|
|
applPath = utils.config_tool.getConfigPath(job, P.KEY_BASIC, B.SUBJECT_APPS) |
|
|
|
utils.file_tool.writeFileDict(job.m, job, applPath, appDict) |
|
|
|
# |
|
|
|
elif fileTime > dbTime: |
|
|
|
print("git vorne") |
|
|
|
applData = utils.config_tool.getConfig(job, P.KEY_BASIC, B.SUBJECT_APPS) |
|
|
|
insertEntities(job, applData, dbTime, dbi) |
|
|
|
|
|
|
|
for app in applData[B.SUBJECT_APPS]: |
|
|
|
def selectEntities(job, dbi): |
|
|
|
appObjects = [] |
|
|
|
appDict = {} |
|
|
|
appDict[B.SUBJECT_PROJECTS] = {} |
|
|
|
appDict[B.SUBJECT_APPS] = {} |
|
|
|
appData = dbi.selectRows(TABLE_NAMES[0], job) |
|
|
|
projData = dbi.selectRows(TABLE_NAMES[1], job) |
|
|
|
compData = dbi.selectRows(TABLE_NAMES[2], job) |
|
|
|
for row in appData[B.DATA_NODE_DATA]: |
|
|
|
ao = Application(job) |
|
|
|
ao.readEntity(job, app) |
|
|
|
rows = ao.getApplicationRows(job) |
|
|
|
apid = dbi.insertRows(TABLE_NAMES[0], rows, job) |
|
|
|
rows = ao.getAppProjectRows(job, apid) |
|
|
|
dbi.insertRows(TABLE_NAMES[1], rows, job) |
|
|
|
rows = ao.getAppComponentRows(job, apid) |
|
|
|
dbi.insertRows(TABLE_NAMES[2], rows, job) |
|
|
|
ao.setAppRow(row, "") |
|
|
|
appDict[B.SUBJECT_APPS][ao.name] = {} |
|
|
|
for f in job.testserver.conf[B.DATA_NODE_DDL][TABLE_NAMES[0]][B.DATA_NODE_HEADER]: |
|
|
|
if f in basic.entity.ENTITY_FIELDS: |
|
|
|
continue |
|
|
|
appDict[B.SUBJECT_APPS][ao.name][f] = getattr(ao, f) |
|
|
|
apid = ao.apid |
|
|
|
rows = [row for row in projData[B.DATA_NODE_DATA] if row["apid"] == apid] |
|
|
|
ao.setProjRow(rows) |
|
|
|
appDict[B.SUBJECT_APPS][ao.name][B.SUBJECT_PROJECTS] = [] |
|
|
|
for proj in getattr(ao, B.PAR_PROJ): |
|
|
|
appDict[B.SUBJECT_APPS][ao.name][B.SUBJECT_PROJECTS].append(proj) |
|
|
|
if proj in appDict[B.SUBJECT_PROJECTS]: |
|
|
|
appDict[B.SUBJECT_PROJECTS][proj][B.SUBJECT_APPS].append(ao.name) |
|
|
|
continue |
|
|
|
appDict[B.SUBJECT_PROJECTS][proj] = {} |
|
|
|
appDict[B.SUBJECT_PROJECTS][proj][B.SUBJECT_APPS] = [] |
|
|
|
appDict[B.SUBJECT_PROJECTS][proj][B.SUBJECT_APPS].append(ao.name) |
|
|
|
aoproj = getattr(ao, "project")[proj] |
|
|
|
for f in job.testserver.conf[B.DATA_NODE_DDL][TABLE_NAMES[1]][B.DATA_NODE_HEADER]: |
|
|
|
if f in basic.entity.ENTITY_FIELDS + ["approid", "apid"]: |
|
|
|
continue |
|
|
|
appDict[B.SUBJECT_PROJECTS][proj][f] = aoproj[f] |
|
|
|
rows = [row for row in compData[B.DATA_NODE_DATA] if row["apid"] == apid] |
|
|
|
ao.setCompRow(rows) |
|
|
|
appDict[B.SUBJECT_APPS][ao.name][B.SUBJECT_COMPS] = [] |
|
|
|
for comp in getattr(ao, B.PAR_COMP): |
|
|
|
appDict[B.SUBJECT_APPS][ao.name][B.SUBJECT_COMPS].append(comp) |
|
|
|
appObjects.append(ao) |
|
|
|
return appObjects, appDict |
|
|
|
|
|
|
|
def insertEntities(job,applData, dbTime, dbi): |
|
|
|
# insertRows |
|
|
|
# get list of application |
|
|
|
if dbTime != basic.entity.VAL_ZERO_TIME: |
|
|
|
for t in TABLE_NAMES: |
|
|
|
dbi.deleteRows(t, job) |
|
|
|
for app in applData[B.SUBJECT_APPS]: |
|
|
|
ao = Application(job) |
|
|
|
ao.readEntity(job, app) |
|
|
|
ao.insertEntity(dbi) |
|
|
|
|
|
|
|
class Application(basic.entity.Entity): |
|
|
|
table = "application" |
|
|
@ -239,23 +301,42 @@ class Application(basic.entity.Entity): |
|
|
|
dbi = basic.toolHandling.getDbTool(job, job.testserver, job.conf.confs[B.TOPIC_NODE_DB][B.ATTR_TYPE]) |
|
|
|
data = dbi.selectRows(TABLE_NAMES[0], job, "WHERE name = \'"+app+"\' AND actual = "+basic.entity.ENTITY_ACTUAL) |
|
|
|
# main object |
|
|
|
for f in job.testserver.conf[B.DATA_NODE_DDL][TABLE_NAMES[0]][B.DATA_NODE_HEADER]: |
|
|
|
if f == basic.entity.ENTITY_NAME: |
|
|
|
setattr(self, f, app) |
|
|
|
else: |
|
|
|
setattr(self, f, str(data[B.DATA_NODE_DATA][0][f])) |
|
|
|
self.setAppRow(data[B.DATA_NODE_DATA][0], app) |
|
|
|
apid = getattr(self, "apid") |
|
|
|
data = dbi.selectRows(TABLE_NAMES[1], job, "WHERE apid = "+str(apid)) |
|
|
|
self.setProjRow(data[B.DATA_NODE_DATA]) |
|
|
|
data = dbi.selectRows(TABLE_NAMES[2], job, "WHERE apid = " + str(apid)) |
|
|
|
self.setCompRow(data[B.DATA_NODE_DATA]) |
|
|
|
|
|
|
|
def setAppRow(self, row, app): |
|
|
|
for f in self.job.testserver.conf[B.DATA_NODE_DDL][TABLE_NAMES[0]][B.DATA_NODE_HEADER]: |
|
|
|
if f not in row and f == basic.entity.ENTITY_NAME: |
|
|
|
setattr(self, f, app) |
|
|
|
else: |
|
|
|
setattr(self, f, str(row[f])) |
|
|
|
def setProjRow(self, rows): |
|
|
|
project = {} |
|
|
|
for row in data[B.DATA_NODE_DATA]: |
|
|
|
for row in rows: |
|
|
|
project[row["project"]] = row |
|
|
|
setattr(self, "project", project) |
|
|
|
data = dbi.selectRows(TABLE_NAMES[2], job, "WHERE apid = " + str(apid)) |
|
|
|
def setCompRow(self, rows): |
|
|
|
component = [] |
|
|
|
for row in data[B.DATA_NODE_DATA]: |
|
|
|
for row in rows: |
|
|
|
component.append(row["component"]) |
|
|
|
setattr(self, "component", component) |
|
|
|
|
|
|
|
def insertEntity(self, dbi=None): |
|
|
|
job = self.job |
|
|
|
rows = self.getApplicationRows(job) |
|
|
|
apid = dbi.insertRows(TABLE_NAMES[0], rows, job) |
|
|
|
rows = self.getAppProjectRows(job, apid) |
|
|
|
dbi.insertRows(TABLE_NAMES[1], rows, job) |
|
|
|
rows = self.getAppComponentRows(job, apid) |
|
|
|
dbi.insertRows(TABLE_NAMES[2], rows, job) |
|
|
|
|
|
|
|
def writeEntity(self): |
|
|
|
pass |
|
|
|
|
|
|
|
def getSchema(self): |
|
|
|
""" |
|
|
|
ersetzt durch testserver.createDB |
|
|
|