Skip to content
Snippets Groups Projects
Commit e11276c1 authored by carlos's avatar carlos
Browse files

python 3 migration

parent 0e0b70b8
Branches
Tags
No related merge requests found
Showing
with 29 additions and 29 deletions
...@@ -291,7 +291,7 @@ To write additional tests, create a directory under *Utest/*. ...@@ -291,7 +291,7 @@ To write additional tests, create a directory under *Utest/*.
- run the script `makeini.py` with the obligatory option `-f`: Using the - run the script `makeini.py` with the obligatory option `-f`: Using the
aforementioned example the call is: aforementioned example the call is:
```bash ```bash
python makeini.py -f test_case1/inifile.xml python3 makeini.py -f test_case1/inifile.xml
``` ```
The Script is going to create two directories: The Script is going to create two directories:
...@@ -305,7 +305,7 @@ The Script is going to create two directories: ...@@ -305,7 +305,7 @@ The Script is going to create two directories:
Your script has to start with the following lines: Your script has to start with the following lines:
```python ```python
#!/usr/bin/env python #!/usr/bin/env python3
import os import os
import sys import sys
from sys import * from sys import *
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
""" """
Test description Test description
================ ================
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
""" """
Test description Test description
================ ================
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
""" """
Test description Test description
================ ================
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
""" """
Test description Test description
================ ================
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
import os import os
import sys import sys
utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0]))) utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0])))
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
import os import os
import sys import sys
utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0]))) utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0])))
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
import os import os
import sys import sys
utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0]))) utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0])))
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
""" """
Test description Test description
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
import os import os
import sys import sys
utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0]))) utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0])))
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
import os import os
import sys import sys
utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0]))) utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0])))
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
import os import os
import sys import sys
utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0]))) utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0])))
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
import os import os
import sys import sys
utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0]))) utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0])))
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
import os import os
import sys import sys
utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0]))) utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0])))
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
""" """
- 100 peds distributed in a room with 2 exits: - 100 peds distributed in a room with 2 exits:
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
""" """
- 100 peds distributed in a room with 2 exits: - 100 peds distributed in a room with 2 exits:
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
""" """
- 6 peds distributed in a room with 2 exits: - 6 peds distributed in a room with 2 exits:
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
import os import os
import sys import sys
utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0]))) utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0])))
... ...
......
#!/usr/bin/env python #!/usr/bin/env python3
""" """
Test description Test description
================ ================
... ...
......
# help: python makeini.py -h # help: python3 makeini.py -h
import os, sys, glob import os, sys, glob
from shutil import copy2, rmtree, move from shutil import copy2, rmtree, move
import logging, types, argparse import logging, types, argparse
import errno, time import errno, time
from numpy import * from numpy import *
from itertools import product, izip from itertools import product
try: try:
import xml.etree.cElementTree as ET import xml.etree.cElementTree as ET
except ImportError: except ImportError:
...@@ -112,7 +112,7 @@ def get_attribute(node): ...@@ -112,7 +112,7 @@ def get_attribute(node):
text = '' text = ''
values = [] values = []
for node_attrib in node.attrib.keys(): for node_attrib in list(node.attrib.keys()):
if node_attrib in attributes: if node_attrib in attributes:
text = node.attrib[node_attrib] text = node.attrib[node_attrib]
if text: if text:
...@@ -146,7 +146,7 @@ def get_product(root): ...@@ -146,7 +146,7 @@ def get_product(root):
d = get_tag(node) d = get_tag(node)
if isinstance(d, list) or isinstance(d, ndarray): if isinstance(d, list) or isinstance(d, ndarray):
# in case some tags have multiple values # in case some tags have multiple values
if not input_tags.has_key(tag) and len(d) > 1: if tag not in input_tags and len(d) > 1:
# ignore lists with one element (equiv to scalars) # ignore lists with one element (equiv to scalars)
# if tag in tags: # if tag in tags:
input_tags[tag] = d input_tags[tag] = d
...@@ -160,7 +160,7 @@ def get_product(root): ...@@ -160,7 +160,7 @@ def get_product(root):
else: else:
continue continue
result_prod = [dict(izip(input_tags, x)) for x in product(*input_tags.itervalues())] result_prod = [dict(zip(input_tags, x)) for x in product(*iter(input_tags.values()))]
# print "result", result_prod # print "result", result_prod
# raw_input() # raw_input()
return result_prod return result_prod
...@@ -168,7 +168,7 @@ def get_product(root): ...@@ -168,7 +168,7 @@ def get_product(root):
def make_filename(directory, d): def make_filename(directory, d):
name = "%s/inifiles/ini"%directory name = "%s/inifiles/ini"%directory
traj = "../trajectories/traj" #%directory traj = "../trajectories/traj" #%directory
for key, value in d.iteritems(): for key, value in d.items():
if key == "geometry": if key == "geometry":
value = os.path.basename(value) value = os.path.basename(value)
# if key == "num_threads": # if key == "num_threads":
...@@ -193,7 +193,7 @@ def update_attrib_value(root, attr_tag, value): ...@@ -193,7 +193,7 @@ def update_attrib_value(root, attr_tag, value):
# raw_input() # raw_input()
if attr_tag == "location": # e.g. location if attr_tag == "location": # e.g. location
for r in root.iter(): for r in root.iter():
if r.attrib.has_key(attr_tag): if attr_tag in r.attrib:
r.attrib[attr_tag] = str(value) r.attrib[attr_tag] = str(value)
return return
...@@ -201,7 +201,7 @@ def update_attrib_value(root, attr_tag, value): ...@@ -201,7 +201,7 @@ def update_attrib_value(root, attr_tag, value):
cor_tag = attr_tag.split("-")[0] cor_tag = attr_tag.split("-")[0]
for r in root.iter(cor_tag): for r in root.iter(cor_tag):
if r.attrib.has_key(attr): if attr in r.attrib:
r.attrib[attr] = str(value) r.attrib[attr] = str(value)
# ======================================================= # =======================================================
def make_file(masterfile, tree, result): def make_file(masterfile, tree, result):
...@@ -219,7 +219,7 @@ def make_file(masterfile, tree, result): ...@@ -219,7 +219,7 @@ def make_file(masterfile, tree, result):
if not os.path.isfile(newfile): if not os.path.isfile(newfile):
logging.error("make_file: could not create file %s"%newfile) logging.error("make_file: could not create file %s"%newfile)
sys.exit(FAILURE) sys.exit(FAILURE)
for tag, value in item.iteritems(): for tag, value in item.items():
# print "tag: ", tag, "value:", value # print "tag: ", tag, "value:", value
# raw_input() # raw_input()
if tag in attributes_tags: if tag in attributes_tags:
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment