require 'yaml'
require 'lib/builder/builder'
namespace :pyrot do
desc "Generate Pyrot Daemon Config File"
task :generate_daemon_config do
if ENV['env'] == "dev"
puts "Starting pyrot in dev mode"
postfix = "_dev"
else
puts "Starting pyrot in production mode"
postfix = ""
end
support_path = File.expand_path("~/Library/Application Support/Pyrot")
mkdir support_path unless File.exist?(support_path)
raw_config = open(File.join(support_path, "pyrot#{postfix}.yml")).read
PYROT_CONFIG = YAML.load(raw_config)
config = open(File.join(support_path, "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! 'create-dirs', PYROT_CONFIG['create_dirs']
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.streamPort 1481
xml.streamPath PYROT_CONFIG['post_scripts']['ipod_path']
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
config.close
end
desc "Start Pyrot"
task :run=> :generate_daemon_config do
postfix = ENV['env'] == "dev" ? "_dev" : ""
puts "Starting Pyrot"
puts
log_path = File.expand_path("~/Library/Logs")
mkdir log_path unless File.exist?(log_path)
support_path = File.expand_path("~/Library/Application Support/Pyrot")
mkdir support_path unless File.exist?(support_path)
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(support_path, "config#{postfix}.xml")}\""
end or raise "Failures"
desc "Start Pyrot daemon"
task :start => :generate_daemon_config do
postfix = ENV['env'] == "dev" ? "_dev" : ""
puts "Starting the Pyrot daemon"
puts
log_path = File.expand_path("~/Library/Logs")
mkdir log_path unless File.exist?(log_path)
support_path = File.expand_path("~/Library/Application Support/Pyrot")
mkdir support_path unless File.exist?(support_path)
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(support_path, "config#{postfix}.xml")}\" &> \"#{log_path}/pyrot-startup.log\" & echo $! > \"#{File.join(support_path, 'pyrot.pid')}\" "
end or raise "Failures"
desc "Stop Pyrot daemon"
task :stop do
puts "Stopping the Pyrot daemon"
puts
log_path = File.expand_path("~/Library/Logs")
mkdir log_path unless File.exist?(log_path)
support_path = File.expand_path("~/Library/Application Support/Pyrot")
mkdir support_path unless File.exist?(support_path)
pid = File.new(File.join(support_path, '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