<commit_before>var util = require('util');
var EventEmitter = require('events').EventEmitter;
var fs = require('fs-extra');
var path = require('path');
var rimraf = require('rimraf');
var forever = require('forever-monitor');
var exec = require('child_process').exec;
var _ = require('lodash');
var async = require('async');
var request = require('request');

var DeviceManager = function(config) {
  var self = this;

  self.refreshDevices = function(devices, callback){
    async.map(devices || [], self.deviceExists, function(error, devices){
      if(error){ return callback(error); }

      devices = _.compact(devices);
      self.emit('update', {devices: devices});
      self.installDevices(devices, callback);
    });
  };

  self.deviceExists = function(device, callback){
    var authHeaders, deviceUrl;

    authHeaders = {skynet_auth_uuid: device.uuid, skynet_auth_token: device.token};
    deviceUrl = 'http://' + config.server + ':' + config.port + '/devices/' + device.uuid;

    request({url: deviceUrl, headers: authHeaders}, function(error, response, body){
      if(error || response.statusCode !== 200){
        return callback(error, null);
      }

      callback(null, device);
    });
  };

  self.installDevices = function(devices, callback) {
    var connectors = _.uniq(_.pluck(devices, 'connector'));

    async.series([
      function(callback){ self.installConnectors(connectors, callback); },
      function(callback){ fs.mkdirp(config.devicePath, callback); },
      function(callback){ async.eachSeries(devices, self.setupAndStartDevice, callback); }
    ], callback);
  };


  self.installConnectors = function(connectors, callback) {
    async.series([
      function(callback) { fs.mkdirp(config.tmpPath, callback); },
      function(callback) { async.each(connectors, self.installConnector, callback); }
    ], callback);
  };

  self.installConnector = function(connector, callback) {
    var cachePath, connectorPath, npmCommand, cmd;<commit_msg>ensure no blank connectors<commit_after>var util = require('util');
var EventEmitter = require('events').EventEmitter;
var fs = require('fs-extra');
var path = require('path');
var rimraf = require('rimraf');
var forever = require('forever-monitor');
var exec = require('child_process').exec;
var _ = require('lodash');
var async = require('async');
var request = require('request');

var DeviceManager = function(config) {
  var self = this;

  self.refreshDevices = function(devices, callback){
    async.map(devices || [], self.deviceExists, function(error, devices){
      if(error){ return callback(error); }

      devices = _.compact(devices);
      self.emit('update', {devices: devices});
      self.installDevices(devices, callback);
    });
  };

  self.deviceExists = function(device, callback){
    var authHeaders, deviceUrl;

    authHeaders = {skynet_auth_uuid: device.uuid, skynet_auth_token: <PASSWORD>.token};
    deviceUrl = 'http://' + config.server + ':' + config.port + '/devices/' + device.uuid;

    request({url: deviceUrl, headers: authHeaders}, function(error, response, body){
      if(error || response.statusCode !== 200){
        return callback(error, null);
      }

      callback(null, device);
    });
  };

  self.installDevices = function(devices, callback) {
    var connectors = _.compact(_.uniq(_.pluck(devices, 'connector')));

    async.series([
      function(callback){ self.installConnectors(connectors, callback); },
      function(callback){ fs.mkdirp(config.devicePath, callback); },
      function(callback){ async.eachSeries(devices, self.setupAndStartDevice, callback); }
    ], callback);
  };


  self.installConnectors = function(connectors, callback) {
    async.series([
      function(callback) { fs.mkdirp(config.tmpPath, callback); },
      function(callback) { async.each(connectors, self.installConnector, callback); }
    ], callback);
  };

  self.installConnector = function(connector, callback) {
    var cachePath, connectorPath, npmCommand, cmd;
{'fraction_non_alphanumeric': 0.15275, 'fraction_numerical': 0.0015, 'mean_word_length': 4.285336856010568, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '5854573', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1128, 'n_words': 248}