module DynTask

Public Class Methods

add_task(task,id=nil) click to toggle source
# File lib/dyntask/task_mngr.rb, line 16
def self.add_task(task,id=nil) #id.nil? => new task
  @@task_mngr ||= DynTask::TaskMngr.new
  @@task_mngr.add_task(task,id)
end
cfg_dir() click to toggle source
# File lib/dyntask/task_mngr.rb, line 34
def self.cfg_dir
  return @@cfg_dir if @@cfg_dir
  root=File.join(ENV["HOME"],".dyntask")
  ## the idea is that any path has to be relative to some system root
  sys_root=(ENV["HOMEDRIVE"]||"")+"/" # local mode
  @@cfg_dir={
    :root => root,
    :etc => File.join(root,"etc"),
    :share => File.join(root,"share"),
    :tasks => File.join(root,"share","tasks"),
    :plugins => File.join(root,"share","plugins"),
    :run => File.join(root,"run") # default folder to watch. In a perfect world (this is my goal), only this folder to watch!
  }
  ## File containing the sys_root_path (used in atom package)
  @@cfg_dir[:sys_root_path_cfg]=File.join(@@cfg_dir[:etc],"sys_root_path")
  self.update_sys_root(sys_root)
  @@cfg_dir
end
cfg_pandoc(renew=false) click to toggle source
# File lib/dyntask/task_mngr.rb, line 81
def self.cfg_pandoc(renew=false)
  return @@cfg_pandoc if @@cfg_pandoc and !renew
  @@cfg_pandoc={}
  @@cfg_pandoc[:extra_etc]=File.join(self.cfg_dir[:etc],"pandoc_extra_dir")
  @@cfg_pandoc[:extra_dir]=((File.exist? @@cfg_pandoc[:extra_etc]) ? File.read(@@cfg_pandoc[:extra_etc]) : File.join(self.cfg_dir[:root],"pandoc-extra")).strip
  @@cfg_pandoc[:config_rb]=File.join(self.cfg_dir[:share],"pandoc","config.rb")
  @@cfg_pandoc[:extra]=(File.exist? @@cfg_pandoc[:config_rb]) ? Object.class_eval(File.read(@@cfg_pandoc[:config_rb])) : {}
  @@cfg_pandoc
end
inc_task_cpt() click to toggle source
# File lib/dyntask/task_mngr.rb, line 12
def self.inc_task_cpt
  ((@@task_cpt += 1) == 9999 ? (@@task_cpt = 0) : @@task_cpt)
end
read_tasks(task_filename) click to toggle source
# File lib/dyntask/task_mngr.rb, line 26
def self.read_tasks(task_filename)
  @@task_mngr ||= DynTask::TaskMngr.new
  @@task_mngr.load_user_task_plugins
  @@task_mngr.read_tasks(task_filename)
end
relative_path_from_sys_root(abs_path) click to toggle source
# File lib/dyntask/task_mngr.rb, line 67
def self.relative_path_from_sys_root(abs_path)
  begin
    #p abs_path
    #p self.cfg_dir[:sys_root]
    ap=Pathname.new(abs_path).realpath
    #p ap
    ap.relative_path_from(Pathname.new(self.cfg_dir[:sys_root])).to_s
  rescue
    nil
  end
end
save_tasks(task_basename,task_dirname=nil) click to toggle source
# File lib/dyntask/task_mngr.rb, line 21
def self.save_tasks(task_basename,task_dirname=nil)
  return unless @@task_mngr
  @@task_mngr.save_tasks(task_basename,task_dirname)
end
sys_root_path(rel_path) click to toggle source
# File lib/dyntask/task_mngr.rb, line 63
def self.sys_root_path(rel_path)
  File.expand_path File.join(self.cfg_dir[:sys_root],rel_path)
end
update_sys_root(path) click to toggle source

to be able to change sys_root path depending on local or remote mode

# File lib/dyntask/task_mngr.rb, line 54
def self.update_sys_root(path)
  @@cfg_dir[:sys_root]=path
  ## save sys_root_path to some config file (used in atom package)
  FileUtils.mkdir_p File.dirname(@@cfg_dir[:sys_root_path_cfg])
  File.open(@@cfg_dir[:sys_root_path_cfg],"w") do |f|
    f << @@cfg_dir[:sys_root]
  end
end
wait_for_file(filename,wait_loop_number = 20, wait_loop_time = 0.5,verbose=false) click to toggle source
# File lib/dyntask/task_mngr.rb, line 91
def self.wait_for_file(filename,wait_loop_number = 20, wait_loop_time = 0.5,verbose=false)
  cpt=0
  while !File.exists? filename and cpt < wait_loop_number
    p "wait: #{cpt}"
    sleep wait_loop_time
    cpt+=1
  end
  ## return succeed
  File.exists? filename
end