diff --git a/mdk/config-dist.json b/mdk/config-dist.json index 9e426b06..e1a608b8 100644 --- a/mdk/config-dist.json +++ b/mdk/config-dist.json @@ -20,7 +20,9 @@ // A directory used by MDK to store different kind of things such as scripts and backups. "moodle": "~/.moodle-sdk", // Used for cached repositories and stuff which could be shared system-wide. - "mdk": "~/.moodle-sdk" + "mdk": "~/.moodle-sdk", + // Used for temporary files (e.g. editor). + "tmpdir": "~/.moodle-sdk/tmp" }, // List of remotes to work with diff --git a/mdk/tools.py b/mdk/tools.py index e2771133..4a851633 100644 --- a/mdk/tools.py +++ b/mdk/tools.py @@ -109,10 +109,14 @@ def launchEditor(filepath=None, suffix='.tmp'): editor = resolveEditor() if not editor: raise Exception('Could not locate the editor') - with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as tmpfile: - with open(filepath, 'r') as f: - tmpfile.write(f.read()) - tmpfile.flush() + tempdir = os.path.expanduser(C.get('dirs.tmpdir')) + if not os.path.exists(tempdir): + mkdir(tempdir) + with tempfile.NamedTemporaryFile(suffix=suffix, delete=False, dir=tempdir) as tmpfile: + if filepath: + with open(filepath, 'r') as f: + tmpfile.write(f.read()) + tmpfile.flush() subprocess.call([editor, tmpfile.name]) return tmpfile.name