-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseJob_test.py
More file actions
79 lines (65 loc) · 2.3 KB
/
Copy pathParseJob_test.py
File metadata and controls
79 lines (65 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import xml.etree.cElementTree as et
from Element import Element
from Job_test import Job
import csv
import os
marketingdb_dir_path = 'C:\\Users\\anuch\\Downloads\\pentaho_jobs_and_transformations\\pentaho_jobs_and_transformations\\jobs'
def removePathVariable(path):
finish = path.find('}')
# print(finish)
# print(path[finish+1:len(path)])
return (path[finish+1:len(path)])
def parseJob(file):
print(file)
job=Job()
tree=et.parse(file)
root =tree.getroot()
job.name= root.find("./name").text
for element in root.iter('entry'):
name =element.find('name').text
elementType= element.find('type').text
if elementType == 'JOB':
filename =element.find('filename').text
filename = marketingdb_dir_path + removePathVariable(filename)
subJob= parseJob(filename)
subJob.name = name
subJob.filename =filename
job.appendJobList(subJob)
else:
element = Element(name, elementType)
job.appendTaskList(element)
return job
def printJob(job,tab):
print(f"{job.name}")
for task in job.tasklist:
print(tab + str(task))
for subJob in job.jobList:
print(f"{subJob.name} || { subJob.name}")
printJob(subJob , ("----"+tab))
def writeCSV(job, jobType,parent, mainParent, writer):
#print(f"{job.name}")
writer.writerow([jobType, job.name, parent, mainParent])
for task in job.taskList:
writer.writerow([task.type, task.name, job.name, mainParent])
for subJob in job.jobList:
writeCSV(subJob, "sub-job",job.name, mainParent, writer)
def getFileNames(path):
dir_list = os.listdir(path)
fileNames = []
for name in dir_list:
if name.endswith(".kjb"):
fileNames.append(name)
return fileNames
path = "C:\\Users\\anuch\\Downloads\\pentaho_jobs_and_transformations"
jobList = []
for filename in getFileNames(path):
try:
job = parseJob(path + "\\" + filename)
jobList.append(job)
except Exception as e:
print (e)
with open('job_list_with_hierarchy_trans.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["Type", "JobName", "Parent","MainParentProcess"])
for job in jobList:
writeCSV(job, "ParentJob", "",job.name, writer)