<commit_before>'use strict';

// Intrinsic modules.
var url = require('url');
var fs = require('fs');
var path = require('path');

// NPM modules
var Promise = require('bluebird');
var _ = require('lodash');

// "Constants"
var PLUGIN_NAME = 'kalabox-plugin-pantheon';

module.exports = function(kbox) {

  kbox.whenApp(function(app) {

    // Grab the terminus client
    var Terminus = require('./terminus.js');
    var terminus = new Terminus(kbox, app);

    // Grab delegated helpers
    var pathToRoot = path.resolve(__dirname, '..', '..', '..');
    var pathToNode = path.join(pathToRoot, 'node_modules');
    var Git = require(pathToNode + '/kalabox-plugin-git/lib/git.js');
    var git = new Git(kbox, app);
    var Rsync = require(pathToNode + '/kalabox-plugin-rsync/lib/rsync.js');
    var rsync = new Rsync(kbox, app);

    // Grab some kalabox modules
    var events = kbox.core.events;
    var engine = kbox.engine;

    // Nobody expects the Spanish Inquisition!
    var inquirer = require('inquirer');

    /*
     * Pull down our sites code
     */
    var pullCode = function(site, env, type) {

      // the pantheon site UUID
      var siteid = null;
      var repo = null;

      // Check to see what our connection mode is
      return terminus.getConnectionMode(site, env)
        // Set the connection mode to git if needed
        // and then try again
        .then(function(connectionMode) {
          var modeSplit = connectionMode.split(':');
          var mode = modeSplit[1].trim().toLowerCase();
          if (mode !== 'git') {
            // @todo: actually test this part
            return terminus.setConnectionMode(site, env)
              .then(function(data) {
                pullCode(site, env);
              });
          }
        })
        // Grab the sites UUID from teh machinename
        .then(function() {
          return terminus.getUUID(site)
            .then(function(uuid) {
              siteid = uuid.trim();
            });
        })
        // Generate our code repo URL and CUT THAT MEAT!
        // errr PULL THAT CODE!
        .then(function() {
          // @todo: better way to generate this?
          // @todo: is 'dev' the only thing that
          var build = {
            protocol: 'ssh',<commit_msg>Added code to handle a specific case where terminus UUID is returned with a warning about a newer version of terminus being available.<commit_after>'use strict';

// Intrinsic modules.
var url = require('url');
var fs = require('fs');
var path = require('path');

// NPM modules
var Promise = require('bluebird');
var _ = require('lodash');

// "Constants"
var PLUGIN_NAME = 'kalabox-plugin-pantheon';

module.exports = function(kbox) {

  kbox.whenApp(function(app) {

    // Grab the terminus client
    var Terminus = require('./terminus.js');
    var terminus = new Terminus(kbox, app);

    // Grab delegated helpers
    var pathToRoot = path.resolve(__dirname, '..', '..', '..');
    var pathToNode = path.join(pathToRoot, 'node_modules');
    var Git = require(pathToNode + '/kalabox-plugin-git/lib/git.js');
    var git = new Git(kbox, app);
    var Rsync = require(pathToNode + '/kalabox-plugin-rsync/lib/rsync.js');
    var rsync = new Rsync(kbox, app);

    // Grab some kalabox modules
    var events = kbox.core.events;
    var engine = kbox.engine;

    // Nobody expects the Spanish Inquisition!
    var inquirer = require('inquirer');

    /*
     * Pull down our sites code
     */
    var pullCode = function(site, env, type) {

      // the pantheon site UUID
      var siteid = null;
      var repo = null;

      // Check to see what our connection mode is
      return terminus.getConnectionMode(site, env)
        // Set the connection mode to git if needed
        // and then try again
        .then(function(connectionMode) {
          var modeSplit = connectionMode.split(':');
          var mode = modeSplit[1].trim().toLowerCase();
          if (mode !== 'git') {
            // @todo: actually test this part
            return terminus.setConnectionMode(site, env)
              .then(function(data) {
                pullCode(site, env);
              });
          }
        })
        // Grab the sites UUID from teh machinename
        .then(function() {
          return terminus.getUUID(site)
            .then(function(uuid) {
              /*
               * bcauldwell: Sometimes terminus won't just return a UUID,
               * sometimes it can be a warning about a newer version of
               * terminus and then the UUID separated by a comma.
               */
              // Split uuid by commas and clean up parts with a trim.
              var parts = _.map(uuid.split(','), function(part) {
                return part.trim();
              });
              if (parts.length === 1) {
                // Default case where just uuid is returned.
                siteid = parts[0];
              } else if (parts.length === 2 &&
                _.startsWith(parts[0]), 'Warning:') {
                // Case where a warning is provided, such as newer version
                // being available etc...
                sideid = parts[1];
              } else {
                // Unexpected condition.
                throw new Error('Unexpected terminus UUID: [' + uuid + ']');
              }
            });
        })
        // Generate our code repo URL and CUT THAT MEAT!
        // errr PULL THAT CODE!
        .then(function() {
          // @todo: better way to generate this?
          // @todo: is 'dev' the only thing that
          var build = {
            protocol: 'ssh',
{'fraction_non_alphanumeric': 0.12166013537584609, 'fraction_numerical': 0.0012468827930174563, 'mean_word_length': 1.8973168214654283, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5317361', 'n_tokens_mistral': 1622, 'n_tokens_neox': 1571, 'n_words': 492}