<commit_before>/*jshint esversion: 6 */

const Docker = require('dockerode');
const DockerEvents = require('docker-events');
const docker = new Docker();
const dockerEmitter = new DockerEvents({docker:docker});


exports.createNetwork = function(name, external) {
    return new Promise((resolve,reject)=>{
      docker.createNetwork({
        Name: name,
        Driver: 'bridge',
        Internal: !external
      })
      .then(()=>{
        resolve();
      });
    })
    .catch(()=>{
      //if the network exists it will fail with Error: socket hang up
      // so lets ignore it.
      resolve();
    });
};<commit_msg>Don't create network if it exists  <commit_after>/*jshint esversion: 6 */

const Docker = require('dockerode');
const DockerEvents = require('docker-events');
const docker = new Docker();
const dockerEmitter = new DockerEvents({docker:docker});


exports.createNetwork = function(name, external) {
    return new Promise((resolve,reject)=>{
      docker.listNetworks()
      .then((nets)=>{
        const matching = nets.filter((itm)=>{ return itm.Name === name;});
        if(matching.length > 0 ) {
          resolve();
        } else {
          docker.createNetwork({
            'Name': name,
            'Driver': 'bridge',
            'Internal': !external
          })
          .then(()=>{
            resolve();
          });
        }

      });
    });
};
{'fraction_non_alphanumeric': 0.1556671449067432, 'fraction_numerical': 0.002152080344332855, 'mean_word_length': 2.410757946210269, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6638543', 'n_tokens_mistral': 412, 'n_tokens_neox': 376, 'n_words': 100}