Added dependencies check to doctor
authorFrederic Massart <fmcell@gmail.com>
Wed, 2 Apr 2014 16:30:33 +0000 (00:30 +0800)
committerFrederic Massart <fmcell@gmail.com>
Wed, 2 Apr 2014 16:30:33 +0000 (00:30 +0800)
extra/bash_completion
lib/commands/doctor.py

index 1243327..bb2efd4 100644 (file)
@@ -108,7 +108,7 @@ function _mdk() {
                 OPTS="--compile --debug --sheets --theme --watch"
                 ;;
             doctor)
-                OPTS="--all --branch --cached --directories --remotes --wwwroot"
+                OPTS="--all --branch --cached --dependencies --directories --remotes --wwwroot"
                 ;;
             fix)
                 if [[ "$PREV" == "-n" || "$PREV" == "--name" ]]; then
index b41f611..5ac2c55 100644 (file)
@@ -24,6 +24,7 @@ http://github.com/FMCorz/mdk
 
 import os
 import shutil
+import imp
 from lib import git
 from lib.command import Command
 from lib.tools import mkdir
@@ -61,6 +62,13 @@ class DoctorCommand(Command):
             }
         ),
         (
+            ['--dependencies'],
+            {
+                'action': 'store_true',
+                'help': 'Check various dependencies'
+            }
+        ),
+        (
             ['--directories'],
             {
                 'action': 'store_true',
@@ -110,6 +118,10 @@ class DoctorCommand(Command):
         if args.cached or allChecks:
             self.cachedRepositories(args)
 
+        # Check the dependencies
+        if args.dependencies or allChecks:
+            self.dependencies(args)
+
         # Check instances remotes
         if args.remotes or allChecks:
             self.remotes(args)
@@ -192,6 +204,34 @@ class DoctorCommand(Command):
                         print '    Setting remote.origin.fetch to %s' % '+refs/*:refs/*'
                         repo.setConfig('remote.origin.fetch', '+refs/*:refs/*')
 
+    def dependencies(self, args):
+        """Check that various dependencies are met"""
+
+        print 'Checking dependencies'
+
+        hasErrors = False
+        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)
+                hasErrors = True
+        if hasErrors and args.fix:
+            print '    Please manually fix the paths in your config file'
+
+        with open(os.path.join(os.path.dirname(__file__), '..', '..', 'requirements.txt'), 'r') as f:
+            hasErrors = False
+            for line in f:
+                # Striping the version number from the package.
+                # And yes, this is a horrible one liner and I'm not expecting anyone to debug it :D.
+                mod = line[:min([len(line)] + [line.find(v) for v in '<=>' if line.find(v) > -1])].strip()
+                try:
+                    imp.find_module(mod)
+                except ImportError:
+                    print '  Could not locate the module \'%s\'' % (mod)
+                    hasErrors = True
+            if hasErrors and args.fix:
+                print '    Try running \'pip -r requirements.txt\' from MDK\'s installation directory'
+
     def directories(self, args):
         """Check that the directories are valid"""