dyntask-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/dyntask-init +90 -0
- data/bin/dyntask-reader +25 -0
- data/bin/dyntask-server +119 -0
- data/bin/dyntask-writer +43 -0
- data/lib/dyntask/task_mngr.rb +365 -0
- data/lib/dyntask.rb +1 -0
- metadata +56 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: db4c0169535bb6a981d671d2999d4938811c6062
|
4
|
+
data.tar.gz: 8aea8a1e1c10fbbb6f98f89deb365d0fa405d50a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 79fa4901c10d0d8192f79df1c4d0aeb53c33a540069dd0b68f630d8a70845d38440254fd9bee5e85642f8793e23711c9c58d6d31d567b68834ffb45c646b8478
|
7
|
+
data.tar.gz: 0fd0be9b9cd04407abb840ad4b41247ff1dcb89807d0488d802b9783b52fd2de3c3ed1866c589a922125d906c0ebe05d731d43664a7009326d79fbc36f6540c6
|
data/bin/dyntask-init
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'trollop'
|
4
|
+
require 'pathname'
|
5
|
+
require 'dyntask/task_mngr'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
VERSION='0.1.0'
|
9
|
+
|
10
|
+
options = Trollop::options do
|
11
|
+
version "dyntask-init version #{VERSION}"
|
12
|
+
banner <<-EOS
|
13
|
+
dyntask-init executes the dynamic task file.
|
14
|
+
Usage:
|
15
|
+
dyntask-init [--force] '<name>' '<working_dir>:<list_of_comma_separated_tasks>' ['<working_dir_2>:<list_of_comma_separated_tasks_2>' ...]
|
16
|
+
dyntask-init '<name>'
|
17
|
+
dyntask-init --force --rm '<name>'
|
18
|
+
Options:
|
19
|
+
EOS
|
20
|
+
opt :force, "force is used to rewrite on an existing file", :short => 'f', :type => :boolean, :default => false
|
21
|
+
opt :rm, "remove an existing file", :type => :boolean, :default => false
|
22
|
+
end
|
23
|
+
|
24
|
+
Trollop::die Trollop::educate if(ARGV.size == 0)
|
25
|
+
|
26
|
+
if ARGV[0] == "pandoc-extra"
|
27
|
+
case ARGV[1]
|
28
|
+
when "ls"
|
29
|
+
if File.directory? DynTask.cfg_pandoc[:extra_dir]
|
30
|
+
puts `/usr/bin/env bash -c 'ls #{DynTask.cfg_pandoc[:extra_dir]}'`
|
31
|
+
end
|
32
|
+
when "dir"
|
33
|
+
if options[:force] and options[:rm]
|
34
|
+
FileUtils.rm(DynTask.cfg_pandoc[:extra_etc])
|
35
|
+
elsif ARGV[2] and (File.directory? ARGV[2] or options[:force])
|
36
|
+
File.open(DynTask.cfg_pandoc[:extra_etc],"w") do |f|
|
37
|
+
f << ARGV[2]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
puts "Config file #{DynTask.cfg_pandoc[:extra_etc]} is "+ ( (File.exist? DynTask.cfg_pandoc[:extra_etc]) ? "" : "not ") +"created."
|
41
|
+
puts "Current pandoc extra installations are located at #{DynTask.cfg_pandoc(true)[:extra_dir]}, "+((File.exist? DynTask.cfg_pandoc[:extra_dir]) ? "an " : "a non-") +"existing directory."
|
42
|
+
|
43
|
+
when "wget"
|
44
|
+
## Stuff!
|
45
|
+
p [:extra_dir,DynTask.cfg_pandoc[:extra_dir]]
|
46
|
+
FileUtils.mkdir_p DynTask.cfg_pandoc[:extra_dir]
|
47
|
+
curdir=Dir.pwd
|
48
|
+
Dir.chdir DynTask.cfg_pandoc[:extra_dir]
|
49
|
+
version="3.1.0"
|
50
|
+
puts "Installing reveal-js-#{version}"
|
51
|
+
system("/usr/bin/env bash -c 'wget -O revealjs.tgz https://github.com/hakimel/reveal.js/archive/#{version}.tar.gz && tar xzvf revealjs.tgz && rm revealjs.tgz'")
|
52
|
+
puts "Installing s5-11"
|
53
|
+
system("/usr/bin/env bash -c 'wget -O s5.zip http://meyerweb.com/eric/tools/s5/v/1.1/s5-11.zip && mkdir -p s5-tmp && unzip -d s5-tmp s5.zip && mv s5-tmp/ui s5-ui && rm s5.zip && rm -fr s5-tmp'")
|
54
|
+
Dir.chdir curdir
|
55
|
+
|
56
|
+
end
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
if ARGV.size == 1 and ARGV[0]=="ls"
|
63
|
+
Dir[File.join(DynTask.cfg_dir[:etc],"tasks","**/*")].each do |f|
|
64
|
+
puts "#{File.basename(f)}: #{File.read(f)}"
|
65
|
+
end
|
66
|
+
exit
|
67
|
+
end
|
68
|
+
|
69
|
+
etc_tasks=File.join(DynTask.cfg_dir[:etc],"tasks",ARGV[0])
|
70
|
+
|
71
|
+
if ARGV.size==1
|
72
|
+
if options[:rm] and options[:force]
|
73
|
+
require 'fileutils'
|
74
|
+
FileUtils.rm etc_tasks
|
75
|
+
end
|
76
|
+
else
|
77
|
+
if File.exists? etc_tasks and !options[:force]
|
78
|
+
puts "Error: file #{etc_tasks} already exist. Use --force or -f to modify this file!"
|
79
|
+
exit
|
80
|
+
else
|
81
|
+
require 'fileutils'
|
82
|
+
FileUtils.mkdir_p File.dirname(etc_tasks)
|
83
|
+
dyntask_tasks=ARGV[1..-1].join(" ")
|
84
|
+
File.open(etc_tasks,"w") do |f|
|
85
|
+
f << dyntask_tasks
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
puts "#{etc_tasks} contains: #{File.read(etc_tasks)}" if File.exists? etc_tasks
|
data/bin/dyntask-reader
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'trollop'
|
4
|
+
require 'pathname'
|
5
|
+
require 'dyntask'
|
6
|
+
|
7
|
+
VERSION='0.1.0'
|
8
|
+
|
9
|
+
options = Trollop::options do
|
10
|
+
version "dyntask-reader version #{VERSION}"
|
11
|
+
banner <<-EOS
|
12
|
+
dyntask-reader executes the dynamic task file.
|
13
|
+
Usage:
|
14
|
+
dyntask-reader '<dyntask file>'
|
15
|
+
Options:
|
16
|
+
EOS
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
Trollop::die Trollop::educate if(ARGV.size == 0)
|
21
|
+
|
22
|
+
filename=Pathname.new(ARGV[-1]).expand_path.to_s
|
23
|
+
|
24
|
+
#p filename
|
25
|
+
DynTask.read_tasks(filename)
|
data/bin/dyntask-server
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'filewatcher'
|
4
|
+
require 'trollop'
|
5
|
+
require 'pathname'
|
6
|
+
require 'thread'
|
7
|
+
require 'dyntask'
|
8
|
+
|
9
|
+
options = Trollop::options do
|
10
|
+
version "dyntask-server based on filewatcher, version #{FileWatcher.VERSION} by Thomas Flemming 2015"
|
11
|
+
banner <<-EOS
|
12
|
+
dyntask-server scans the filesystem and executes shell commands when files changes.
|
13
|
+
Usage:
|
14
|
+
dyntask-server [--restart] '<command type>'
|
15
|
+
Comment:
|
16
|
+
when file ~/.dyntask_workdir exists and contains a valid directory name, this becomes the working directory to watch unless -w option is provided at command line.
|
17
|
+
Options:
|
18
|
+
EOS
|
19
|
+
opt :dontwait, "Do not wait for filesystem updates before running", :short => 'd', :type => :boolean, :default => false
|
20
|
+
opt :restart, "Restart process when filesystem is updated", :short => 'r', :type => :boolean, :default => false
|
21
|
+
opt :list, "Print name of files being watched"
|
22
|
+
opt :interval, "Interval to scan filesystem.", :short => 'i', :type => :float, :default => 0.5
|
23
|
+
opt :spinner, "Show an ascii spinner", :short => 's', :type => :boolean, :default => false
|
24
|
+
end
|
25
|
+
|
26
|
+
Trollop::die Trollop::educate if(ARGV.size == 0)
|
27
|
+
|
28
|
+
tasks_to_watch = []
|
29
|
+
ARGV[0..-1].each do |a|
|
30
|
+
if !(a.include? ",") and File.exists? (etc_tasks=File.join(DynTask.cfg_dir[:etc],"tasks",a))
|
31
|
+
tasks_to_watch += File.read(etc_tasks).strip.split(/\s+/)
|
32
|
+
else
|
33
|
+
tasks_to_watch << a
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
# root working directory
|
39
|
+
# dyntask_root=nil
|
40
|
+
# if options[:workdir] != ""
|
41
|
+
# dyntask_root=options[:workdir].sub("~",ENV["HOME"])
|
42
|
+
# else
|
43
|
+
# etc_work_dir=File.join(DynTask.cfg_dir[:etc],"workdir")
|
44
|
+
# dyntask_root=File.read(etc_work_dir).strip.sub("~",ENV["HOME"]) if File.exists? etc_work_dir
|
45
|
+
# end
|
46
|
+
|
47
|
+
# unless dyntask_root
|
48
|
+
# puts "Working directory unset!\n Use: option -w with dyntask-server\n or\n Launch: dyntask-init -w <WORKING DIRECTORY> to set default working directory!"
|
49
|
+
# exit
|
50
|
+
# end
|
51
|
+
# unless File.exists? dyntask_root
|
52
|
+
# puts "Stop: #{dyntask_root} is not a directory!"
|
53
|
+
# exit
|
54
|
+
# end
|
55
|
+
|
56
|
+
#puts "Root directory is #{dyntask_root}"
|
57
|
+
|
58
|
+
if tasks_to_watch.empty?
|
59
|
+
puts "Stop: no tasks to serve!\n Launch: dyntask-init <NAME> <WORKDIR>:<LIST OF COMMA SEPARATED TASKS> to set of tasks to be called by <NAME>!"
|
60
|
+
exit
|
61
|
+
end
|
62
|
+
|
63
|
+
files_to_watch=[]
|
64
|
+
tasks_to_watch.each do |e|
|
65
|
+
workdir,tasks=e.split(":")
|
66
|
+
workdir=workdir.sub("~",ENV["HOME"])
|
67
|
+
tasks.split(",").each do |t|
|
68
|
+
files_to_watch << File.join(workdir,"**/*" +DynTask::TaskMngr::TASK_EXT+t) #if DynTask::TaskMngr::TASKS.include? file
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
files_to_watch.uniq!
|
73
|
+
|
74
|
+
puts "Tasks watched: #{files_to_watch}"
|
75
|
+
|
76
|
+
def restart(child_pid, env, cmd)
|
77
|
+
Process.kill(9,child_pid)
|
78
|
+
Process.wait(child_pid)
|
79
|
+
rescue Errno::ESRCH
|
80
|
+
# already killed
|
81
|
+
ensure
|
82
|
+
child_pid = Process.spawn({}, cmd)
|
83
|
+
end
|
84
|
+
|
85
|
+
if(options[:restart])
|
86
|
+
rd, wr = IO.pipe
|
87
|
+
child_pid = nil
|
88
|
+
end
|
89
|
+
|
90
|
+
begin
|
91
|
+
##p files
|
92
|
+
fw = FileWatcher.new(files_to_watch, options[:list], options[:dontwait], options[:spinner])
|
93
|
+
task_mngr=DynTask::TaskMngr.new
|
94
|
+
fw.watch(options[:interval]) do |filename, event|
|
95
|
+
cmd=nil
|
96
|
+
if([:changed,:new].include? event)
|
97
|
+
path = Pathname.new(filename).realpath.to_s
|
98
|
+
cmd = "dyntask-reader "+path
|
99
|
+
|
100
|
+
if(options[:restart])
|
101
|
+
if(child_pid == nil)
|
102
|
+
child_pid = Process.spawn({}, cmd)
|
103
|
+
else
|
104
|
+
child_id = restart(child_pid, {}, cmd)
|
105
|
+
end
|
106
|
+
else
|
107
|
+
begin
|
108
|
+
p "cmd: <#{cmd}>"
|
109
|
+
pid = Process.spawn({}, cmd)
|
110
|
+
Process.wait()
|
111
|
+
rescue SystemExit, Interrupt
|
112
|
+
exit(0)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
rescue SystemExit, Interrupt
|
118
|
+
fw.finalize
|
119
|
+
end
|
data/bin/dyntask-writer
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'trollop'
|
4
|
+
require 'pathname'
|
5
|
+
require 'dyntask'
|
6
|
+
|
7
|
+
VERSION='0.1.0'
|
8
|
+
|
9
|
+
options = Trollop::options do
|
10
|
+
version "dyntask-writer version #{VERSION}"
|
11
|
+
banner <<-EOS
|
12
|
+
dyntask-writer creates a dynamic task file.
|
13
|
+
Usage:
|
14
|
+
dyntask-writer '<dyntask file>' ['<dyntask file2>' ...]
|
15
|
+
Options:
|
16
|
+
EOS
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
Trollop::die Trollop::educate if(ARGV.size == 0)
|
21
|
+
task_basename=Pathname.new(ARGV[0]).expand_path.to_s
|
22
|
+
ARGV[1..-1].each do |task|
|
23
|
+
cmd,*opts=task.split(",")
|
24
|
+
task2={cmd: cmd}
|
25
|
+
opts.each{|o|
|
26
|
+
key,*value=o.split("=")
|
27
|
+
value=value.join("=")
|
28
|
+
#p [:value,value]
|
29
|
+
|
30
|
+
begin
|
31
|
+
task2[key.to_sym]=Object.class_eval(value)
|
32
|
+
rescue Exception
|
33
|
+
task2[key.to_sym]=value
|
34
|
+
end
|
35
|
+
}
|
36
|
+
[:source,:target].each {|t|
|
37
|
+
task2[t]=Pathname.new(task2[t]).expand_path.to_s if task2[t] and !(task2[t] =~ /^\%/)
|
38
|
+
}
|
39
|
+
p [:added,task2]
|
40
|
+
DynTask.add_task(task2)
|
41
|
+
end
|
42
|
+
|
43
|
+
DynTask.save_tasks(task_basename)
|
@@ -0,0 +1,365 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'dyndoc-software'
|
3
|
+
require 'dyndoc-converter'
|
4
|
+
require "fileutils"
|
5
|
+
|
6
|
+
module DynTask
|
7
|
+
|
8
|
+
@@task_mngr=nil
|
9
|
+
|
10
|
+
def self.add_task(task)
|
11
|
+
@@task_mngr ||= DynTask::TaskMngr.new
|
12
|
+
@@task_mngr.add_task(task)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.save_tasks(task_basename)
|
16
|
+
return unless @@task_mngr
|
17
|
+
@@task_mngr.save_tasks(task_basename)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.read_tasks(task_filename)
|
21
|
+
@@task_mngr ||= DynTask::TaskMngr.new
|
22
|
+
@@task_mngr.load_user_task_plugins
|
23
|
+
@@task_mngr.read_tasks(task_filename)
|
24
|
+
end
|
25
|
+
|
26
|
+
@@cfg_dir=nil
|
27
|
+
|
28
|
+
def self.cfg_dir
|
29
|
+
return @@cfg_dir if @@cfg_dir
|
30
|
+
root=File.join(ENV["HOME"],".dyntask")
|
31
|
+
@@cfg_dir={
|
32
|
+
:root => root,
|
33
|
+
:etc => File.join(root,"etc"),
|
34
|
+
:share => File.join(root,"share"),
|
35
|
+
:tasks => File.join(root,"share","tasks"),
|
36
|
+
:plugins => File.join(root,"share","plugins")
|
37
|
+
}
|
38
|
+
@@cfg_dir
|
39
|
+
end
|
40
|
+
|
41
|
+
@@cfg_pandoc=nil
|
42
|
+
|
43
|
+
def self.cfg_pandoc(renew=false)
|
44
|
+
return @@cfg_pandoc if @@cfg_pandoc and !renew
|
45
|
+
@@cfg_pandoc={}
|
46
|
+
@@cfg_pandoc[:extra_etc]=File.join(self.cfg_dir[:etc],"pandoc_extra_dir")
|
47
|
+
@@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
|
48
|
+
@@cfg_pandoc[:config_rb]=File.join(self.cfg_dir[:share],"pandoc","config.rb")
|
49
|
+
@@cfg_pandoc[:extra]=(File.exist? @@cfg_pandoc[:config_rb]) ? Object.class_eval(File.read(@@cfg_pandoc[:config_rb])) : {}
|
50
|
+
@@cfg_pandoc
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.wait_for_file(filename,wait_loop_number = 20, wait_loop_time = 0.5,verbose=false)
|
54
|
+
cpt=0
|
55
|
+
while !File.exists? filename and cpt < wait_loop_number
|
56
|
+
p "wait: #{cpt}"
|
57
|
+
sleep wait_loop_time
|
58
|
+
cpt+=1
|
59
|
+
end
|
60
|
+
## return succeed
|
61
|
+
File.exists? filename
|
62
|
+
end
|
63
|
+
|
64
|
+
class TaskMngr
|
65
|
+
|
66
|
+
# TODO: to put outside to be extended by users!
|
67
|
+
TASKS=["pdflatex","pandoc","png","dyn","sh"]
|
68
|
+
TASK_EXT=".task_"
|
69
|
+
|
70
|
+
def initialize
|
71
|
+
init_tasks
|
72
|
+
end
|
73
|
+
|
74
|
+
def init_tasks
|
75
|
+
@tasks=[]
|
76
|
+
end
|
77
|
+
|
78
|
+
## Comment on writing task:
|
79
|
+
## task is just a ruby hash containing at least :cmd key to describe the
|
80
|
+
## command type. Other keys are for completing the task related to command :cmd
|
81
|
+
## However, :source and :target are recommanded keynames for describing source and target filename
|
82
|
+
|
83
|
+
## possibly add condition to check before applying command+options
|
84
|
+
def add_task(task)
|
85
|
+
@tasks << task
|
86
|
+
end
|
87
|
+
|
88
|
+
def save_tasks(task_basename)
|
89
|
+
task_filename=task_basename+TASK_EXT+@tasks[0][:cmd].to_s
|
90
|
+
File.open(task_filename,"w") do |f|
|
91
|
+
f << @tasks.inspect
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def write_tasks(task_basename,tasks)
|
96
|
+
@tasks=tasks
|
97
|
+
save_tasks(task_basename)
|
98
|
+
end
|
99
|
+
|
100
|
+
## maybe to maintain only one task, remove current task when the new one is created
|
101
|
+
def read_tasks(task_filename)
|
102
|
+
@task_filename=task_filename
|
103
|
+
@workdir=File.dirname(@task_filename)
|
104
|
+
@tasks=Object.class_eval(File.read(@task_filename))
|
105
|
+
##p @tasks
|
106
|
+
if @tasks.length>=1
|
107
|
+
@task=@tasks.shift #first task to deal with
|
108
|
+
##p @task
|
109
|
+
make_task
|
110
|
+
if @tasks.length>=1
|
111
|
+
dirname=File.dirname(task_filename)
|
112
|
+
basename=File.basename(task_filename,".*")
|
113
|
+
task_basename=File.join(dirname,basename)
|
114
|
+
save_tasks(task_basename)
|
115
|
+
end
|
116
|
+
# remove since it is executed!
|
117
|
+
FileUtils.rm(task_filename)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
## if option to not remove taskfiles, this is a clean!
|
122
|
+
def task_clean_taskfiles(task_filename)
|
123
|
+
dirname=File.dirname(task_filename)
|
124
|
+
basename=File.basename(task_filename,TASK_EXT+"*")
|
125
|
+
|
126
|
+
Dir[File.join(dirname,basename+TASK_EXT+"*")].each do |f|
|
127
|
+
FileUtils.rm(f)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def load_user_task_plugins
|
132
|
+
Dir[File.join(DynTask.cfg_dir[:plugins],"*.rb")].each {|lib| require lib} if File.exists? DynTask.cfg_dir[:plugins]
|
133
|
+
end
|
134
|
+
|
135
|
+
def info_file(filename)
|
136
|
+
return {} unless filename
|
137
|
+
filename=File.join(@workdir,filename[1..-1]) if filename =~ /^\%/
|
138
|
+
|
139
|
+
##p [:info_file,filename]
|
140
|
+
|
141
|
+
res = {
|
142
|
+
dirname: File.dirname(filename),
|
143
|
+
extname: File.extname(filename),
|
144
|
+
basename: File.basename(filename,".*")
|
145
|
+
}
|
146
|
+
res[:filename]=res[:basename]+res[:extname]
|
147
|
+
res[:full_filename]=File.join(res[:dirname],res[:filename])
|
148
|
+
res
|
149
|
+
end
|
150
|
+
|
151
|
+
def make_task
|
152
|
+
|
153
|
+
##
|
154
|
+
@source=@task[:source] ? info_file(@task[:source]) : info_file(@task_filename)
|
155
|
+
#p [:info,@task[:source]]
|
156
|
+
|
157
|
+
#p [:source,@source]
|
158
|
+
@basename=@source[:basename]
|
159
|
+
@extname=@source[:extname]
|
160
|
+
@dirname=@source[:dirname]
|
161
|
+
@filename=@source[:filename]
|
162
|
+
|
163
|
+
@target=info_file(@task[:target]) if @task[:target]
|
164
|
+
|
165
|
+
cd_new
|
166
|
+
|
167
|
+
## This is a rule, if a @task contains both :source and :content
|
168
|
+
## then save the file @task[:source] with this content @task[:content]
|
169
|
+
## This is useful when delegating a next task in some dropbox-like environment: task and source are synchronized!
|
170
|
+
if @task[:content] and @task[:source]
|
171
|
+
#p [:content,@source[:filename]]
|
172
|
+
File.open(@source[:filename],"w") do |f|
|
173
|
+
f << @task[:content]
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
method("make_"+@task[:cmd].to_s).call
|
178
|
+
|
179
|
+
# case @task[:cmd].to_s
|
180
|
+
# when "sh"
|
181
|
+
# make_sh
|
182
|
+
# when "dyn"
|
183
|
+
# make_dyn
|
184
|
+
# when "pdflatex"
|
185
|
+
# make_pdf
|
186
|
+
# when "pandoc"
|
187
|
+
# make_pandoc
|
188
|
+
# when "png"
|
189
|
+
# make_png
|
190
|
+
# end
|
191
|
+
|
192
|
+
cd_old
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
def cd_new
|
197
|
+
@curdir=Dir.pwd
|
198
|
+
Dir.chdir(@workdir)
|
199
|
+
end
|
200
|
+
|
201
|
+
def cd_old
|
202
|
+
Dir.chdir(@curdir)
|
203
|
+
end
|
204
|
+
|
205
|
+
# make sh
|
206
|
+
|
207
|
+
def make_sh
|
208
|
+
shell_opts=@task[:shell_opts] || ""
|
209
|
+
script_opts=@task[:script_opts] || ""
|
210
|
+
`sh #{shell_opts} #{source[:filename]} #{script_opts}`
|
211
|
+
end
|
212
|
+
|
213
|
+
# make dyn
|
214
|
+
|
215
|
+
def make_dyn
|
216
|
+
opts = @task[:options] || ""
|
217
|
+
p [:dyn_cmd,"dyn #{opts} #{@filename}"]
|
218
|
+
`dyn #{opts} #{@filename}`
|
219
|
+
end
|
220
|
+
|
221
|
+
# make dyn-cli
|
222
|
+
|
223
|
+
def make_dyn_cli
|
224
|
+
p [:dyn_cmd_cli,"dyn-cli #{@filename} #{@target[:filename]} "]
|
225
|
+
`dyn-cli #{@filename} #{@target[:filename]}`
|
226
|
+
end
|
227
|
+
|
228
|
+
# make pdf
|
229
|
+
|
230
|
+
def make_pdflatex
|
231
|
+
#p [:task,@task]
|
232
|
+
nb_pass = @task[:nb_pass] || 1
|
233
|
+
echo_mode=@task[:echo] || false
|
234
|
+
|
235
|
+
## Just in case of synchronisation delay!
|
236
|
+
wait_time=@task[:wait_loop_time] || 0.5
|
237
|
+
wait_nb=@task[:wait_loop_nb] || 20
|
238
|
+
ok=DynTask.wait_for_file(@basename+".tex",wait_nb,wait_time)
|
239
|
+
|
240
|
+
if ok
|
241
|
+
nb_pass.times {|i| make_pdflatex_pass(echo_mode) }
|
242
|
+
else
|
243
|
+
puts "Warning: no way to apply pdflatex since #{@basename+'.tex'} does not exist!"
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
# make pdflatex
|
248
|
+
|
249
|
+
def make_pdflatex_pass(echo_mode=false)
|
250
|
+
unless File.exists? @basename+".tex"
|
251
|
+
msg="No pdflatex #{@basename} in #{@dirname} since file does not exist!"
|
252
|
+
print "\n==> "+msg
|
253
|
+
end
|
254
|
+
if File.read(@basename+".tex").empty?
|
255
|
+
msg="No pdflatex #{@basename} in #{@dirname} since empty file!"
|
256
|
+
print "\n==> "+msg
|
257
|
+
###$dyn_logger.write("ERROR pdflatex: "+msg+"\n") unless Dyndoc.cfg_dyn[:dyndoc_mode]==:normal
|
258
|
+
return ""
|
259
|
+
end
|
260
|
+
print "\n==> #{Dyndoc.pdflatex} #{@basename} in #{@dirname}"
|
261
|
+
|
262
|
+
out=`#{Dyndoc.pdflatex} -halt-on-error -file-line-error -interaction=nonstopmode #{@basename}`
|
263
|
+
out=out.b if RUBY_VERSION >= "1.9" #because out is not necessarily utf8 encoded
|
264
|
+
out=out.split("\n")
|
265
|
+
puts out if echo_mode
|
266
|
+
if out[-2].include? "Fatal error"
|
267
|
+
#if Dyndoc.cfg_dyn[:dyndoc_mode]==:normal
|
268
|
+
# print " -> NOT OKAY!!!\n==> "
|
269
|
+
# puts out[-4...-1]
|
270
|
+
# raise SystemExit
|
271
|
+
#end
|
272
|
+
else
|
273
|
+
print " -> OKAY!!!\n"
|
274
|
+
###@cfg[:created_docs] << @basename+".pdf" #( @dirname.empty? ? "" : @dirname+"/" ) + @basename+".pdf"
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
# make pandoc
|
279
|
+
|
280
|
+
def make_pandoc
|
281
|
+
|
282
|
+
cfg_pandoc = DynTask.cfg_pandoc[:extra]
|
283
|
+
|
284
|
+
format_doc,format_output=@task[:filter].split("2")
|
285
|
+
#
|
286
|
+
p [format_doc.to_s , format_output.to_s]
|
287
|
+
append_doc= @task[:append_doc] || ""
|
288
|
+
cmd_pandoc_options,pandoc_file_output,pandoc_file_input=[],"",nil
|
289
|
+
case @task[:filter]
|
290
|
+
when "md2odt"
|
291
|
+
cmd_pandoc_options = cfg_pandoc["md2odt"] || []
|
292
|
+
pandoc_file_output=@basename+append_doc+".odt"
|
293
|
+
when "md2docx"
|
294
|
+
cmd_pandoc_options= cfg_pandoc["md2docx"] || ["-s","-S"]
|
295
|
+
pandoc_file_output=@basename+append_doc+".docx"
|
296
|
+
when "tex2docx"
|
297
|
+
pandoc_file_input=@filename
|
298
|
+
cmd_pandoc_options= cfg_pandoc["tex2docx"] || ["-s"]
|
299
|
+
pandoc_file_output=@basename+append_doc+".docx"
|
300
|
+
when "md2beamer"
|
301
|
+
cmd_pandoc_options= cfg_pandoc["md2beamer"] || ["-t","beamer"]
|
302
|
+
pandoc_file_output=@basename+append_doc+".pdf"
|
303
|
+
when "md2dzslides"
|
304
|
+
cmd_pandoc_options= cfg_pandoc["md2dzslides"] || ["-s","--mathml","-i","-t","dzslides"]
|
305
|
+
pandoc_file_output=@basename+append_doc+".html"
|
306
|
+
when "md2slidy"
|
307
|
+
cmd_pandoc_options= cfg_pandoc["md2slidy"] || ["-s","--webtex","-i","-t","slidy"]
|
308
|
+
pandoc_file_output=@basename+append_doc+".html"
|
309
|
+
when "md2s5"
|
310
|
+
cmd_pandoc_options= cfg_pandoc["md2s5"] || ["-s","--self-contained","--webtex","-i","-t","s5"]
|
311
|
+
pandoc_file_output=@basename+append_doc+".html"
|
312
|
+
when "md2revealjs"
|
313
|
+
cmd_pandoc_options= cfg_pandoc["md2revealjs"] || ["-s","--self-contained","--webtex","-i","-t","revealjs"]
|
314
|
+
pandoc_file_output=@basename+append_doc+".html"
|
315
|
+
when "md2slideous"
|
316
|
+
cmd_pandoc_options=["-s","--mathjax","-i","-t","slideous"]
|
317
|
+
pandoc_file_output=@basename+append_doc+".html"
|
318
|
+
end
|
319
|
+
|
320
|
+
opts=cmd_pandoc_options #OBSOLETE NOW!: +["-o",pandoc_file_output]
|
321
|
+
|
322
|
+
output=if pandoc_file_input
|
323
|
+
opts << pandoc_file_input
|
324
|
+
Dyndoc::Converter.pandoc(nil,opts.join(" "))
|
325
|
+
else
|
326
|
+
@content=@task[:content]
|
327
|
+
#
|
328
|
+
p [:make_pandoc_content, opts.join(" "),@content]
|
329
|
+
Dyndoc::Converter.pandoc(@content,opts.join(" "))
|
330
|
+
end
|
331
|
+
|
332
|
+
if pandoc_file_output
|
333
|
+
File.open(pandoc_file_output,"w") do |f|
|
334
|
+
f << output
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
end
|
339
|
+
|
340
|
+
|
341
|
+
|
342
|
+
# make png
|
343
|
+
|
344
|
+
def make_png
|
345
|
+
make_dvipng
|
346
|
+
end
|
347
|
+
|
348
|
+
# make latex and dvipng
|
349
|
+
|
350
|
+
def make_dvipng
|
351
|
+
system "latex #{@basename}.tex"
|
352
|
+
print "\nlatex #{@basename}.tex -> ok\n"
|
353
|
+
system "dvipng --nogssafer #{@basename}.dvi -o #{@basename}.png"
|
354
|
+
print "\ndvipng --nogssafer #{@basename}.dvi -o #{@basename}.png -> ok\n"
|
355
|
+
end
|
356
|
+
|
357
|
+
# make ttm
|
358
|
+
|
359
|
+
def make_ttm
|
360
|
+
#puts "make_ttm:begin"
|
361
|
+
Dyndoc::Converter.ttm(File.read(@task[:filename]))
|
362
|
+
end
|
363
|
+
|
364
|
+
end
|
365
|
+
end
|
data/lib/dyntask.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'dyntask/task_mngr'
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dyntask-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- CQLS
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |2
|
14
|
+
Managing dyndoc tasks.
|
15
|
+
email: rdrouilh@gmail.com
|
16
|
+
executables:
|
17
|
+
- dyntask-server
|
18
|
+
- dyntask-reader
|
19
|
+
- dyntask-writer
|
20
|
+
- dyntask-init
|
21
|
+
extensions: []
|
22
|
+
extra_rdoc_files: []
|
23
|
+
files:
|
24
|
+
- lib/dyntask.rb
|
25
|
+
- lib/dyntask/task_mngr.rb
|
26
|
+
- bin/dyntask-server
|
27
|
+
- bin/dyntask-reader
|
28
|
+
- bin/dyntask-writer
|
29
|
+
- bin/dyntask-init
|
30
|
+
homepage: http://cqls.upmf-grenoble.fr
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
- GPL-2
|
34
|
+
metadata: {}
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements:
|
50
|
+
- none
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 2.0.14
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: dyntask system
|
56
|
+
test_files: []
|