"recess": "/usr/local/bin/recess",
// Path to lessc
"lessc": "/usr/local/bin/lessc",
- // Path to your favourite editor
- "editor": "/usr/bin/vim",
+ // Path to your favourite editor. Set to null to guess it from the System environment.
+ "editor": null,
// Debug level of MDK. 'debug', 'info', 'warning', 'error' or 'critical'.
"debug": "info",
import os
import shutil
import imp
+import subprocess
from lib import git
from lib.command import Command
-from lib.tools import mkdir
+from lib.tools import mkdir, resolveEditor
class DoctorCommand(Command):
print 'Checking dependencies'
+ # Check binaries.
hasErrors = False
- for k in ['git', 'php', 'java', 'recess', 'lessc', 'editor']:
+ for k in ['git', 'php', 'java', 'recess', 'lessc']:
path = self.C.get(k)
if not path or not os.path.isfile(path):
print ' The path to \'%s\' is invalid: %s' % (k, path)
if hasErrors and args.fix:
print ' Please manually fix the paths in your config file'
+ # Check PIP modules.
with open(os.path.join(os.path.dirname(__file__), '..', '..', 'requirements.txt'), 'r') as f:
hasErrors = False
for line in f:
if hasErrors and args.fix:
print ' Try running \'pip -r requirements.txt\' from MDK\'s installation directory'
+ # Checking editor.
+ editor = resolveEditor()
+ if editor:
+ try:
+ # Check if it is callable.
+ proc = subprocess.Popen(editor, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ proc.kill()
+ except OSError:
+ editor = None
+
+ if not editor:
+ print ' Could not resolve the path to your editor'
+ if args.fix:
+ print ' Set $EDITOR, /usr/bin/editor, or use: mdk config set editor [path]'
+
def directories(self, args):
"""Check that the directories are valid"""
This returns the path to the saved file.
"""
+ 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()
- subprocess.call([C.get('editor'), tmpfile.name])
+ subprocess.call([editor, tmpfile.name])
return tmpfile.name
return (proc.returncode, out, err)
+def resolveEditor():
+ """Try to resolve the editor that the user would want to use.
+ This does actually checks if it is executable"""
+ editor = C.get('editor')
+ if not editor:
+ editor = os.environ.get('EDITOR')
+ if not editor:
+ editor = os.environ.get('VISUAL')
+ if not editor and os.path.isfile('/usr/bin/editor'):
+ editor = '/usr/bin/editor'
+ return editor
+
+
def downloadProcessHook(count, size, total):
"""Hook to report the downloading a file using urllib.urlretrieve"""
if count <= 0: