Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move function, increase chunk size
  • Loading branch information
kkiesling committed May 26, 2022
commit d518f996d5b08c7c75a1007ae4ea73948e749cfb
30 changes: 15 additions & 15 deletions openmc_plotter/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ def _openmcReload():
openmc.lib.init(["-c"])
openmc.lib.settings.verbosity = 1

def hash_file(filename):
# return the md5 hash of a file
h = hashlib.md5()
with open(filename,'rb') as file:
chunk = 0
while chunk != b'':
# read 32768 bytes at a time
chunk = file.read(32768)
h.update(chunk)
return h.hexdigest()

class MainWindow(QMainWindow):
def __init__(self,
font=QtGui.QFontMetrics(QtGui.QFont()),
Expand Down Expand Up @@ -1068,8 +1079,8 @@ def restoreModelSettings(self):
model = pickle.load(file)

# check if loaded cell/mat ids hash match the pkl file:
current_mat_xml_hash = self.hash_file('materials.xml')
current_geom_xml_hash = self.hash_file('geometry.xml')
current_mat_xml_hash = hash_file('materials.xml')
current_geom_xml_hash = hash_file('geometry.xml')
if (current_mat_xml_hash != model.mat_xml_hash) or \
(current_geom_xml_hash != model.geom_xml_hash):
# hashes do not match so ignore plot_settings.pkl file
Expand Down Expand Up @@ -1200,8 +1211,8 @@ def saveSettings(self):
self.model.subsequentViews = self.model.subsequentViews[-10:]

# get hashes for geometry.xml and material.xml at close
self.model.mat_xml_hash = self.hash_file('materials.xml')
self.model.geom_xml_hash = self.hash_file('geometry.xml')
self.model.mat_xml_hash = hash_file('materials.xml')
self.model.geom_xml_hash = hash_file('geometry.xml')

with open('plot_settings.pkl', 'wb') as file:
if self.model.statepoint:
Expand All @@ -1212,14 +1223,3 @@ def exportTallyData(self):
# show export tool dialog
self.showExportDialog()

@staticmethod
def hash_file(filename):
# return the md5 hash of a file
h = hashlib.md5()
with open(filename,'rb') as file:
chunk = 0
while chunk != b'':
# read 1024 bytes at a time
chunk = file.read(1024)
h.update(chunk)
return h.hexdigest()