<commit_before>class KiteController extends KDController

  _tempOptions   = null
  _tempCallback  = null
  _attempt       = 1
  _notifications =
    default           : "Something went wrong"
    creatingEnv       : "Creating your environment."
    stillCreatingEnv  : "...still busy with setting up your environment."
    creationTookLong  : "...still busy with it, there might be something wrong."
    tookTooLong       : "It seems like we couldn't set up your environment, please click here to try again."
    envCreated        : "Your server, terminal and files are ready, enjoy!"
    notResponding     : "Backend is not responding, trying to fix..."
    checkingServers   : "Checking if servers are back..."
    alive             : "Shared hosting is alive!"

  getKiteKey =(kiteName, correlationName)->
    "~#{kiteName}~#{correlationName}"

  getKite:(kiteName, correlationName)->
    key = getKiteKey kiteName, correlationName
    kite = @kiteInstances[key]
    return kite  if kite?
    kite = @createKite kiteName, correlationName, key
    @kiteInstances[key] = kite
    return kite

  destroyKite:(kite)->
    delete @kiteInstances[kite.kiteKey]

  createKite:(kiteName, correlationName, kiteKey)->
    kite = new Kite { kiteName, correlationName, kiteKey }
    kite.on 'destroy', => @destroyKite kite
    return kite

  # notification = null
  notify = (options = {})->

    # notification.destroy() if notification
    if "string" is typeof options
      options = msg : options

    options.msg      or= _notifications.default
    options.duration or= 3303
    options.cssClass or= ""
    options.click    or= noop

    notification = new KDNotificationView
      title     : "<span></span>#{options.msg}"
      type      : "tray"
      cssClass  : "mini realtime #{options.cssClass}"
      duration  : options.duration
      click     : options.click

  constructor:->

    super

    @kiteIds   = {}
    @status    = no
    @intervals = {}
    @setListeners()
    @kites     = {}
    @channels  = {}

    # new API:
    @kiteInstances = {}


  addKite: (name, channel) ->
    @channels[name] = channel
    @kites[name] = channel
    @emit "channelAdded", channel, name

  deleteKite: (name) ->
    @emit "channelDeleted", @kites[name], name
    delete @kites[name]
    delete @channels[name]

  run:(options = {}, callback)->

    if "string" is typeof options
      command = options
      options = {}

    options.kiteName or= "os"
    options.method   or= "exec"

    vmName = if options.vmName then options.vmName \
             else KD.singletons.vmController.getDefaultVmName()
    options.vmName = vmName

    kite = @getKite options.kiteName, vmName

    if command
      options.withArgs = command
    else
      options.withArgs or= {}

    if KD.logsEnabled
      notify """
              Calling <b>#{options.method}</b> method,
              from <b>#{options.kiteName}</b> kite
             """

    log "Kite Request:", options

    kite.tell options, (err, response)=>
      @parseKiteResponse {err, response}, options, callback

  setListeners:->

    mainController = @getSingleton "mainController"

    @on "CreatingUserEnvironment", =>
      mainView = @getSingleton "mainView"<commit_msg>Unless someone sets the KD.showKiteCalls to true do not show kite call notifications<commit_after>class KiteController extends KDController

  _tempOptions   = null
  _tempCallback  = null
  _attempt       = 1
  _notifications =
    default           : "Something went wrong"
    creatingEnv       : "Creating your environment."
    stillCreatingEnv  : "...still busy with setting up your environment."
    creationTookLong  : "...still busy with it, there might be something wrong."
    tookTooLong       : "It seems like we couldn't set up your environment, please click here to try again."
    envCreated        : "Your server, terminal and files are ready, enjoy!"
    notResponding     : "Backend is not responding, trying to fix..."
    checkingServers   : "Checking if servers are back..."
    alive             : "Shared hosting is alive!"

  getKiteKey =(kiteName, correlationName)->
    "~#{kiteName}~#{correlationName}"

  getKite:(kiteName, correlationName)->
    key = getKiteKey kiteName, correlationName
    kite = @kiteInstances[key]
    return kite  if kite?
    kite = @createKite kiteName, correlationName, key
    @kiteInstances[key] = kite
    return kite

  destroyKite:(kite)->
    delete @kiteInstances[kite.kiteKey]

  createKite:(kiteName, correlationName, kiteKey)->
    kite = new Kite { kiteName, correlationName, kiteKey }
    kite.on 'destroy', => @destroyKite kite
    return kite

  # notification = null
  notify = (options = {})->

    # notification.destroy() if notification
    if "string" is typeof options
      options = msg : options

    options.msg      or= _notifications.default
    options.duration or= 3303
    options.cssClass or= ""
    options.click    or= noop

    notification = new KDNotificationView
      title     : "<span></span>#{options.msg}"
      type      : "tray"
      cssClass  : "mini realtime #{options.cssClass}"
      duration  : options.duration
      click     : options.click

  constructor:->

    super

    @kiteIds   = {}
    @status    = no
    @intervals = {}
    @setListeners()
    @kites     = {}
    @channels  = {}

    # new API:
    @kiteInstances = {}


  addKite: (name, channel) ->
    @channels[name] = channel
    @kites[name] = channel
    @emit "channelAdded", channel, name

  deleteKite: (name) ->
    @emit "channelDeleted", @kites[name], name
    delete @kites[name]
    delete @channels[name]

  run:(options = {}, callback)->

    if "string" is typeof options
      command = options
      options = {}

    options.kiteName or= "os"
    options.method   or= "exec"

    vmName = if options.vmName then options.vmName \
             else KD.singletons.vmController.getDefaultVmName()
    options.vmName = vmName

    kite = @getKite options.kiteName, vmName

    if command
      options.withArgs = command
    else
      options.withArgs or= {}

    if KD.logsEnabled and KD.showKiteCalls
      notify """
              Calling <b>#{options.method}</b> method,
              from <b>#{options.kiteName}</b> kite
             """

    log "Kite Request:", options

    kite.tell options, (err, response)=>
      @parseKiteResponse {err, response}, options, callback

  setListeners:->

    mainController = @getSingleton "mainController"

    @on "CreatingUserEnvironment", =>
      mainView = @getSingleton "mainView"
{'fraction_non_alphanumeric': 0.10754659333944394, 'fraction_numerical': 0.0015276504735716467, 'mean_word_length': 2.6311702717692733, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 41, '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': '5704818', 'n_tokens_mistral': 2022, 'n_tokens_neox': 1933, 'n_words': 543}