Commits

Rhys ! committed f98548e

now logs executable location problems rather than bailing

Comments (0)

Files changed (1)

itsuki/converter.py

         if closure:
             self.to_con.append(('.js', '.min.js', self.convert_js))
 
+    def _exec_call(self, name, func, *args, **kwargs):
+        try:
+            return func(*args, **kwargs)
+        except OSError, exc:
+            if exc.errno == errno.ENOENT:
+                self.log.error('Cannot find %s executable.' % name)
+                return False
+            else:
+                raise
+
     def convert_shpaml(self, fname, tmpl):
         with open(fname) as f:
             raws = f.read()
         self.log.info('Updated: %s and %s' % (fname, tmpl))
 
     def convert_sass(self, fname, css):
-        subprocess.call(['sass', '-q', '--style', 'compressed', '--update', fname + ':' + css])
-        self.log.info('Updated: %s and %s' % (fname, css))
+        mkdir_p(path.dirname(css))
+        if self._exec_call('Sass', subprocess.call, ['sass', '-q', '--style',
+            'compressed', '--update', fname + ':' + css]) != False:
+
+            self.log.info('Updated: %s and %s' % (fname, css))
 
     def convert_coffee(self, fname, js):
         mkdir_p(path.dirname(js))
-        p = subprocess.Popen(['coffee', '--print', fname], stdout=subprocess.PIPE)
-        out, err = p.communicate()
-        if p.returncode == 0:
-            with open(js, 'w') as f:
-                f.write(out)
-        self.log.info('Updated: %s and %s' % (fname, js))
+        p = self._exec_call('CoffeeScript', subprocess.Popen,
+            ['coffee', '--print', fname], stdout=subprocess.PIPE)
+        if p != False:
+            out, err = p.communicate()
+            if p.returncode == 0:
+                with open(js, 'w') as f:
+                    f.write(out)
+            self.log.info('Updated: %s and %s' % (fname, js))
 
     def convert_js(self, fname, js):
         for outf, infs in self.js_amalgamations.iteritems():
                     for f in infs:
                         args.extend(['--js', f])
                     args.extend(['--create_source_map', outf + '.map', '--js_output_file', outf])
-                    subprocess.call(args)
-                    self.log.info('Updated: %s (amalgamation)' % outf)
+                    if self._exec_call('Java', subprocess.call, args) != False:
+                        self.log.info('Updated: %s (amalgamation)' % outf)
                 return
         mkdir_p(path.dirname(js))
         subprocess.call(['java', '-jar', self.closure_jar, '--js', fname, '--create_source_map', js + '.map', '--js_output_file', js])