<commit_before>require 'erb'
require 'open-uri'

module PressPass
  module Cli

    class NewProjectGenerator

      def initialize(command = "new")
        @options = {:php_port => 8000}

        @app_name = ARGV.first

        OptionParser.new do |opts|
          opts.banner = "Usage: presspass #{command} <app_name> [options]"

          opts.on("--port NUMBER", "Port to run PHP on") do |php_port|
            @options[:php_port] = php_port
          end

        end.parse!(ARGV)

      end

      def run
        create_project_directory

        download_wordpress

        extract_wordpress_into_project_directory

        install_foreman(php_port: @options[:php_port])

        puts "WordPress installation created at #{@app_name}."
      end

      private

      def install_foreman(php_port: 8000)
        foreman_config = "web: php -S 0.0.0.0:#{php_port}\n"

        File.open(File.join(@app_name, "Procfile"), "w+") do |f|
          f.write(foreman_config)
        end
      end

      def create_project_directory
        if File.exist?(@app_name)
          puts "A file or directory with name #{@app_name} already exists."
          exit 1
        end
      end

      def download_wordpress
        if !File.exists?("/tmp/wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz")
          puts "Downloading wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz..."

          resp = open("https://wordpress.org/wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz")
          open("/tmp/wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz", 'w') do |file|
            file.write(resp.read)
          end
        end

        puts "wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz downloaded."
      end

      def extract_wordpress_into_project_directory
        filestamp = Time.now.to_i
        download_location = File.join('/tmp', "wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz")
        tmp_dir = "/tmp/wordpress-latest-#{filestamp}"

        Dir.mkdir(tmp_dir)
        `cd #{tmp_dir}; tar -xzf #{download_location}`

        FileUtils.mv("#{tmp_dir}/wordpress", @app_name)
        FileUtils.rm_r(tmp_dir)
      end

    end
  end
end<commit_msg>Use curl for downloading latest Wordpress<commit_after>require 'erb'
require 'open-uri'

module PressPass
  module Cli

    class NewProjectGenerator

      def initialize(command = "new")
        @options = {:php_port => 8000}

        @app_name = ARGV.first

        OptionParser.new do |opts|
          opts.banner = "Usage: presspass #{command} <app_name> [options]"

          opts.on("--port NUMBER", "Port to run PHP on") do |php_port|
            @options[:php_port] = php_port
          end

        end.parse!(ARGV)

      end

      def run
        create_project_directory

        download_wordpress

        extract_wordpress_into_project_directory

        install_foreman(php_port: @options[:php_port])

        puts "WordPress installation created at #{@app_name}."
      end

      private

      def install_foreman(php_port: 8000)
        foreman_config = "web: php -S 0.0.0.0:#{php_port}\n"

        File.open(File.join(@app_name, "Procfile"), "w+") do |f|
          f.write(foreman_config)
        end
      end

      def create_project_directory
        if File.exist?(@app_name)
          puts "A file or directory with name #{@app_name} already exists."
          exit 1
        end
      end

      def download_wordpress
        if !File.exists?("/tmp/wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz")
          filename = "wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz"
          puts "Downloading #{filename}..."

          `curl -o /tmp/#{filename} https://wordpress.org/#{filename}`
        end

        puts "#{filename} downloaded."
      end

      def extract_wordpress_into_project_directory
        filestamp = Time.now.to_i
        download_location = File.join('/tmp', "wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz")
        tmp_dir = "/tmp/wordpress-latest-#{filestamp}"

        Dir.mkdir(tmp_dir)
        `cd #{tmp_dir}; tar -xzf #{download_location}`

        FileUtils.mv("#{tmp_dir}/wordpress", @app_name)
        FileUtils.rm_r(tmp_dir)
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.11883085769046478, 'fraction_numerical': 0.006229036895064686, 'mean_word_length': 2.350722311396469, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5439508', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1262, 'n_words': 266}