Skip to content

Commit d518f99

Browse files
committed
move function, increase chunk size
1 parent 8e481fe commit d518f99

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

openmc_plotter/main_window.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ def _openmcReload():
3838
openmc.lib.init(["-c"])
3939
openmc.lib.settings.verbosity = 1
4040

41+
def hash_file(filename):
42+
# return the md5 hash of a file
43+
h = hashlib.md5()
44+
with open(filename,'rb') as file:
45+
chunk = 0
46+
while chunk != b'':
47+
# read 32768 bytes at a time
48+
chunk = file.read(32768)
49+
h.update(chunk)
50+
return h.hexdigest()
51+
4152
class MainWindow(QMainWindow):
4253
def __init__(self,
4354
font=QtGui.QFontMetrics(QtGui.QFont()),
@@ -1068,8 +1079,8 @@ def restoreModelSettings(self):
10681079
model = pickle.load(file)
10691080

10701081
# check if loaded cell/mat ids hash match the pkl file:
1071-
current_mat_xml_hash = self.hash_file('materials.xml')
1072-
current_geom_xml_hash = self.hash_file('geometry.xml')
1082+
current_mat_xml_hash = hash_file('materials.xml')
1083+
current_geom_xml_hash = hash_file('geometry.xml')
10731084
if (current_mat_xml_hash != model.mat_xml_hash) or \
10741085
(current_geom_xml_hash != model.geom_xml_hash):
10751086
# hashes do not match so ignore plot_settings.pkl file
@@ -1200,8 +1211,8 @@ def saveSettings(self):
12001211
self.model.subsequentViews = self.model.subsequentViews[-10:]
12011212

12021213
# get hashes for geometry.xml and material.xml at close
1203-
self.model.mat_xml_hash = self.hash_file('materials.xml')
1204-
self.model.geom_xml_hash = self.hash_file('geometry.xml')
1214+
self.model.mat_xml_hash = hash_file('materials.xml')
1215+
self.model.geom_xml_hash = hash_file('geometry.xml')
12051216

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

1215-
@staticmethod
1216-
def hash_file(filename):
1217-
# return the md5 hash of a file
1218-
h = hashlib.md5()
1219-
with open(filename,'rb') as file:
1220-
chunk = 0
1221-
while chunk != b'':
1222-
# read 1024 bytes at a time
1223-
chunk = file.read(1024)
1224-
h.update(chunk)
1225-
return h.hexdigest()

0 commit comments

Comments
 (0)