Skip to content

Commit

Permalink
Merge pull request #211 from DimitriPapadopoulos/transforms
Browse files Browse the repository at this point in the history
Port script to Python 3
  • Loading branch information
sbesson authored Jan 23, 2025
2 parents 39cdaae + fe2cd1e commit aa8feb0
Showing 1 changed file with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

# author: m.t.b.carroll@dundee.ac.uk

import os
import re
from collections import defaultdict
from os import listdir
from re import compile


# note the schemas (in reverse order) and the transforms among them
Expand Down Expand Up @@ -82,7 +82,7 @@ def shortest_path(from_schema, to_schema, min_quality):

# the style of transform file names

name_pattern = compile('^(.+)\-to\-(.+)\.xsl$')
name_pattern = re.compile(r'^(.+)\-to\-(.+)\.xsl$')


# scan the current directory to determine the schemas and transforms
Expand All @@ -92,7 +92,7 @@ def load_transforms():
global schemas
seen = set()

for name in listdir('.'):
for name in os.listdir('.'):
match = name_pattern.match(name)
if match:
from_schema = match.group(1)
Expand Down Expand Up @@ -137,18 +137,18 @@ def load_transforms():

def print_path(to_schema):
(path, min_quality) = best_paths[(from_schema, to_schema)]
print '\t\t\t<target schema="' + to_schema + \
'" quality="' + qualities[min_quality - 1] + '">'
print('\t\t\t<target schema="' + to_schema + \
'" quality="' + qualities[min_quality - 1] + '">')
while len(path) > 1:
print '\t\t\t\t<transform file="' + \
path[0] + '-to-' + path[1] + '.xsl"/>'
print('\t\t\t\t<transform file="' + \
path[0] + '-to-' + path[1] + '.xsl"/>')
path = path[1:]
print '\t\t\t</target>'
print('\t\t\t</target>')


# print in XML all the transforms among the schemas

print """<?xml version = "1.0" encoding = "UTF-8"?>
print("""<?xml version = "1.0" encoding = "UTF-8"?>
<!--
#%L
OME Data Model transforms
Expand Down Expand Up @@ -181,27 +181,27 @@ def print_path(to_schema):
POSSIBILITY OF SUCH DAMAGE.
#L%
-->
"""
""")

print '<ome-transforms current="' + schemas[0] + '">'
print('<ome-transforms current="' + schemas[0] + '">')

for from_schema in schemas:
print '\t<source schema="' + from_schema + '">'
print '\t\t<upgrades>'
print('\t<source schema="' + from_schema + '">')
print('\t\t<upgrades>')
upgrades = True
for to_schema in schemas:
if from_schema < to_schema:
print_path(to_schema)
elif to_schema < from_schema:
if upgrades:
upgrades = False
print '\t\t</upgrades>'
print '\t\t<downgrades>'
print('\t\t</upgrades>')
print('\t\t<downgrades>')
print_path(to_schema)
if upgrades:
print '\t\t</upgrades>'
print '\t\t<downgrades>'
print '\t\t</downgrades>'
print '\t</source>'
print('\t\t</upgrades>')
print('\t\t<downgrades>')
print('\t\t</downgrades>')
print('\t</source>')

print '</ome-transforms>'
print('</ome-transforms>')

0 comments on commit aa8feb0

Please # to comment.