require 'rubygems'
require 'yaml'
require 'builder'
namespace :pyrot do
desc "Generate Pyrot Daemon Config File"
task :generate_daemon_config do
postfix = ENV['env'] == "dev" ? "_dev" : ""
raw_config = open(File.join(File.dirname(__FILE__), 'config', "pyrot#{postfix}.yml")).read
PYROT_CONFIG = YAML.load(raw_config)
config = open(File.join(File.dirname(__FILE__), 'lib', 'pyrot', "config#{postfix}.xml"), 'w+')
xml = Builder::XmlMarkup.new(:target => config, :indent => 1)
xml.instruct!
xml.tag! 'nzb-config' do
xml.tag! 'thread-count', PYROT_CONFIG['thread_count']
xml.tag! 'bandwidth-limit', PYROT_CONFIG['bandwidth_limit']
xml.tag! 'skip-pars', PYROT_CONFIG['skip_pars']
xml.tag! 'store-by-group', PYROT_CONFIG['store_by_group']
xml.usenet do
xml.host PYROT_CONFIG['usenet']['host']
xml.login PYROT_CONFIG['usenet']['login']
xml.password PYROT_CONFIG['usenet']['password']
end
xml.newzbin do
xml.login PYROT_CONFIG['newzbin']['login']
xml.password PYROT_CONFIG['newzbin']['password']
end
xml.server do
xml.port 1480
xml.login 'test'
xml.password 'test'
end
xml.group :title => :Movies do
xml.tag! 'save-directory', PYROT_CONFIG['movies']['save_directory']
xml.tag! 'par-repair'
xml.unrar
xml.script do
xml.command PYROT_CONFIG['movies']['script']
end
end
xml.group :title => :TV do
xml.tag! 'save-directory', PYROT_CONFIG['tv']['save_directory']
xml.tag! 'par-repair'
xml.unrar
xml.script do
xml.command PYROT_CONFIG['tv']['script']
end
end
end
end
desc "Start Pyrot daemon"
task :start => :generate_daemon_config do
postfix = ENV['env'] == "dev" ? "_dev" : ""
puts "Starting the Pyrot daemon"
puts
mkdir "log" unless File.exist?("log")
system "java -Djava.awt.headless=true -Dlog4j.configuration=file:#{File.join(File.dirname(__FILE__), 'lib', 'pyrot', 'log4j.properties')} -jar #{File.join(File.dirname(__FILE__), 'lib', 'pyrot', 'pyrot-client.jar')} #{File.join(File.dirname(__FILE__), 'lib', 'pyrot', "config#{postfix}.xml")} &> log/pyrot-startup.log & echo $! > #{File.join(File.dirname(__FILE__), 'log', 'pyrot.pid')} "
end or raise "Failures"
desc "Stop Pyrot daemon"
task :stop do
puts "Stopping the Pyrot daemon"
puts
pid = File.new(File.join(File.dirname(__FILE__), 'log', 'pyrot.pid'), 'r').readline
system "kill #{pid}"
end or raise "Failures"
desc "Restart Pyrot daemon"
task :restart => [:stop, :start] do
end or raise "Failures"
end