<commit_before>#!/usr/bin/env ruby

$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))

require 'rubygems'
require 'bundler/setup'

require 'webrick'
require 'user_command'
require 'paamuk_command'
require 'command_dispatcher'

require 'command_file'
require 'request'

require 'trollop'

#TODO
#make it possible to start without a .paamuk.json, only with setcommand
#make it possible to use the POST-method


options = Trollop::options do
  opt :daemon, "Run as a daemon"
  opt :port, "The port to listen on", :default => 8000
end



server = WEBrick::HTTPServer.new :BindAddress => "127.0.0.1",
  :Port => options[:port],
  :DocumentRoot => "."


command_dispatcher = CommandDispatcher.new
expanded_path = File.expand_path("~/.paamuk.json")
CommandFile.file_name = expanded_path
command_dispatcher.bind_command("user", UserCommand.new)
command_dispatcher.bind_command("paamuk", PaamukCommand.new(server))

server.mount_proc '/' do |req, res|
  query_hash = req.query()
  query = query_hash['q']

  if not query.nil?
    request = Request.from_string query.gsub("+", " ")
    command_dispatcher.dispatch(request, res)
  end
end


trap('INT') { server.shutdown }<commit_msg>Changed 'paamuk' prefix to 'server' for server related commands<commit_after>#!/usr/bin/env ruby

$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))

require 'rubygems'
require 'bundler/setup'

require 'webrick'
require 'user_command'
require 'paamuk_command'
require 'command_dispatcher'

require 'command_file'
require 'request'

require 'trollop'

#TODO
#make it possible to start without a .paamuk.json, only with setcommand
#make it possible to use the POST-method
#use backticks in arguments to run system commands (is that safe? investigate)


options = Trollop::options do
  opt :daemon, "Run as a daemon"
  opt :port, "The port to listen on", :default => 8000
end



server = WEBrick::HTTPServer.new :BindAddress => "127.0.0.1",
  :Port => options[:port],
  :DocumentRoot => "."


command_dispatcher = CommandDispatcher.new
expanded_path = File.expand_path("~/.paamuk.json")
CommandFile.file_name = expanded_path
command_dispatcher.bind_command("user", UserCommand.new)
command_dispatcher.bind_command("server", PaamukCommand.new(server))

server.mount_proc '/' do |req, res|
  query_hash = req.query()
  query = query_hash['q']

  if not query.nil?
    request = Request.from_string query.gsub("+", " ")
    command_dispatcher.dispatch(request, res)
  end
end


trap('INT') { server.shutdown }
{'fraction_non_alphanumeric': 0.12903225806451613, 'fraction_numerical': 0.007590132827324478, 'mean_word_length': 5.508641975308642, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '710094', 'n_tokens_mistral': 912, 'n_tokens_neox': 879, 'n_words': 216}