<commit_before>module DPL
  class Provider
    class GAE < Provider
      experimental 'Google App Engine'

      BASE='https://dl.google.com/dl/cloudsdk/channels/rapid/'
      NAME='google-cloud-sdk'
      EXT='.tar.gz'
      INSTALL='~'
      BOOTSTRAP="#{INSTALL}/#{NAME}/bin/bootstrapping/install.py"
      GCLOUD="#{INSTALL}/#{NAME}/bin/gcloud"

      def with_python_2_7(cmd)
        "source #{context.env['HOME']}/virtualenv/python2.7/bin/activate; #{cmd}"
      end

      def install_deploy_dependencies
        if File.exists? GCLOUD
          return
        end

        $stderr.puts 'Downloading Google Cloud SDK ...'

        unless context.shell("curl -L #{BASE + NAME + EXT} | gzip -d | tar -x -C #{INSTALL}")
          error 'Could not download Google Cloud SDK.'
        end

        $stderr.puts 'Bootstrapping Google Cloud SDK ...'

        unless context.shell(with_python_2_7("#{BOOTSTRAP} --usage-reporting=false --command-completion=false --path-update=false"))
          error 'Could not bootstrap Google Cloud SDK.'
        end
      end

      def needs_key?
        false
      end

      def check_auth
        unless context.shell(with_python_2_7("#{GCLOUD} -q --verbosity debug auth activate-service-account --key-file #{keyfile}"))
          error 'Authentication failed.'
        end
      end

      def keyfile
        options[:keyfile] || context.env['GOOGLECLOUDKEYFILE'] || 'service-account.json'
      end

      def project
        options[:project] || context.env['GOOGLECLOUDPROJECT'] || context.env['CLOUDSDK_CORE_PROJECT'] || File.dirname(context.env['TRAVIS_REPO_SLUG'] || '')
      end

      def version
        options[:version]
      end

      def config
        options[:config] || 'app.yaml'
      end

      def no_promote
        options[:no_promote]
      end

      def verbosity
        options[:verbosity] || 'warning'
      end

      def no_stop_previous_version
        options[:no_stop_previous_version]
      end

      def push_app
        command = GCLOUD
        command << ' --quiet'
        command << " --verbosity \"#{verbosity}\""
        command << " --project \"#{project}\""
        command << " app deploy \"#{config}\""
        command << " --version \"#{version}\"" unless version.to_s.empty?
        command << " --#{no_promote ? 'no-' : ''}promote"
        command << ' --no-stop-previous-version' unless no_stop_previous_version.to_s.empty?
        unless context.shell(with_python_2_7(command))
          log 'Deployment failed.'
          context.shell('find $HOME/.config/gcloud/logs -type f -print -exec cat {} \;')
          error ''
        end
      end
    end
  end
end<commit_msg>Invoke `source` inside bash process<commit_after>module DPL
  class Provider
    class GAE < Provider
      experimental 'Google App Engine'

      BASE='https://dl.google.com/dl/cloudsdk/channels/rapid/'
      NAME='google-cloud-sdk'
      EXT='.tar.gz'
      INSTALL='~'
      BOOTSTRAP="#{INSTALL}/#{NAME}/bin/bootstrapping/install.py"
      GCLOUD="#{INSTALL}/#{NAME}/bin/gcloud"

      def with_python_2_7(cmd)
        context.shell("bash -c 'source #{context.env['HOME']}/virtualenv/python2.7/bin/activate; #{cmd}'")
      end

      def install_deploy_dependencies
        if File.exists? GCLOUD
          return
        end

        $stderr.puts 'Downloading Google Cloud SDK ...'

        unless context.shell("curl -L #{BASE + NAME + EXT} | gzip -d | tar -x -C #{INSTALL}")
          error 'Could not download Google Cloud SDK.'
        end

        $stderr.puts 'Bootstrapping Google Cloud SDK ...'

        unless with_python_2_7("#{BOOTSTRAP} --usage-reporting=false --command-completion=false --path-update=false")
          error 'Could not bootstrap Google Cloud SDK.'
        end
      end

      def needs_key?
        false
      end

      def check_auth
        unless with_python_2_7("#{GCLOUD} -q --verbosity debug auth activate-service-account --key-file #{keyfile}")
          error 'Authentication failed.'
        end
      end

      def keyfile
        options[:keyfile] || context.env['GOOGLECLOUDKEYFILE'] || 'service-account.json'
      end

      def project
        options[:project] || context.env['GOOGLECLOUDPROJECT'] || context.env['CLOUDSDK_CORE_PROJECT'] || File.dirname(context.env['TRAVIS_REPO_SLUG'] || '')
      end

      def version
        options[:version]
      end

      def config
        options[:config] || 'app.yaml'
      end

      def no_promote
        options[:no_promote]
      end

      def verbosity
        options[:verbosity] || 'warning'
      end

      def no_stop_previous_version
        options[:no_stop_previous_version]
      end

      def push_app
        command = GCLOUD
        command << ' --quiet'
        command << " --verbosity \"#{verbosity}\""
        command << " --project \"#{project}\""
        command << " app deploy \"#{config}\""
        command << " --version \"#{version}\"" unless version.to_s.empty?
        command << " --#{no_promote ? 'no-' : ''}promote"
        command << ' --no-stop-previous-version' unless no_stop_previous_version.to_s.empty?
        unless with_python_2_7(command)
          log 'Deployment failed.'
          context.shell('find $HOME/.config/gcloud/logs -type f -print -exec cat {} \;')
          error ''
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.13239700374531835, 'fraction_numerical': 0.003745318352059925, 'mean_word_length': 2.17538644470868, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5142619', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1596, 'n_words': 357}