From f7f61bb575a9b9a962f625e3e340f03f7295ba3b Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 19 Feb 2014 18:26:29 -0500 Subject: [PATCH] Make many scripts in src/utils Python 3 compatible. --- src/utils/analyze_source.py | 6 ++++-- src/utils/build_dependencies.py | 5 +++-- src/utils/convert_xsdata.py | 2 +- src/utils/convert_xsdir.py | 2 +- src/utils/eigenfunction_rms.py | 12 ++++++----- src/utils/memory_usage.py | 11 ++++++++--- src/utils/plot_mesh_tally.py | 33 ++++++++++++++++++------------- src/utils/split_nuclide.py | 3 ++- src/utils/statepoint_histogram.py | 3 ++- src/utils/tally_conv.py | 3 ++- 10 files changed, 49 insertions(+), 31 deletions(-) diff --git a/src/utils/analyze_source.py b/src/utils/analyze_source.py index 0209bfd51a..0b044c67d0 100755 --- a/src/utils/analyze_source.py +++ b/src/utils/analyze_source.py @@ -1,4 +1,6 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python + +from __future__ import print_function import sys import os @@ -36,7 +38,7 @@ for sourceFile in source: commentChar = '!' elif ending == 'F90': commentChar = '!' - + for line in open(sourceFile, 'r'): line = line.strip() if line.startswith(commentChar): diff --git a/src/utils/build_dependencies.py b/src/utils/build_dependencies.py index 2a42b07456..7aab269da4 100755 --- a/src/utils/build_dependencies.py +++ b/src/utils/build_dependencies.py @@ -1,4 +1,6 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python + +from __future__ import print_function import glob import re @@ -18,7 +20,6 @@ for src in glob.iglob('*.F90'): if deps: dependencies[module] = sorted(list(deps)) - for module in sorted(dependencies.keys()): for dep in dependencies[module]: print("{0}.o: {1}.o".format(module, dep)) diff --git a/src/utils/convert_xsdata.py b/src/utils/convert_xsdata.py index 215b9256a7..708a196f97 100755 --- a/src/utils/convert_xsdata.py +++ b/src/utils/convert_xsdata.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python import os import sys diff --git a/src/utils/convert_xsdir.py b/src/utils/convert_xsdir.py index edee1a66c7..7e1606fc4c 100755 --- a/src/utils/convert_xsdir.py +++ b/src/utils/convert_xsdir.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python import os import sys diff --git a/src/utils/eigenfunction_rms.py b/src/utils/eigenfunction_rms.py index 568d173f40..44394ae483 100644 --- a/src/utils/eigenfunction_rms.py +++ b/src/utils/eigenfunction_rms.py @@ -1,12 +1,14 @@ -#!/usr/bin/python2 -# Filename: eigenfunction_rms.py +#!/usr/bin/env python + +from __future__ import print_function -# import packages -import statepoint -import numpy as np import os import sys +import numpy as np + +import statepoint + def main(tally_id, score_id, batch_start, batch_end, name): # read in statepoint header data diff --git a/src/utils/memory_usage.py b/src/utils/memory_usage.py index bf3cc1efd7..32655c62c7 100755 --- a/src/utils/memory_usage.py +++ b/src/utils/memory_usage.py @@ -1,7 +1,12 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python -# This script reads a cross_sections.out file, adds up the memory usage for -# each nuclide and S(a,b) table, and displays the total memory usage +""" +This script reads a cross_sections.out file, adds up the memory usage for each +nuclide and S(a,b) table, and displays the total memory usage. + +""" + +from __future__ import print_function import sys import os diff --git a/src/utils/plot_mesh_tally.py b/src/utils/plot_mesh_tally.py index fb5b8cb839..ad51a8bb35 100755 --- a/src/utils/plot_mesh_tally.py +++ b/src/utils/plot_mesh_tally.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python """Python script to plot tally data generated by OpenMC.""" @@ -15,12 +15,16 @@ from statepoint import * if sys.version_info[0] < 3: import Tkinter as tk + import tkFileDialog as filedialog + import tkFont as font + import tkMessageBox as messagebox + import ttk as ttk else: import tkinter as tk -import tkFileDialog -import tkFont -import tkMessageBox -import ttk + import tkinter.filedialog as filedialog + import tkinter.font as font + import tkinter.messagebox as messagebox + import tkinter.ttk as ttk class MeshPlotter(tk.Frame): @@ -111,8 +115,9 @@ class MeshPlotter(tk.Frame): self.scoreBox.bind('<>', self.redraw) # Filter label - font = tkFont.Font(weight='bold') - labelFilters = tk.Label(self.selectFrame, text='Filters:', font=font) + boldfont = font.Font(weight='bold') + labelFilters = tk.Label(self.selectFrame, text='Filters:', + font=boldfont) labelFilters.grid(row=5, column=0, sticky=tk.W) def update(self, event=None): @@ -201,7 +206,7 @@ class MeshPlotter(tk.Frame): # Create spec_list spec_list = [] - for f in selectedTally.filters.values(): + for f in list(selectedTally.filters.values()): if f.type == 'mesh': continue index = self.filterBoxes[f.type].current() @@ -296,8 +301,8 @@ class MeshPlotter(tk.Frame): self.meshTallies.append(itally) if not self.meshTallies: - tkMessageBox.showerror("Invalid StatePoint File", - "File does not contain mesh tallies!") + messagebox.showerror("Invalid StatePoint File", + "File does not contain mesh tallies!") sys.exit(1) @@ -308,16 +313,16 @@ if __name__ == '__main__': # If no filename given as command-line argument, open file dialog if len(sys.argv) < 2: - filename = tkFileDialog.askopenfilename(title='Select statepoint file', - initialdir='.') + filename = filedialog.askopenfilename(title='Select statepoint file', + initialdir='.') else: filename = sys.argv[1] if filename: # Check to make sure file exists if not os.path.isfile(filename): - tkMessageBox.showerror("File not found", - "Could not find regular file: " + filename) + messagebox.showerror("File not found", + "Could not find regular file: " + filename) sys.exit(1) app = MeshPlotter(root, filename) diff --git a/src/utils/split_nuclide.py b/src/utils/split_nuclide.py index 2a816ac69d..d91cf9b777 100755 --- a/src/utils/split_nuclide.py +++ b/src/utils/split_nuclide.py @@ -1,5 +1,6 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python +from __future__ import print_function import sys if len(sys.argv) != 3: diff --git a/src/utils/statepoint_histogram.py b/src/utils/statepoint_histogram.py index 6276fde056..e16d368dfb 100755 --- a/src/utils/statepoint_histogram.py +++ b/src/utils/statepoint_histogram.py @@ -1,5 +1,6 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python +from __future__ import print_function from sys import argv from math import sqrt diff --git a/src/utils/tally_conv.py b/src/utils/tally_conv.py index 99574bbb91..8f60dd2067 100755 --- a/src/utils/tally_conv.py +++ b/src/utils/tally_conv.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python # This program takes OpenMC statepoint binary files and creates a variety of # outputs from them which should provide the user with an idea of the @@ -15,6 +15,7 @@ # fileType, printxs, showImg, and savetoCSV. See the options block for more # information. +from __future__ import print_function from math import sqrt, pow from glob import glob