Commit 27f1cd9f76c30f89ae61e700b0ab9bbd4e506a76
1 parent
86ab5b3e
Exists in
master
readPlist and writePlist are deprecated
Showing
6 changed files
with
39 additions
and
21 deletions
Show diff stats
invesalius/control.py
@@ -1071,7 +1071,8 @@ class Controller(): | @@ -1071,7 +1071,8 @@ class Controller(): | ||
1071 | if not os.path.isfile(path): | 1071 | if not os.path.isfile(path): |
1072 | path = os.path.join(inv_paths.USER_RAYCASTING_PRESETS_DIRECTORY, | 1072 | path = os.path.join(inv_paths.USER_RAYCASTING_PRESETS_DIRECTORY, |
1073 | preset_name+".plist") | 1073 | preset_name+".plist") |
1074 | - preset = plistlib.readPlist(path) | 1074 | + with open(path, 'r+b') as f: |
1075 | + preset = plistlib.load(f, fmt=plistlib.FMT_XML) | ||
1075 | prj.Project().raycasting_preset = preset | 1076 | prj.Project().raycasting_preset = preset |
1076 | # Notify volume | 1077 | # Notify volume |
1077 | # TODO: Chamar grafico tb! | 1078 | # TODO: Chamar grafico tb! |
@@ -1085,7 +1086,8 @@ class Controller(): | @@ -1085,7 +1086,8 @@ class Controller(): | ||
1085 | preset['name'] = preset_name | 1086 | preset['name'] = preset_name |
1086 | preset_dir = os.path.join(inv_paths.USER_RAYCASTING_PRESETS_DIRECTORY, | 1087 | preset_dir = os.path.join(inv_paths.USER_RAYCASTING_PRESETS_DIRECTORY, |
1087 | preset_name + '.plist') | 1088 | preset_name + '.plist') |
1088 | - plistlib.writePlist(preset, preset_dir) | 1089 | + with open(preset_dir, 'w+b') as f: |
1090 | + plistlib.dump(preset, f) | ||
1089 | 1091 | ||
1090 | def ShowBooleanOpDialog(self): | 1092 | def ShowBooleanOpDialog(self): |
1091 | dlg = dialogs.MaskBooleanDialog(prj.Project().mask_dict) | 1093 | dlg = dialogs.MaskBooleanDialog(prj.Project().mask_dict) |
invesalius/data/mask.py
@@ -293,14 +293,16 @@ class Mask(): | @@ -293,14 +293,16 @@ class Mask(): | ||
293 | #plist_filepath = os.path.join(dir_temp, plist_filename) | 293 | #plist_filepath = os.path.join(dir_temp, plist_filename) |
294 | 294 | ||
295 | temp_plist = tempfile.mktemp() | 295 | temp_plist = tempfile.mktemp() |
296 | - plistlib.writePlist(mask, temp_plist) | 296 | + with open(temp_plist, 'w+b') as f: |
297 | + plistlib.dump(mask, f) | ||
297 | 298 | ||
298 | filelist[temp_plist] = plist_filename | 299 | filelist[temp_plist] = plist_filename |
299 | 300 | ||
300 | return plist_filename | 301 | return plist_filename |
301 | 302 | ||
302 | def OpenPList(self, filename): | 303 | def OpenPList(self, filename): |
303 | - mask = plistlib.readPlist(filename) | 304 | + with open(filename, 'r+b') as f: |
305 | + mask = plistlib.load(f, fmt=plistlib.FMT_XML) | ||
304 | 306 | ||
305 | self.index = mask['index'] | 307 | self.index = mask['index'] |
306 | self.name = mask['name'] | 308 | self.name = mask['name'] |
invesalius/data/surface.py
@@ -115,14 +115,16 @@ class Surface(): | @@ -115,14 +115,16 @@ class Surface(): | ||
115 | plist_filename = filename + u'.plist' | 115 | plist_filename = filename + u'.plist' |
116 | #plist_filepath = os.path.join(dir_temp, filename + '.plist') | 116 | #plist_filepath = os.path.join(dir_temp, filename + '.plist') |
117 | temp_plist = tempfile.mktemp() | 117 | temp_plist = tempfile.mktemp() |
118 | - plistlib.writePlist(surface, temp_plist) | 118 | + with open(temp_plist, 'w+b') as f: |
119 | + plistlib.dump(surface, f) | ||
119 | 120 | ||
120 | filelist[temp_plist] = plist_filename | 121 | filelist[temp_plist] = plist_filename |
121 | 122 | ||
122 | return plist_filename | 123 | return plist_filename |
123 | 124 | ||
124 | def OpenPList(self, filename): | 125 | def OpenPList(self, filename): |
125 | - sp = plistlib.readPlist(filename) | 126 | + with open(filename, 'r+b') as f: |
127 | + sp = plistlib.load(f, fmt=plistlib.FMT_XML) | ||
126 | dirpath = os.path.abspath(os.path.split(filename)[0]) | 128 | dirpath = os.path.abspath(os.path.split(filename)[0]) |
127 | self.index = sp['index'] | 129 | self.index = sp['index'] |
128 | self.name = sp['name'] | 130 | self.name = sp['name'] |
invesalius/data/volume.py
@@ -354,9 +354,11 @@ class Volume(): | @@ -354,9 +354,11 @@ class Volume(): | ||
354 | color_transfer.RemoveAllPoints() | 354 | color_transfer.RemoveAllPoints() |
355 | color_preset = self.config['CLUT'] | 355 | color_preset = self.config['CLUT'] |
356 | if color_preset != "No CLUT": | 356 | if color_preset != "No CLUT": |
357 | - p = plistlib.readPlist( | ||
358 | - os.path.join(inv_paths.RAYCASTING_PRESETS_DIRECTORY, | ||
359 | - 'color_list', color_preset + '.plist')) | 357 | + path = os.path.join(inv_paths.RAYCASTING_PRESETS_DIRECTORY, |
358 | + 'color_list', color_preset + '.plist') | ||
359 | + with open(path, 'r+b') as f: | ||
360 | + p = plistlib.load(f, fmt=plistlib.FMT_XML) | ||
361 | + | ||
360 | r = p['Red'] | 362 | r = p['Red'] |
361 | g = p['Green'] | 363 | g = p['Green'] |
362 | b = p['Blue'] | 364 | b = p['Blue'] |
invesalius/presets.py
@@ -129,10 +129,11 @@ class Presets(): | @@ -129,10 +129,11 @@ class Presets(): | ||
129 | thresh_ct_new = {} | 129 | thresh_ct_new = {} |
130 | for name in self.thresh_ct.keys(): | 130 | for name in self.thresh_ct.keys(): |
131 | thresh_ct_new[translate_to_en[name]] = self.thresh_ct[name] | 131 | thresh_ct_new[translate_to_en[name]] = self.thresh_ct[name] |
132 | - | 132 | + |
133 | preset['thresh_mri'] = thresh_mri_new | 133 | preset['thresh_mri'] = thresh_mri_new |
134 | preset['thresh_ct'] = thresh_ct_new | 134 | preset['thresh_ct'] = thresh_ct_new |
135 | - plistlib.writePlist(preset, filename) | 135 | + with open(filename, 'w+b') as f: |
136 | + plistlib.dump(preset, f) | ||
136 | return os.path.split(filename)[1] | 137 | return os.path.split(filename)[1] |
137 | 138 | ||
138 | def OpenPlist(self, filename): | 139 | def OpenPlist(self, filename): |
@@ -154,7 +155,8 @@ class Presets(): | @@ -154,7 +155,8 @@ class Presets(): | ||
154 | "Custom":_("Custom")} | 155 | "Custom":_("Custom")} |
155 | 156 | ||
156 | 157 | ||
157 | - p = plistlib.readPlist(filename) | 158 | + with open(filename, 'r+b') as f: |
159 | + p = plistlib.load(f, fmt=plistlib.FMT_XML) | ||
158 | thresh_mri = p['thresh_mri'].copy() | 160 | thresh_mri = p['thresh_mri'].copy() |
159 | thresh_ct = p['thresh_ct'].copy() | 161 | thresh_ct = p['thresh_ct'].copy() |
160 | 162 | ||
@@ -181,7 +183,8 @@ def get_wwwl_presets(): | @@ -181,7 +183,8 @@ def get_wwwl_presets(): | ||
181 | 183 | ||
182 | 184 | ||
183 | def get_wwwl_preset_colours(pfile): | 185 | def get_wwwl_preset_colours(pfile): |
184 | - preset = plistlib.readPlist(pfile) | 186 | + with open(pfile, 'r+b') as f: |
187 | + preset = plistlib.load(f, fmt=plistlib.FMT_XML) | ||
185 | ncolours = len(preset['Blue']) | 188 | ncolours = len(preset['Blue']) |
186 | colours = [] | 189 | colours = [] |
187 | for i in range(ncolours): | 190 | for i in range(ncolours): |
invesalius/project.py
@@ -188,7 +188,8 @@ class Project(metaclass=Singleton): | @@ -188,7 +188,8 @@ class Project(metaclass=Singleton): | ||
188 | 188 | ||
189 | def SetRaycastPreset(self, label): | 189 | def SetRaycastPreset(self, label): |
190 | path = os.path.join(RAYCASTING_PRESETS_DIRECTORY, label + '.plist') | 190 | path = os.path.join(RAYCASTING_PRESETS_DIRECTORY, label + '.plist') |
191 | - preset = plistlib.readPlist(path) | 191 | + with open(path, 'r+b') as f: |
192 | + preset = plistlib.load(f, fmt=plistlib.FMT_XML) | ||
192 | Publisher.sendMessage('Set raycasting preset', preset) | 193 | Publisher.sendMessage('Set raycasting preset', preset) |
193 | 194 | ||
194 | def GetMeasuresDict(self): | 195 | def GetMeasuresDict(self): |
@@ -252,9 +253,9 @@ class Project(metaclass=Singleton): | @@ -252,9 +253,9 @@ class Project(metaclass=Singleton): | ||
252 | # Saving the measurements | 253 | # Saving the measurements |
253 | measurements = self.GetMeasuresDict() | 254 | measurements = self.GetMeasuresDict() |
254 | measurements_filename = 'measurements.plist' | 255 | measurements_filename = 'measurements.plist' |
255 | - temp_mplist = tempfile.mktemp() | ||
256 | - plistlib.writePlist(measurements, | ||
257 | - temp_mplist) | 256 | + temp_mplist = tempfile.mktemp() |
257 | + with open(temp_mplist, 'w+b') as f: | ||
258 | + plistlib.dump(measurements, f) | ||
258 | filelist[temp_mplist] = measurements_filename | 259 | filelist[temp_mplist] = measurements_filename |
259 | project['measurements'] = measurements_filename | 260 | project['measurements'] = measurements_filename |
260 | 261 | ||
@@ -263,7 +264,8 @@ class Project(metaclass=Singleton): | @@ -263,7 +264,8 @@ class Project(metaclass=Singleton): | ||
263 | 264 | ||
264 | # Saving the main plist | 265 | # Saving the main plist |
265 | temp_plist = tempfile.mktemp() | 266 | temp_plist = tempfile.mktemp() |
266 | - plistlib.writePlist(project, temp_plist) | 267 | + with open(temp_plist, 'w+b') as f: |
268 | + plistlib.dump(project, f) | ||
267 | filelist[temp_plist] = 'main.plist' | 269 | filelist[temp_plist] = 'main.plist' |
268 | 270 | ||
269 | # Compressing and generating the .inv3 file | 271 | # Compressing and generating the .inv3 file |
@@ -298,7 +300,8 @@ class Project(metaclass=Singleton): | @@ -298,7 +300,8 @@ class Project(metaclass=Singleton): | ||
298 | import invesalius.data.surface as srf | 300 | import invesalius.data.surface as srf |
299 | # Opening the main file from invesalius 3 project | 301 | # Opening the main file from invesalius 3 project |
300 | main_plist = os.path.join(dirpath ,'main.plist') | 302 | main_plist = os.path.join(dirpath ,'main.plist') |
301 | - project = plistlib.readPlist(main_plist) | 303 | + with open(main_plist, 'r+b') as f: |
304 | + project = plistlib.load(f, fmt=plistlib.FMT_XML) | ||
302 | 305 | ||
303 | format_version = project["format_version"] | 306 | format_version = project["format_version"] |
304 | if format_version > const.INVESALIUS_ACTUAL_FORMAT_VERSION: | 307 | if format_version > const.INVESALIUS_ACTUAL_FORMAT_VERSION: |
@@ -350,7 +353,8 @@ class Project(metaclass=Singleton): | @@ -350,7 +353,8 @@ class Project(metaclass=Singleton): | ||
350 | self.measurement_dict = {} | 353 | self.measurement_dict = {} |
351 | measures_file = os.path.join(dirpath, project.get("measurements", "measurements.plist")) | 354 | measures_file = os.path.join(dirpath, project.get("measurements", "measurements.plist")) |
352 | if os.path.exists(measures_file): | 355 | if os.path.exists(measures_file): |
353 | - measurements = plistlib.readPlist(measures_file) | 356 | + with open(measures_file, 'r+b') as f: |
357 | + measurements = plistlib.load(f, fmt=plistlib.FMT_XML) | ||
354 | for index in measurements: | 358 | for index in measurements: |
355 | if measurements[index]["type"] in (const.DENSITY_ELLIPSE, const.DENSITY_POLYGON): | 359 | if measurements[index]["type"] in (const.DENSITY_ELLIPSE, const.DENSITY_POLYGON): |
356 | measure = ms.DensityMeasurement() | 360 | measure = ms.DensityMeasurement() |
@@ -390,7 +394,10 @@ class Project(metaclass=Singleton): | @@ -390,7 +394,10 @@ class Project(metaclass=Singleton): | ||
390 | 394 | ||
391 | "matrix": matrix, | 395 | "matrix": matrix, |
392 | } | 396 | } |
393 | - plistlib.writePlist(project, os.path.join(folder, 'main.plist')) | 397 | + |
398 | + path = os.path.join(folder, 'main.plist') | ||
399 | + with open(path, 'w+b') as f: | ||
400 | + plistlib.dump(project, f) | ||
394 | 401 | ||
395 | 402 | ||
396 | def export_project(self, filename, save_masks=True): | 403 | def export_project(self, filename, save_masks=True): |