<commit_before>######################################################################################################
# Substantial portions of this code were adapted from the Radiant CMS project (http://radiantcms.org) #
#######################################################################################################

require 'rbconfig'
require 'digest/md5'
require 'rails_generator/secret_key_generator'
require 'generators/extension/extension_generator'
require 'lib/plugins/string_extensions/lib/string_extensions'

class InstanceGenerator < Rails::Generator::Base
  DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
                              Config::CONFIG['ruby_install_name'])
  
  DATABASES = %w( mysql postgresql sqlite3 sqlserver )
  
  MYSQL_SOCKET_LOCATIONS = [
    "/tmp/mysql.sock",                        # default
    "/var/run/mysqld/mysqld.sock",            # debian/gentoo
    "/var/tmp/mysql.sock",                    # freebsd
    "/var/lib/mysql/mysql.sock",              # fedora
    "/opt/local/lib/mysql/mysql.sock",        # fedora
    "/opt/local/var/run/mysqld/mysqld.sock",  # mac + darwinports + mysql
    "/opt/local/var/run/mysql4/mysqld.sock",  # mac + darwinports + mysql4
    "/opt/local/var/run/mysql5/mysqld.sock"   # mac + darwinports + mysql5
  ]
    
  default_options :db => "sqlite3", :shebang => DEFAULT_SHEBANG, :freeze => false

  def initialize(runtime_args, runtime_options = {})
    super
    usage if args.empty?
    usage("Databases supported for preconfiguration are: #{DATABASES.join(", ")}") if (options[:db] && !DATABASES.include?(options[:db]))
    @destination_root = args.shift
    @app_name = File.basename(File.expand_path(@destination_root))  
  end

  def manifest
    
    md5 = Digest::MD5.new
    now = Time.now
    md5 << now.to_s
    md5 << String(now.usec)
    md5 << String(rand(0))
    md5 << String($$)
    md5 << @app_name
 
    # Do our best to generate a secure secret key for CookieStore
    secret = ActiveSupport::SecureRandom.hex(64)
        
    # The absolute location of the Spree files
    root = File.expand_path(SPREE_ROOT) 
    
    # Use /usr/bin/env if no special shebang was specified
    script_options     = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
    dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] }
    
    record do |m|
      # Root directory
      m.directory ""
      
      # Standard files and directories
      base_dirs = %w(config config/environments config/initializers db log script public vendor/plugins vendor/extensions)
      text_files = %w(CHANGELOG CONTRIBUTORS LICENSE INSTALL README.markdown)
      environments = Dir["#{root}/config/environments/*.rb"]
      scripts = Dir["#{root}/script/**/*"].reject { |f| f =~ /(destroy|generate)$/ }
      public_files = ["public/.htaccess.example"] + Dir["#{root}/public/**/*"]
      frozen_gems =  Dir["#{root}/vendor/gems/**/*"]
      
      files = base_dirs + text_files + environments + scripts + public_files + frozen_gems
      files.map! { |f| f = $1 if f =~ %r{^#{root}/(.+)$}; f }
      
      files.sort!
      
      files.each do |file|
        case
        when File.directory?("#{root}/#{file}")
          m.directory file
        when file =~ %r{^script/}
          m.file spree_root(file), file, script_options
        when file =~ %r{^public/dispatch}
          m.file spree_root(file), file, dispatcher_options
        when file =~ %r{^public/robots\.txt}
          # we'll use a special robots.txt if creating a demo instance
          m.file spree_root(file), file unless options[:demo]<commit_msg>changed extension for README file, following earlier renaming (this was preventing spree command from running)<commit_after>######################################################################################################
# Substantial portions of this code were adapted from the Radiant CMS project (http://radiantcms.org) #
#######################################################################################################

require 'rbconfig'
require 'digest/md5'
require 'rails_generator/secret_key_generator'
require 'generators/extension/extension_generator'
require 'lib/plugins/string_extensions/lib/string_extensions'

class InstanceGenerator < Rails::Generator::Base
  DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
                              Config::CONFIG['ruby_install_name'])
  
  DATABASES = %w( mysql postgresql sqlite3 sqlserver )
  
  MYSQL_SOCKET_LOCATIONS = [
    "/tmp/mysql.sock",                        # default
    "/var/run/mysqld/mysqld.sock",            # debian/gentoo
    "/var/tmp/mysql.sock",                    # freebsd
    "/var/lib/mysql/mysql.sock",              # fedora
    "/opt/local/lib/mysql/mysql.sock",        # fedora
    "/opt/local/var/run/mysqld/mysqld.sock",  # mac + darwinports + mysql
    "/opt/local/var/run/mysql4/mysqld.sock",  # mac + darwinports + mysql4
    "/opt/local/var/run/mysql5/mysqld.sock"   # mac + darwinports + mysql5
  ]
    
  default_options :db => "sqlite3", :shebang => DEFAULT_SHEBANG, :freeze => false

  def initialize(runtime_args, runtime_options = {})
    super
    usage if args.empty?
    usage("Databases supported for preconfiguration are: #{DATABASES.join(", ")}") if (options[:db] && !DATABASES.include?(options[:db]))
    @destination_root = args.shift
    @app_name = File.basename(File.expand_path(@destination_root))  
  end

  def manifest
    
    md5 = Digest::MD5.new
    now = Time.now
    md5 << now.to_s
    md5 << String(now.usec)
    md5 << String(rand(0))
    md5 << String($$)
    md5 << @app_name
 
    # Do our best to generate a secure secret key for CookieStore
    secret = ActiveSupport::SecureRandom.hex(64)
        
    # The absolute location of the Spree files
    root = File.expand_path(SPREE_ROOT) 
    
    # Use /usr/bin/env if no special shebang was specified
    script_options     = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
    dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] }
    
    record do |m|
      # Root directory
      m.directory ""
      
      # Standard files and directories
      base_dirs = %w(config config/environments config/initializers db log script public vendor/plugins vendor/extensions)
      text_files = %w(CHANGELOG CONTRIBUTORS LICENSE INSTALL README.md)
      environments = Dir["#{root}/config/environments/*.rb"]
      scripts = Dir["#{root}/script/**/*"].reject { |f| f =~ /(destroy|generate)$/ }
      public_files = ["public/.htaccess.example"] + Dir["#{root}/public/**/*"]
      frozen_gems =  Dir["#{root}/vendor/gems/**/*"]
      
      files = base_dirs + text_files + environments + scripts + public_files + frozen_gems
      files.map! { |f| f = $1 if f =~ %r{^#{root}/(.+)$}; f }
      
      files.sort!
      
      files.each do |file|
        case
        when File.directory?("#{root}/#{file}")
          m.directory file
        when file =~ %r{^script/}
          m.file spree_root(file), file, script_options
        when file =~ %r{^public/dispatch}
          m.file spree_root(file), file, dispatcher_options
        when file =~ %r{^public/robots\.txt}
          # we'll use a special robots.txt if creating a demo instance
          m.file spree_root(file), file unless options[:demo]
{'fraction_non_alphanumeric': 0.18214911689362276, 'fraction_numerical': 0.007010920857489551, 'mean_word_length': 3.003237992444684, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 17, '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': '5554395', 'n_tokens_mistral': 2303, 'n_tokens_neox': 2246, 'n_words': 493}