Commit 27f1cd9f76c30f89ae61e700b0ab9bbd4e506a76

Authored by Thiago Franco de Moraes
1 parent 86ab5b3e
Exists in master

readPlist and writePlist are deprecated

invesalius/control.py
... ... @@ -1071,7 +1071,8 @@ class Controller():
1071 1071 if not os.path.isfile(path):
1072 1072 path = os.path.join(inv_paths.USER_RAYCASTING_PRESETS_DIRECTORY,
1073 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 1076 prj.Project().raycasting_preset = preset
1076 1077 # Notify volume
1077 1078 # TODO: Chamar grafico tb!
... ... @@ -1085,7 +1086,8 @@ class Controller():
1085 1086 preset['name'] = preset_name
1086 1087 preset_dir = os.path.join(inv_paths.USER_RAYCASTING_PRESETS_DIRECTORY,
1087 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 1092 def ShowBooleanOpDialog(self):
1091 1093 dlg = dialogs.MaskBooleanDialog(prj.Project().mask_dict)
... ...
invesalius/data/mask.py
... ... @@ -293,14 +293,16 @@ class Mask():
293 293 #plist_filepath = os.path.join(dir_temp, plist_filename)
294 294  
295 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 299 filelist[temp_plist] = plist_filename
299 300  
300 301 return plist_filename
301 302  
302 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 307 self.index = mask['index']
306 308 self.name = mask['name']
... ...
invesalius/data/surface.py
... ... @@ -115,14 +115,16 @@ class Surface():
115 115 plist_filename = filename + u'.plist'
116 116 #plist_filepath = os.path.join(dir_temp, filename + '.plist')
117 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 121 filelist[temp_plist] = plist_filename
121 122  
122 123 return plist_filename
123 124  
124 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 128 dirpath = os.path.abspath(os.path.split(filename)[0])
127 129 self.index = sp['index']
128 130 self.name = sp['name']
... ...
invesalius/data/volume.py
... ... @@ -354,9 +354,11 @@ class Volume():
354 354 color_transfer.RemoveAllPoints()
355 355 color_preset = self.config['CLUT']
356 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 362 r = p['Red']
361 363 g = p['Green']
362 364 b = p['Blue']
... ...
invesalius/presets.py
... ... @@ -129,10 +129,11 @@ class Presets():
129 129 thresh_ct_new = {}
130 130 for name in self.thresh_ct.keys():
131 131 thresh_ct_new[translate_to_en[name]] = self.thresh_ct[name]
132   -
  132 +
133 133 preset['thresh_mri'] = thresh_mri_new
134 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 137 return os.path.split(filename)[1]
137 138  
138 139 def OpenPlist(self, filename):
... ... @@ -154,7 +155,8 @@ class Presets():
154 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 160 thresh_mri = p['thresh_mri'].copy()
159 161 thresh_ct = p['thresh_ct'].copy()
160 162  
... ... @@ -181,7 +183,8 @@ def get_wwwl_presets():
181 183  
182 184  
183 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 188 ncolours = len(preset['Blue'])
186 189 colours = []
187 190 for i in range(ncolours):
... ...
invesalius/project.py
... ... @@ -188,7 +188,8 @@ class Project(metaclass=Singleton):
188 188  
189 189 def SetRaycastPreset(self, label):
190 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 193 Publisher.sendMessage('Set raycasting preset', preset)
193 194  
194 195 def GetMeasuresDict(self):
... ... @@ -252,9 +253,9 @@ class Project(metaclass=Singleton):
252 253 # Saving the measurements
253 254 measurements = self.GetMeasuresDict()
254 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 259 filelist[temp_mplist] = measurements_filename
259 260 project['measurements'] = measurements_filename
260 261  
... ... @@ -263,7 +264,8 @@ class Project(metaclass=Singleton):
263 264  
264 265 # Saving the main plist
265 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 269 filelist[temp_plist] = 'main.plist'
268 270  
269 271 # Compressing and generating the .inv3 file
... ... @@ -298,7 +300,8 @@ class Project(metaclass=Singleton):
298 300 import invesalius.data.surface as srf
299 301 # Opening the main file from invesalius 3 project
300 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 306 format_version = project["format_version"]
304 307 if format_version > const.INVESALIUS_ACTUAL_FORMAT_VERSION:
... ... @@ -350,7 +353,8 @@ class Project(metaclass=Singleton):
350 353 self.measurement_dict = {}
351 354 measures_file = os.path.join(dirpath, project.get("measurements", "measurements.plist"))
352 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 358 for index in measurements:
355 359 if measurements[index]["type"] in (const.DENSITY_ELLIPSE, const.DENSITY_POLYGON):
356 360 measure = ms.DensityMeasurement()
... ... @@ -390,7 +394,10 @@ class Project(metaclass=Singleton):
390 394  
391 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 403 def export_project(self, filename, save_masks=True):
... ...