Logfile skal fjernes og mail skal laves
This commit is contained in:
parent
72483a854a
commit
488370b2e1
@ -1,45 +1,50 @@
|
|||||||
from sqlalchemy import Table, Column, Integer, String,MetaData,select,insert,NVARCHAR
|
from sqlalchemy import Table, Column, Integer, String,MetaData,select,insert,NVARCHAR,TIMESTAMP,and_
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
import datetime
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
|
||||||
|
|
||||||
class LabelHandler:
|
class LabelHandler:
|
||||||
|
|
||||||
def __init__(self,engine) -> None:
|
def __init__(self,engine,engineSource) -> None:
|
||||||
self.engine=engine
|
self.engine=engine
|
||||||
|
self.engineSource=engineSource
|
||||||
|
|
||||||
def getNewReleases(self):
|
def getNewReleases(self):
|
||||||
class PropertyNamesChecked(Base):
|
class LabelsChecked(Base):
|
||||||
__tablename__ = 'PropertyNamesChecked'
|
__tablename__ = 'LabelsChecked'
|
||||||
id = Column(Integer, primary_key=True)
|
id = Column(Integer, primary_key=True)
|
||||||
Project = Column(NVARCHAR(length=100))
|
DW_ID_Label = Column(Integer)
|
||||||
CurrentVersion = Column(NVARCHAR(length=145))
|
DW_ID_Project = Column(Integer)
|
||||||
|
timestamp = Column(TIMESTAMP)
|
||||||
|
|
||||||
Base.metadata.create_all(self.engine)
|
|
||||||
|
|
||||||
|
#LabelsChecked. (self.engine)
|
||||||
|
|
||||||
#Session = sessionmaker(bind=self.engine)
|
|
||||||
session = Session(self.engine, future=True)
|
session = Session(self.engine, future=True)
|
||||||
|
sessionSource = Session(self.engineSource, future=True)
|
||||||
meta = MetaData()
|
meta = MetaData()
|
||||||
meta.reflect(bind=self.engine)
|
meta.reflect(bind=self.engineSource,schema='dpl')
|
||||||
listDeployedLabels=meta.tables['ListDeployedLabels']
|
t_label=meta.tables['dpl.Label']
|
||||||
class ListDeployedLabels(Base):
|
class Label(Base): #biadmin.dpl.[Label]
|
||||||
__table__=listDeployedLabels
|
__table__= t_label
|
||||||
__mapper_args__ = {
|
__mapper_args__ = {
|
||||||
'primary_key':[listDeployedLabels.c.Project]
|
'primary_key':[t_label.c.DW_ID_Label]
|
||||||
}
|
}
|
||||||
|
|
||||||
statement=select(ListDeployedLabels).join(PropertyNamesChecked,PropertyNamesChecked.Project==ListDeployedLabels.Project)
|
# statement=select(ListDeployedLabels).join(PropertyNamesChecked,PropertyNamesChecked.Project==ListDeployedLabels.Project)
|
||||||
|
|
||||||
listOfUncheckedPropertyNames=session.execute(statement).scalars().all()
|
listOfUncheckedPropertyNames=sessionSource.scalars(select(Label).where(Label.isCurrent==True).where(Label.DateDeployed>=datetime.datetime.today()-datetime.timedelta(days=1))).all()
|
||||||
return listOfUncheckedPropertyNames
|
return listOfUncheckedPropertyNames
|
||||||
|
|
||||||
|
|
||||||
def markAsChecked(self):
|
def markAsChecked(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def getLabel(self,listDeployedLabels:Base):
|
def getLabel(self,listDeployedLabels:Base) -> str:
|
||||||
strLabel=""
|
strLabel=""
|
||||||
strLabel=listDeployedLabels.CurrentVersion.split(':')[2].strip()
|
strLabel=listDeployedLabels.Label.split(':')[2].strip()
|
||||||
return strLabel
|
return strLabel
|
||||||
@ -1,26 +1,52 @@
|
|||||||
|
from ast import Continue
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
import urllib
|
import urllib
|
||||||
from LabelHandler import LabelHandler
|
from LabelHandler import LabelHandler
|
||||||
from TfsHandler import TfsHandler
|
from TfsHandler import TfsHandler
|
||||||
|
from jproperties import Properties
|
||||||
|
import datetime
|
||||||
|
|
||||||
server = 'bi-dsa-udv\dsa' # to specify an alternate port
|
server = 'bi-dsa-udv\dsa' # to specify an alternate port
|
||||||
database = 'udv_denker'
|
database = 'udv_denker'
|
||||||
username = 'admindenker'
|
|
||||||
password = 'biadmin#kode4meO9'
|
|
||||||
tfsBasePath=r'F:\Users\admindenker\TFS Workspace'
|
tfsBasePath=r'F:\Users\admindenker\TFS Workspace'
|
||||||
tfPath=r'c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE'
|
tfPath=r'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer'
|
||||||
|
sqlpackage=r'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\130'
|
||||||
|
|
||||||
connection_string = "DRIVER={SQL Server};Database="+database+";SERVER="+server
|
connection_string = "DRIVER={SQL Server};Database="+database+";SERVER="+server
|
||||||
connection_string = urllib.parse.quote_plus(connection_string)
|
connection_string = urllib.parse.quote_plus(connection_string)
|
||||||
connection_string = "mssql+pyodbc:///?odbc_connect=%s" % connection_string
|
connection_string = "mssql+pyodbc:///?odbc_connect=%s" % connection_string
|
||||||
engine = create_engine(connection_string, echo = True)
|
engine = create_engine(connection_string, echo = True)
|
||||||
|
|
||||||
labelHandler = LabelHandler(engine)
|
serverSource = 'bi-dsa-test\dsa' # to specify an alternate port
|
||||||
|
databaseSource = 'biadmin'
|
||||||
|
connection_string_source = "DRIVER={SQL Server};Database="+databaseSource+";SERVER="+serverSource
|
||||||
|
connection_string_source = urllib.parse.quote_plus(connection_string_source)
|
||||||
|
connection_string_source = "mssql+pyodbc:///?odbc_connect=%s" % connection_string_source
|
||||||
|
engineSource = create_engine(connection_string_source, echo = True)
|
||||||
|
|
||||||
|
|
||||||
|
labelHandler = LabelHandler(engine,engineSource)
|
||||||
tfsHandler = TfsHandler(tfPath,tfsBasePath)
|
tfsHandler = TfsHandler(tfPath,tfsBasePath)
|
||||||
newReleases=labelHandler.getNewReleases()
|
newReleases=labelHandler.getNewReleases()
|
||||||
|
|
||||||
for a in newReleases:
|
for a in newReleases:
|
||||||
print(labelHandler.getLabel(a))
|
print(a.Label)
|
||||||
path=tfsHandler.getProjectPath(labelHandler.getLabel(a))
|
failedPackages=tfsHandler.checkLabel(a.Label)
|
||||||
|
if(failedPackages is not None and len(failedPackages)>0):
|
||||||
|
logfile=open(r'f:\packageCheck\\'+str(datetime.datetime.today().year)+str(datetime.datetime.today().month)+str(datetime.datetime.today().day)+'_failedPackeges.txt','a')
|
||||||
|
logfile.write('---------------------------------------------------------------------------------------------------------------\n')
|
||||||
|
logfile.write(str(a.Label)+'\n')
|
||||||
|
logfile.write('Deployed af : ' + str(a.DeployedBy) + '\n')
|
||||||
|
logfile.write('---------------------------------------------------------------------------------------------------------------\n')
|
||||||
|
for packages in failedPackages:
|
||||||
|
logfile.write('File: '+ str(packages[0]) + '\n')
|
||||||
|
logfile.write('PropertyName: ' + str(packages[1]) + '\n')
|
||||||
|
|
||||||
|
logfile.write('---------------------------------------------------------------------------------------------------------------\n')
|
||||||
|
logfile.write('\n')
|
||||||
|
logfile.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print("done")
|
print("done")
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
|
from ast import List
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from os import chdir
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from LabelHandler import LabelHandler
|
||||||
class TfsHandler():
|
class TfsHandler():
|
||||||
def __init__(self,tfPath,tfsBasePath):
|
def __init__(self,tfPath,tfsBasePath):
|
||||||
self.tfPath=Path(tfPath)
|
self.tfPath=Path(tfPath)
|
||||||
@ -8,10 +12,12 @@ class TfsHandler():
|
|||||||
pass
|
pass
|
||||||
def updateRepository(self):
|
def updateRepository(self):
|
||||||
pass
|
pass
|
||||||
def checkFile(self, file):
|
def checkFile(self, file:Path) -> List:
|
||||||
|
fileResult=[]
|
||||||
f=open(file,"r", encoding='utf-8')
|
f=open(file,"r", encoding='utf-8')
|
||||||
for x in f:
|
for x in f:
|
||||||
if(x.find("DTS:ObjectName")>-1):
|
if(x.find("DTS:ObjectName")>-1):
|
||||||
|
fileResult=[file]
|
||||||
propertyNameTokens=x.split('=')
|
propertyNameTokens=x.split('=')
|
||||||
count=0
|
count=0
|
||||||
propertyNameToken=None
|
propertyNameToken=None
|
||||||
@ -22,28 +28,66 @@ class TfsHandler():
|
|||||||
count+=2
|
count+=2
|
||||||
if(propertyNameToken==None):
|
if(propertyNameToken==None):
|
||||||
print(f"propertyNameToken findes ikke i {file.name}")
|
print(f"propertyNameToken findes ikke i {file.name}")
|
||||||
|
fileResult+=['',False]
|
||||||
continue
|
continue
|
||||||
if(file.stem!=propertyNameToken):
|
fileResult+=[propertyNameToken]
|
||||||
ssisproject=[a for a in file.parts if a.find("SSIS_")>-1]
|
if( str.lower(file.stem)!=str.lower(propertyNameToken)):
|
||||||
if(len(ssisproject)>0):
|
fileResult+=[False]
|
||||||
#insertOrUpdateTable(ssisproject[0],str(file.parent),str(file.stem),propertyNameToken)
|
else:
|
||||||
# insertIntoTable(ssisproject[0],str(file.parent),str(file.stem),propertyNameToken)
|
fileResult+=[True]
|
||||||
print(ssisproject[0] + ' ' + str(file.parent) + ' ' + file.stem + ' ' + propertyNameToken)
|
|
||||||
print(x)
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
f.close()
|
f.close()
|
||||||
def updateRepo(self,path):
|
return fileResult
|
||||||
project=''
|
def updateRepo(self,label,path):
|
||||||
|
chdir(path)
|
||||||
|
updateStatus=subprocess.run([str(self.tfPath.joinpath('tf.exe')),"vc","get","/all","/version:L"+label,str(path)],stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True,text=True)
|
||||||
|
if(len(updateStatus.stdout)>0):
|
||||||
|
print("STDOUT:\n" + updateStatus.stdout)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print("STDERR:\n" + updateStatus.stdout)
|
||||||
|
return False
|
||||||
|
|
||||||
def getProjectPath(self,label):
|
def getProjectPath(self,label):
|
||||||
labelInfo=subprocess.run([str(self.tfPath.joinpath('tf.exe')),"vc","labels","/owner:*","/format:detailed",label],stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True,text=True)
|
labelInfo=subprocess.run([str(self.tfPath.joinpath('tf.exe')),"vc","labels","/owner:*","/format:detailed",label],stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True,text=True)
|
||||||
if(len(labelInfo.stdout)>0):
|
if(len(labelInfo.stdout)>0):
|
||||||
relativePath=labelInfo.stdout.split('\n')[9].split('$')[1]
|
print("STDOUT:\n" + labelInfo.stdout)
|
||||||
return self.tfsBasePath.joinpath(relativePath.removeprefix('/'))
|
for a in labelInfo.stdout.split('\n'):
|
||||||
def traverseDirectory(x):
|
if(a.find('$/Datavarehus')!=-1 and a.find('Scope')==-1):
|
||||||
if (x.name=='obj' or x.name.strip()=='DataPresentationArea' or x.name=='FastTrack' or x.name=='Undervisning' or x.name=='Udvikling'):
|
relativePath=a.split('$')[1]
|
||||||
print(x.name)
|
break
|
||||||
return
|
else:
|
||||||
[checkFile(z) for z in x.iterdir() if z.is_file and z.name.endswith('.dtsx')]
|
print("STDERR:\n" + labelInfo.stdout)
|
||||||
[traverseDirectory(y) for y in x.iterdir() if y.is_dir()]
|
return None
|
||||||
|
resPath=self.tfsBasePath.joinpath(relativePath.removeprefix('/'))
|
||||||
|
if(resPath.is_dir() == False):
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return resPath
|
||||||
|
def traverseDirectory(self, x:Path,propertyNameDiffs:List):
|
||||||
|
[print(z) for z in x.iterdir() if z.is_file and z.name]
|
||||||
|
[propertyNameDiffs.append(self.checkFile(z)) for z in x.iterdir() if z.is_file and z.name.endswith('.dtsx')]
|
||||||
|
[self.traverseDirectory(y,propertyNameDiffs) for y in x.iterdir() if y.is_dir() and y.name!='obj']
|
||||||
|
print(propertyNameDiffs)
|
||||||
|
|
||||||
|
def checkLabel(self,label):
|
||||||
|
labelResult=[]
|
||||||
|
if(label[0:4]=='SSIS'):
|
||||||
|
projectPath=self.getProjectPath(label)
|
||||||
|
if projectPath == None:
|
||||||
|
return
|
||||||
|
updated=self.updateRepo(label,projectPath)
|
||||||
|
if(updated==False):
|
||||||
|
return
|
||||||
|
labelResult=self.checkSSISProject(projectPath)
|
||||||
|
return labelResult
|
||||||
|
def checkSSISProject(self, projectPath):
|
||||||
|
labelResult=[]
|
||||||
|
self.traverseDirectory(Path(projectPath),labelResult)
|
||||||
|
failed=[a for a in labelResult if a[-1]==False]
|
||||||
|
return failed
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user