text: // Generated by CoffeeScript 2.5.1
  // # `nikita.docker.load`
  
  // Load Docker images.
  
  // ## Options
  
  // * `boot2docker` (boolean)   
  //   Whether to use boot2docker or not, default to false.
  // * `machine` (string)   
  //   Name of the docker-machine, required if using docker-machine.
  // * `input` (string)   
  //   TAR archive file to read from.
  // * `source` (string)   
  //   Alias for the "input" option.
  // * `checksum` (string)   
  //   If provided, will check if attached input archive to checksum already exist,
  //   not native to docker but implemented to get better performance.
  
  // ## Callback parameters
  
  // * `err`   
  //   Error object if any.
  // * `status`   
  //   True if container was loaded.
  // * `stdout`   
  //   Stdout value(s) unless `stdout` option is provided.
  // * `stderr`   
  //   Stderr value(s) unless `stderr` option is provided.
  
  // ## Example
  
  // ```javascript
  // require('nikita')
  // .docker.load({
  //   image: 'nikita/load_test:latest',
  //   machine: machine,
  //   source: source + "/nikita_load.tar"
  // }, function(err, {status}) {
  //   console.log( err ? err.message : 'Container loaded: ' + status);
  // })
  // ```
  
  // ## Source Code
  var docker, string, util;
  
  module.exports = function({options}, callback) {
    var cmd, images, k, ref, v;
    this.log({
      message: "Entering Docker load",
      level: 'DEBUG',
      module: 'nikita/lib/docker/load'
    });
    // Global options
    if (options.docker == null) {
      options.docker = {};
    }
    ref = options.docker;
    for (k in ref) {
      v = ref[k];
      if (options[k] == null) {
        options[k] = v;
      }
    }
    // Validate parameters
    if (options.input == null) {
      options.input = options.source;
    }
    if (options.input == null) {
      return callback(Error('Missing input parameter'));
    }
    cmd = `load -i ${options.input}`;
    // need to records the list of image to see if status is modified or not after load
    // for this we print the existing images as REPOSITORY:TAG:IMAGE
    // parse the result to record images as an array of   {'REPOSITORY:TAG:'= 'IMAGE'}
    images = {};
    delete options.cmd;
    this.log({
      message: 'Storing previous state of image',
      level: 'INFO',
      module: 'nikita/lib/docker/load'
    });
    if (options.checksum == null) {
      this.log({
        message: 'No checksum provided',
        level: 'INFO',
        module: 'nikita/lib/docker/load'
      });
    }
    if (options.checksum) {
      this.log({
        message: `Checksum provided :${options.checksum}`,
        level: 'INFO',
        module: 'nikita/lib/docker/load'
      });
    }
    if (options.checksum == null) {
      options.checksum = '';
    }
    return this.system.execute({
      cmd: docker.wrap(options, " images | grep -v '<none>' | awk '{ print $1\":\"$2\":\"$3 }'")
    }, (err, {stdout}) => {
      var i, image, infos, len, ref1;
      if (err) {
        return callback(err);
      }
      // skip header line, wi skip it here instead of in the grep  to have
      // an array with at least one not empty line
      if (string.lines(stdout).length > 1) {
        ref1 = string.lines(stdout);
        for (i = 0, len = ref1.length; i < len; i++) {
          image = ref1[i];
          image = image.trim();
          if (image !== '') {
            infos = image.split(':');
            if (infos[2] === options.checksum) {
              // if image is here we skip
              this.log({
                message: `Image already exist checksum :${options.checksum}, repo:tag ${`${infos[0]}:${infos[1]}`}`,
                level: 'INFO',
                module: 'nikita/lib/docker/load'
              });
            }
            if (infos[2] === options.checksum) {
              return callback(null, false);
            }
            images[`${infos[0]}:${infos[1]}`] = `${infos[2]}`;
          }
        }
      }
      this.log({
        message: `Start Loading ${options.input} `,
        level: 'INFO',
        module: 'nikita/lib/docker/load'
      });
      this.system.execute({
        cmd: docker.wrap(options, cmd)
      });
      return this.system.execute({
        cmd: docker.wrap(options, 'images | grep -v \'<none>\' | awk \'{ print $1":"$2":"$3 }\'')
      }, function(err, {stdout, stderr}) {
        var j, len1, new_image, new_images, new_k, ref2, status;
        if (err) {
          return callback(err);
        }
        new_images = {};
        status = false;
        this.log({
          message: 'Comparing new images',
          level: 'INFO',
          module: 'nikita/lib/docker/load'
        });
        if (string.lines(stdout).length > 1) {
          ref2 = string.lines(stdout.toString());
          for (j = 0, len1 = ref2.length; j < len1; j++) {
            image = ref2[j];
            if (image !== '') {
              infos = image.split(':');
              new_images[`${infos[0]}:${infos[1]}`] = `${infos[2]}`;
            }
          }
        }
        for (new_k in new_images) {
          new_image = new_images[new_k];
          if (images[new_k] == null) {
            status = true;
            break;
          } else {
            for (k in images) {
              image = images[k];
              if (image !== new_image && new_k === k) {
                status = true;
                this.log({
                  message: 'Identical images',
                  level: 'INFO',
                  module: 'nikita/lib/docker/load'
                });
                break;
              }
            }
          }
        }
        return callback(err, {
          status: status,
          stdout: stdout,
          stderr: stderr
        });
      });
    });
  };
  
  // ## Modules Dependencies
  docker = require('@nikitajs/core/lib/misc/docker');
  
  string = require('@nikitajs/core/lib/misc/string');
  
  util = require('util');
  