Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

azuki-trusty / azk   deb

Repository URL to install this package:

Version: 0.5.1 

/ usr / lib / azk / node_modules / vboxmanage / lib / command.js

// Generated by CoffeeScript 1.6.3
(function() {
  var async, child_process, logsmith, path, stream_buffers,
    __slice = [].slice;

  path = require('path');

  async = require('async');

  logsmith = require('logsmith');

  child_process = require('child_process');

  stream_buffers = require('stream-buffers');

  /*
  	* Executes VBoxManage command. Commands are queued in order to prevent race conditions within VirtualBox.
  	*
  	* @param {string} command
  	* @param {array<string>} args
  	* @param {function(?err, code, output)} callback
  */


  exports.exec = (function() {
    var vboxmanage_path, vboxmanage_queue;
    vboxmanage_path = (function() {
      switch (false) {
        case !process.platform.match(/^win/):
          return path.join(process.env.VBOX_INSTALL_PATH || '', 'VBoxManage.exe');
        case !process.platform.match(/^dar/):
          return '/Applications/VirtualBox.app/Contents/MacOS/VBoxManage';
        default:
          return 'VBoxManage';
      }
    })();
    vboxmanage_queue = async.queue(function(task, callback) {
      return task.run(callback);
    });
    return function() {
      var args, callback, command, task, _i;
      command = arguments[0], args = 3 <= arguments.length ? __slice.call(arguments, 1, _i = arguments.length - 1) : (_i = 1, []), callback = arguments[_i++];
      args = args.filter(function(arg) {
        return arg;
      });
      args = [].concat.apply([], args);
      task = {
        stream: new stream_buffers.WritableStreamBuffer,
        run: function(callback) {
          var child, _ref,
            _this = this;
          logsmith.verbose("exec " + vboxmanage_path + " " + command + " " + (args.join(' ')));
          child = child_process.spawn(vboxmanage_path, [command].concat(args));
          child.stdout.pipe(this.stream);
          child.stderr.pipe(this.stream);
          if ((_ref = logsmith.level) === 'debug' || _ref === 'silly') {
            child.stdout.pipe(process.stdout);
            child.stderr.pipe(process.stderr);
          }
          child.on('error', function(error) {
            return callback(error);
          });
          return child.on('close', function(code) {
            return callback(null, code, _this.stream.getContentsAsString('utf8') || '');
          });
        }
      };
      return vboxmanage_queue.push(task, function(err, code, output) {
        if (err) {
          return callback(err);
        }
        return callback(null, code, output);
      });
    };
  })();

}).call(this);