<commit_before>fs = require 'fs'
path = require 'path'

request = require 'request'

module.exports = (grunt) ->
  {spawn, mkdir, rm, cp} = require('./task-helpers')(grunt)

  getAtomShellVersion = ->
    versionPath = path.join('atom-shell', 'version')
    if grunt.file.isFile(versionPath)
      grunt.file.read(versionPath).trim()
    else
      null

  getCachePath = (version) -> "/tmp/atom-cached-atom-shells/#{version}"

  isAtomShellVersionCached = (version) ->
    grunt.file.isFile(getCachePath(version), 'version')

  downloadAtomShell = (version, callback) ->
    downloadUrl = "https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/#{version}/atom-shell-#{version}-darwin.zip"

    inputStream = request(downloadUrl)
    inputStream.on 'response', (response) ->
      if response.statusCode is 200
        grunt.log.writeln("Downloading atom-shell version #{version.cyan}")
        cacheDirectory = getCachePath(version)
        rm(cacheDirectory)
        mkdir(cacheDirectory)
        cacheFile = path.join(cacheDirectory, 'atom-shell.zip')
        outputStream = fs.createWriteStream(cacheFile)
        outputStream.on 'close', -> callback(null, cacheFile)
        inputStream.pipe(outputStream)
      else
        if response.statusCode is 404
          grunt.log.error("atom-shell #{version.cyan} not found")
        else
          grunt.log.error("atom-shell #{version.cyan} request failed")
        callback(false)

  unzipAtomShell = (zipPath, callback) ->
    grunt.log.writeln('Unzipping atom-shell')
    directoryPath = path.dirname(zipPath)

    spawn {cmd: 'unzip', args: [zipPath, '-d', directoryPath]}, (error) ->
      rm(zipPath)
      callback(error)
        <commit_msg>Enable to use http proxy when updating atom-shell.<commit_after>fs = require 'fs'
path = require 'path'

request = require 'request'

module.exports = (grunt) ->
  {spawn, mkdir, rm, cp} = require('./task-helpers')(grunt)

  getAtomShellVersion = ->
    versionPath = path.join('atom-shell', 'version')
    if grunt.file.isFile(versionPath)
      grunt.file.read(versionPath).trim()
    else
      null

  getCachePath = (version) -> "/tmp/atom-cached-atom-shells/#{version}"

  isAtomShellVersionCached = (version) ->
    grunt.file.isFile(getCachePath(version), 'version')

  downloadAtomShell = (version, callback) ->
    options =
      url: "https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/#{version}/atom-shell-#{version}-darwin.zip"
      proxy: process.env.http_proxy || process.env.https_proxy

    inputStream = request(options)
    inputStream.on 'response', (response) ->
      if response.statusCode is 200
        grunt.log.writeln("Downloading atom-shell version #{version.cyan}")
        cacheDirectory = getCachePath(version)
        rm(cacheDirectory)
        mkdir(cacheDirectory)
        cacheFile = path.join(cacheDirectory, 'atom-shell.zip')
        outputStream = fs.createWriteStream(cacheFile)
        outputStream.on 'close', -> callback(null, cacheFile)
        inputStream.pipe(outputStream)
      else
        if response.statusCode is 404
          grunt.log.error("atom-shell #{version.cyan} not found")
        else
          grunt.log.error("atom-shell #{version.cyan} request failed")
        callback(false)

  unzipAtomShell = (zipPath, callback) ->
    grunt.log.writeln('Unzipping atom-shell')
    directoryPath = path.dirname(zipPath)

    spawn {cmd: 'unzip', args: [zipPath, '-d', directoryPath]}, (error) ->
      rm(zipPath)
      callback(error)
        
{'fraction_non_alphanumeric': 0.13842210196525206, 'fraction_numerical': 0.003987467957846767, 'mean_word_length': 3.1859356376638854, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1063437', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1088, 'n_words': 203}