[pylint] Fix referencing undefined variable 'shutil'
Let's just use the scope limited TemporaryDirectory() instead, so
the temporary directory will be removed by Python automatically.
pySim/filesystem.py:679:16: E0602: Undefined variable 'shutil' (undefined-variable)
Change-Id: I4ea833fd79f4342c33899124379be509ba1e35ed
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index dec521e..edfe85d 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -659,8 +659,7 @@
def do_edit_record_decoded(self, opts):
"""Edit the JSON representation of one record in an editor."""
(orig_json, sw) = self._cmd.rs.read_record_dec(opts.record_nr)
- dirname = tempfile.mkdtemp(prefix='pysim_')
- try:
+ with tempfile.TemporaryDirectory(prefix='pysim_') as dirname:
filename = '%s/file' % dirname
# write existing data as JSON to file
with open(filename, 'w') as text_file:
@@ -675,8 +674,6 @@
(data, sw) = self._cmd.rs.update_record_dec(opts.record_nr, edited_json)
if data:
self._cmd.poutput_json(data)
- finally:
- shutil.rmtree(dirname)
def __init__(self, fid:str, sfid:str=None, name:str=None, desc:str=None,