<commit_before># FIXME: ========== cleanup and remove ====================
require 'yaml'
require 'date'
require 'fileutils'

AUTHENTICATED_PREFIX = "oo"
SITES_ROOT = "#{RAILS_ROOT}/sites"
PASSWORD_SALT = "<PASSWORD>" # type anything here (but change this line !)
ZENA_CALENDAR_LANGS = ["en", "fr"] # FIXME: build this dynamically from existing files
def has_executable(*list)
  list.inject(true) do |s,e|
    s && !(`which #{e} || echo 'no #{e}'` =~ /^no #{e}/)
  end
end
ENABLE_LATEX   = true  && has_executable('pdflatex') # enable LateX post-rendering
ENABLE_FOP     = true  && has_executable('fop', 'xsltproc') # enable xsl-fo post-rendering
ENABLE_MATH    = true  && has_executable('latex', 'dvips', 'convert', 'gs')
ENABLE_ZENA_UP = false && has_executable('zena_up')
ENABLE_XSENDFILE = false

UPLOAD_KEY     = defined?(Mongrel) ? 'upload_id' : "X-Progress-ID"

require 'bricks/patcher'

module Zena
  VERSION = '0.14.0'
  REVISION = 1336
  ROOT    = File.expand_path(File.join(File.dirname(__FILE__), '..'))

  class << self
    attr_accessor :tools_enabled
    def add_load_paths(config = nil)
      paths_to_add = (
        Dir["#{Zena::ROOT}/vendor/gems/*/lib"] +
        Dir["#{Zena::ROOT}/vendor/plugins/*/lib"] +
        Bricks::Patcher.models_paths
      )
      if config
        config.load_paths += ["#{Zena::ROOT}/vendor"]
      else
        paths_to_add.each do |path|
          $LOAD_PATH.push path
        end
      end
    end

    def enable_tools
      # TODO: move all code from environment.rb here...
      @tools_enabled ||= {:Latex => ENABLE_LATEX, :fop => ENABLE_FOP, :math => ENABLE_MATH, :zena_up => ENABLE_ZENA_UP}.map{|k,v| v ? k : nil}.compact
    end

    def include_modules
      ActionController::Routing::RouteSet::Mapper.send :include, Zena::Routes

      if ActiveRecord::Base.configurations[RAILS_ENV]['adapter'] == 'mysql'
        # This has to come first
        Zena::Fix::MysqlConnection
      end

      # FIXME: make this explicit in models
      ActiveRecord::Base.send :include, Zena::Use::PublicAttributes
      ActiveRecord::Base.send :include, Zena::Use::Zafu::ModelMethods
      ActiveRecord::Base.send :include, Zena::Use::NodeQueryFinders::AddUseNodeQueryMethod
      ActiveRecord::Base.send :include, Zena::Acts::Secure
      ActiveRecord::Base.send :include, Zena::Acts::Multiversion::AddActsAsMethods
    end

    def require_in_lib(name, dir, lib_name = nil)
      if defined?(ActiveRecord)
        # late loading, require
        base = Dir["#{dir}/*#{name}*"].first
        lib_path = "#{base}/lib/#{lib_name || name}"
        lib_path += '.rb' unless lib_path =~ /\.rb$/
        if File.exist?(lib_path)
          require lib_path
        else
          puts "Could not require #{lib_path.inspect}"
        end
      end
    end

    def gem_configuration
      conf = open("#{Zena::ROOT}/config/gems.yml") {|f| YAML.load(f.read)}
      res = {}
      conf.each do |k, v|
        if v.kind_of?(String)
          res[k] = {'version' => v}
        else
          res[k] = v
        end
      end
      res
    end

    def gems_setup
      gem_configuration.each do |gem_name, gem_config|
        if gem_config
          gem gem_name, gem_config['version']
        else
          gem gem_name
        end
      end
    end

    def config_gems(config)
      gem_configuration.each do |gem_name, gem_config|
        if gem_config
          config.gem gem_name, gem_config.symbolize_keys # to we need to replace '= 3.0.4' by '3.0.4' ?
        else
          config.gem gem_name
        end
      end
    end<commit_msg>Gems should not be forced to load when we are not using zena as external gem.<commit_after># FIXME: ========== cleanup and remove ====================
require 'yaml'
require 'date'
require 'fileutils'

AUTHENTICATED_PREFIX = "oo"
SITES_ROOT = "#{RAILS_ROOT}/sites"
PASSWORD_SALT = "<PASSWORD>" # type anything here (but change this line !)
ZENA_CALENDAR_LANGS = ["en", "fr"] # FIXME: build this dynamically from existing files
def has_executable(*list)
  list.inject(true) do |s,e|
    s && !(`which #{e} || echo 'no #{e}'` =~ /^no #{e}/)
  end
end
ENABLE_LATEX   = true  && has_executable('pdflatex') # enable LateX post-rendering
ENABLE_FOP     = true  && has_executable('fop', 'xsltproc') # enable xsl-fo post-rendering
ENABLE_MATH    = true  && has_executable('latex', 'dvips', 'convert', 'gs')
ENABLE_ZENA_UP = false && has_executable('zena_up')
ENABLE_XSENDFILE = false

UPLOAD_KEY     = defined?(Mongrel) ? 'upload_id' : "X-Progress-ID"

require 'bricks/patcher'

module Zena
  VERSION = '0.14.0'
  REVISION = 1336
  ROOT    = File.expand_path(File.join(File.dirname(__FILE__), '..'))

  class << self
    attr_accessor :tools_enabled
    def add_load_paths(config = nil)
      paths_to_add = (
        Dir["#{Zena::ROOT}/vendor/gems/*/lib"] +
        Dir["#{Zena::ROOT}/vendor/plugins/*/lib"] +
        Bricks::Patcher.models_paths
      )
      if config
        config.load_paths += ["#{Zena::ROOT}/vendor"]
      else
        paths_to_add.each do |path|
          $LOAD_PATH.push path
        end
      end
    end

    def enable_tools
      # TODO: move all code from environment.rb here...
      @tools_enabled ||= {:Latex => ENABLE_LATEX, :fop => ENABLE_FOP, :math => ENABLE_MATH, :zena_up => ENABLE_ZENA_UP}.map{|k,v| v ? k : nil}.compact
    end

    def include_modules
      ActionController::Routing::RouteSet::Mapper.send :include, Zena::Routes

      if ActiveRecord::Base.configurations[RAILS_ENV]['adapter'] == 'mysql'
        # This has to come first
        Zena::Fix::MysqlConnection
      end

      # FIXME: make this explicit in models
      ActiveRecord::Base.send :include, Zena::Use::PublicAttributes
      ActiveRecord::Base.send :include, Zena::Use::Zafu::ModelMethods
      ActiveRecord::Base.send :include, Zena::Use::NodeQueryFinders::AddUseNodeQueryMethod
      ActiveRecord::Base.send :include, Zena::Acts::Secure
      ActiveRecord::Base.send :include, Zena::Acts::Multiversion::AddActsAsMethods
    end

    def require_in_lib(name, dir, lib_name = nil)
      if defined?(ActiveRecord)
        # late loading, require
        base = Dir["#{dir}/*#{name}*"].first
        lib_path = "#{base}/lib/#{lib_name || name}"
        lib_path += '.rb' unless lib_path =~ /\.rb$/
        if File.exist?(lib_path)
          require lib_path
        else
          puts "Could not require #{lib_path.inspect}"
        end
      end
    end

    def gem_configuration
      conf = open("#{Zena::ROOT}/config/gems.yml") {|f| YAML.load(f.read)}
      res = {}
      conf.each do |k, v|
        if v.kind_of?(String)
          res[k] = {'version' => v}
        else
          res[k] = v
        end
      end
      res
    end

    def gems_setup
      if RAILS_ROOT != Zena::ROOT
        gem_configuration.each do |gem_name, gem_config|
          if gem_config
            gem gem_name, gem_config['version']
          else
            gem gem_name
          end
        end
      end
    end

    def config_gems(config)
      gem_configuration.each do |gem_name, gem_config|
        if gem_config
          config.gem gem_name, gem_config.symbolize_keys # to we need to replace '= 3.0.4' by '3.0.4' ?
        else
          config.gem gem_name
        end
      end
    end
{'fraction_non_alphanumeric': 0.1375, 'fraction_numerical': 0.0038461538461538464, 'mean_word_length': 2.7223926380368098, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '5057667', 'n_tokens_mistral': 2472, 'n_tokens_neox': 2435, 'n_words': 554}