<commit_before>'use strict';

const chalk = require('chalk');
const exec = require('child_process').exec;
const commandExists = require('command-exists');

const checkDockerVersion = (callback) => {
  const cmd = "docker --version | cut -f3 -d' '";
  const minX = 1;
  const minY = 12;
  const child = exec(cmd);
  // expected output: Docker version 1.12.2, build bb80604
  // after cut: '1.12.2,'
  child.stdout.on('data', (data) => {
    try {
      const version = data.slice(0,-1);
      const versArray = version.split('.');
      const major = parseInt(versArray[0]);
      const minor = parseInt(versArray[1]);
      const micro = parseInt(versArray[2]);
      if (major >= minX && minor >= minY) {
        callback();
      } else {
        console.log(chalk.red(`Please upgrade the version of Docker. We need version higher than ${minX}.${minY}.*.`));
      }
    } catch (e) {
      console.log(chalk.red(e + ' occured when parsing this output: ' + data + ' after calling ' + cmd));
    }
  });
};

const checkDockerIsInstalled = (callback) => {
  commandExists('docker', (err, dockerEsixts) => {
    if(!dockerEsixts) {
      console.log(chalk.red('Command docker is not present on this machine.'));
    }
    commandExists('docker-compose', (err, dockerComposeExists) => {
      if(dockerComposeExists) {
        if (dockerEsixts) {
          checkDockerVersion(() => callback());
        }
      } else {
        console.log(chalk.red('Command docker-compose is not present on this machine.'));
      }
    });
  });
};


module.exports = {
  checkDockerIsInstalled: checkDockerIsInstalled
};<commit_msg>Fixes #6 - check that docker deamon is running.<commit_after>'use strict';

const chalk = require('chalk');
const exec = require('child_process').exec;
const commandExists = require('command-exists');

const checkDockerVersion = (callback) => {
  const cmd = "docker --version | cut -f3 -d' '";
  const minX = 1;
  const minY = 12;
  const child = exec(cmd);
  // expected output: Docker version 1.12.2, build bb80604
  // after cut: '1.12.2,'
  child.stdout.on('data', (data) => {
    try {
      const version = data.slice(0,-1);
      const versArray = version.split('.');
      const major = parseInt(versArray[0]);
      const minor = parseInt(versArray[1]);
      const micro = parseInt(versArray[2]);
      if (major >= minX && minor >= minY) {
        callback();
      } else {
        console.log(chalk.red(`Please upgrade the version of Docker. We need version higher than ${minX}.${minY}.*.`));
      }
    } catch (e) {
      console.log(chalk.red(e + ' occured when parsing this output: ' + data + ' after calling ' + cmd));
    }
  });
};

const checkDockerDeamonRunning = (callback) => {
  const cmd = 'docker ps';
  const child = exec(cmd);
  child.on('exit', (code, _) => {
    if (code !== 0) {
      console.log(chalk.red('Unable to contact the docker deamon. ' +
      'Make sure it\'s running and that your user is in the docker group.'));
    } else {
      callback();
    }
  });
};

const checkDockerIsInstalled = (callback) => {
  commandExists('docker', (err, dockerEsixts) => {
    if(!dockerEsixts) {
      console.log(chalk.red('Command docker is not present on this machine.'));
    }
    commandExists('docker-compose', (err, dockerComposeExists) => {
      if(dockerComposeExists) {
        if (dockerEsixts) {
          checkDockerVersion(() => checkDockerDeamonRunning(() => callback()));
        }
      } else {
        console.log(chalk.red('Command docker-compose is not present on this machine.'));
      }
    });
  });
};


module.exports = {
  checkDockerIsInstalled: checkDockerIsInstalled
};
{'fraction_non_alphanumeric': 0.15900383141762453, 'fraction_numerical': 0.012588943623426382, 'mean_word_length': 2.9513513513513514, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1960364', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1154, 'n_words': 292}