Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mdk/config-dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions mdk/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down