42
42
43
43
# report the quality of a single transform
44
44
45
+
45
46
def quality (from_schema , to_schema ):
46
47
if from_schema < to_schema :
47
48
return 4
@@ -55,6 +56,7 @@ def quality(from_schema, to_schema):
55
56
56
57
# find the shortest sequence of transforms of sufficient quality
57
58
59
+
58
60
def shortest_path (from_schema , to_schema , min_quality ):
59
61
paths = [[from_schema ]]
60
62
while True :
@@ -68,8 +70,10 @@ def shortest_path(from_schema, to_schema, min_quality):
68
70
for path in paths :
69
71
curr_step = path [- 1 ]
70
72
for next_step in transforms [curr_step ]:
71
- if quality (curr_step , next_step ) >= min_quality and \
72
- next_step not in path :
73
+ if (
74
+ quality (curr_step , next_step ) >= min_quality
75
+ and next_step not in path
76
+ ):
73
77
next_path = list (path )
74
78
next_path .append (next_step )
75
79
next_paths .append (next_path )
@@ -86,6 +90,7 @@ def shortest_path(from_schema, to_schema, min_quality):
86
90
87
91
# scan the current directory to determine the schemas and transforms
88
92
93
+
89
94
def load_transforms ():
90
95
global transforms
91
96
global schemas
@@ -123,8 +128,7 @@ def load_transforms():
123
128
best_paths [(from_schema , to_schema )] = (path , min_quality )
124
129
break
125
130
if not best_paths [(from_schema , to_schema )]:
126
- raise Exception (
127
- 'no path from ' + from_schema + ' to ' + to_schema )
131
+ raise Exception ('no path from ' + from_schema + ' to ' + to_schema )
128
132
129
133
130
134
# name the quality levels of transforms
@@ -134,13 +138,18 @@ def load_transforms():
134
138
135
139
# print in XML a sequence of transforms to the given schema
136
140
141
+
137
142
def print_path (to_schema ):
138
143
(path , min_quality ) = best_paths [(from_schema , to_schema )]
139
- print ('\t \t \t <target schema="' + to_schema + \
140
- '" quality="' + qualities [min_quality - 1 ] + '">' )
144
+ print (
145
+ '\t \t \t <target schema="'
146
+ + to_schema
147
+ + '" quality="'
148
+ + qualities [min_quality - 1 ]
149
+ + '">'
150
+ )
141
151
while len (path ) > 1 :
142
- print ('\t \t \t \t <transform file="' + \
143
- path [0 ] + '-to-' + path [1 ] + '.xsl"/>' )
152
+ print ('\t \t \t \t <transform file="' + path [0 ] + '-to-' + path [1 ] + '.xsl"/>' )
144
153
path = path [1 :]
145
154
print ('\t \t \t </target>' )
146
155
0 commit comments