RepositoryAutoCheck/TfsHandler.py
2022-10-27 08:37:53 +02:00

49 lines
2.3 KiB
Python

from pathlib import Path
import subprocess
class TfsHandler():
def __init__(self,tfPath,tfsBasePath):
self.tfPath=Path(tfPath)
self.tfsBasePath=Path(tfsBasePath)
def checkPropertyName(self):
pass
def updateRepository(self):
pass
def checkFile(self, file):
f=open(file,"r", encoding='utf-8')
for x in f:
if(x.find("DTS:ObjectName")>-1):
propertyNameTokens=x.split('=')
count=0
propertyNameToken=None
while count < len(propertyNameTokens):
if(propertyNameTokens[count].find("DTS:ObjectName")>-1):
propertyNameToken=propertyNameTokens[count+1].split('"')[1]
break
count+=2
if(propertyNameToken==None):
print(f"propertyNameToken findes ikke i {file.name}")
continue
if(file.stem!=propertyNameToken):
ssisproject=[a for a in file.parts if a.find("SSIS_")>-1]
if(len(ssisproject)>0):
#insertOrUpdateTable(ssisproject[0],str(file.parent),str(file.stem),propertyNameToken)
# insertIntoTable(ssisproject[0],str(file.parent),str(file.stem),propertyNameToken)
print(ssisproject[0] + ' ' + str(file.parent) + ' ' + file.stem + ' ' + propertyNameToken)
print(x)
break
else:
continue
f.close()
def updateRepo(self,path):
project=''
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)
if(len(labelInfo.stdout)>0):
relativePath=labelInfo.stdout.split('\n')[9].split('$')[1]
return self.tfsBasePath.joinpath(relativePath.removeprefix('/'))
def traverseDirectory(x):
if (x.name=='obj' or x.name.strip()=='DataPresentationArea' or x.name=='FastTrack' or x.name=='Undervisning' or x.name=='Udvikling'):
print(x.name)
return
[checkFile(z) for z in x.iterdir() if z.is_file and z.name.endswith('.dtsx')]
[traverseDirectory(y) for y in x.iterdir() if y.is_dir()]