dyndoc-ruby 1.2.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fb3f2c7f43257295393916babc73a24a01b5be83f2497be40f4d6516fc0a8e3
4
- data.tar.gz: 8a3d7d4ea1676d9192213b5062a7a25b80c8063c236e10d15378276bf5388ac8
3
+ metadata.gz: 9ead83e394d38dcc18626162ada3e9fc5077d1e5673a6992227811bfda153fd5
4
+ data.tar.gz: be7ce6c24f93febcfddf6822aaf30e4dad4978cbbc8e88e47c02d6902cff525e
5
5
  SHA512:
6
- metadata.gz: 925f6d28081d121501344010bdcda7bbe71fbff2d412ed42673952aae9ef0a91bd0f539323316cf324b5f7e30464e71c879bd5f6939070c4290f75ff94b21b59
7
- data.tar.gz: a5754bd8233d1b94ad5073bf1c69e28d62f7de77176a44b0c3353ac579d68a807762ac4437866b0fef71fef0cb66c73401a0a49c81e10d03336f3701042d5e20
6
+ metadata.gz: 924604a6f99dd1fc71ec45c2fb7d062b4564ae569bc8d6328ddbf2ae7e1ed88326aa607e8e62f7ba99f95ed68cef0e46732bcbc9468d8caa5ffa0b3abf039524
7
+ data.tar.gz: 015316465d1ac2db277a1390e4566a525e5005fdb45b9ea333e89b61014a8f870cdc6305a8301772bf5c8a70e5f0634704410fc26068f365fdd3da5c6356842d
data/bin/dyn-ctl CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'fileutils'
4
4
 
5
- SRVS=["dyn-srv","dyn-html","dyn-http"]
5
+ SRVS=["dyn-srv","dyn-html","dyn-http","dyn-task"]
6
6
  CMD="dyn-ctl"
7
7
  DYNCTL_PLIST=File.expand_path("~/Library/LaunchAgents/local.dyn-ctl.plist")
8
8
 
data/bin/dyn-task ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ require 'dyndoc-tasks'
3
+
4
+ if ["--no-forever","--no-daemon"].include? ARGV[0]
5
+ cfg={}
6
+ cfg[:dyntasks_root]=ARGV[1] if ARGV[1]
7
+ DyndocTasks::filewatcher(cfg)
8
+ else
9
+ require 'daemons'
10
+ require 'dyndoc/init/home'
11
+ require 'fileutils'
12
+
13
+ dir_pids=File.join(Dyndoc.home,"pids")
14
+ FileUtils.mkdir_p dir_pids
15
+ Daemons.run_proc('dyn-task',{dir: dir_pids}) do
16
+ DyndocTasks::filewatcher
17
+ end
18
+
19
+ end
data/bin/dyn-yml CHANGED
@@ -98,84 +98,84 @@ end.parse!(args)
98
98
  doc=args[0]
99
99
 
100
100
  doc += "_dyn.yml" unless doc =~ /_dyn.yml$/
101
- require 'yaml'
102
- require 'fileutils'
103
-
104
- doc =~ /^(.*)_dyn\.yml$/
105
- docname=$1
106
-
107
- cfg_lines=File.readlines(doc)
108
- i=0
109
- i += 1 if cfg_lines[i][0,3] == "---"
110
-
111
- if cfg_lines[i][0,9] == "dyntask: "
112
- ## regular _dyn.yml file
113
- cfg_yml=YAML::load(cfg_lines.join("\n"))
114
- else
115
- cfg_txt = cfg_lines[0..i].join("\n")
116
- cfg_lines[(i+1)..-1].each do |line|
117
- if line[0,2] == " "
118
- cfg_txt << line
119
- else
120
- tn,td=line.split(":")
121
- cfg_txt << tn.strip << ": |\n"
122
- cfg_txt << " " << td.strip << "\n"
123
- end
124
- end
125
- puts "ici\n"
126
- puts cfg_txt
127
- cfg_yml=YAML::load(cfg_txt.strip)
128
- end
129
-
130
-
131
- unless cfg_yml["dyntask"]
132
- #attempt to know if format is the simplified one for workflow
133
- ks=cfg_yml.keys
134
- cfg2={"dyntask" => "workflow", "params" => {"id" => ks[0], "workdir" => cfg_yml[ks[0]]}}
135
- tasks={}
136
- ks[1..-1].each do |t|
137
- kt,*pt=cfg_yml[t].strip.split("\n")
138
- wt,tn=kt.strip.split("->").map{|e| e.strip if e}
139
- if tn
140
- tasks[t]={"dyntask" => tn}
141
- wt="init" if wt.empty?
142
- tasks[t]["wait"]=wt
143
- pt=YAML::load(pt.join("\n"))
144
- tasks[t]["params"]=pt
145
- else
146
- puts "Warning: task "+ t + " not considered because malformed"
147
- end
148
- end
149
- cfg2["params"]["tasks"]=tasks
150
- cfg_yml=cfg2
151
- end
152
-
153
- dyntaskname=cfg_yml["dyntask"]
154
-
155
- if dyntaskname
156
- puts dyntaskname
157
- dyntaskname += "_task.dyn" unless dyntaskname=~/_task.dyn$/
158
- dyntaskpath=dyntaskname
159
- is_dyntask=File.exists? dyntaskpath
160
- unless is_dyntask
161
- dyntaskpath=File.join(ENV["HOME"],"dyndoc","tasks",dyntaskname)
162
- is_dyntask=File.exists? dyntaskpath
163
- end
164
- unless is_dyntask
165
- share_path=File.expand_path("../../share", __FILE__)
166
- dyntaskpath=File.join(share_path,"dyntasks",dyntaskname)
167
- is_dyntask=File.exists? dyntaskpath
168
- end
169
- if is_dyntask
170
- dynfile=docname+".dyn"
171
- FileUtils.cp dyntaskpath, dynfile
172
- $params=cfg_yml["params"]
173
- $dyntask=dyntaskname
174
- cfg_yml["params"].each do |key,val|
175
- Settings["cfg_dyn.user_input"] << [key,val]
176
- end
177
-
178
- d=Dyndoc::TemplateDocument.new(dynfile)
179
- d.make_all
180
- end
181
- end
101
+
102
+ require 'dyndoc-tasks'
103
+
104
+ DyndocTasks.dyn_yml doc
105
+
106
+ # require 'yaml'
107
+ # require 'fileutils'
108
+
109
+ # cfg_lines=File.readlines(doc)
110
+ # i=0
111
+ # i += 1 if cfg_lines[i][0,3] == "---"
112
+
113
+ # if cfg_lines[i][0,9] == "dyntask: "
114
+ # ## regular _dyn.yml file
115
+ # cfg_yml=YAML::load(cfg_lines.join("\n"))
116
+ # else
117
+ # cfg_txt = cfg_lines[0..i].join("\n")
118
+ # cfg_lines[(i+1)..-1].each do |line|
119
+ # if line[0,2] == " "
120
+ # cfg_txt << line
121
+ # else
122
+ # tn,td=line.split(":")
123
+ # cfg_txt << tn.strip << ": |\n"
124
+ # cfg_txt << " " << td.strip << "\n"
125
+ # end
126
+ # end
127
+ # cfg_yml=YAML::load(cfg_txt.strip)
128
+ # end
129
+
130
+
131
+ # unless cfg_yml["dyntask"]
132
+ # #attempt to know if format is the simplified one for workflow
133
+ # ks=cfg_yml.keys
134
+ # cfg2={"dyntask" => "workflow", "params" => {"id" => ks[0], "workdir" => cfg_yml[ks[0]]}}
135
+ # tasks={}
136
+ # ks[1..-1].each do |t|
137
+ # kt,*pt=cfg_yml[t].strip.split("\n")
138
+ # wt,tn=kt.strip.split("->").map{|e| e.strip if e}
139
+ # if tn
140
+ # tasks[t]={"dyntask" => tn}
141
+ # wt="init" if wt.empty?
142
+ # tasks[t]["wait"]=wt
143
+ # pt=YAML::load(pt.join("\n"))
144
+ # tasks[t]["params"]=pt
145
+ # else
146
+ # puts "Warning: task "+ t + " not considered because malformed"
147
+ # end
148
+ # end
149
+ # cfg2["params"]["tasks"]=tasks
150
+ # cfg_yml=cfg2
151
+ # end
152
+
153
+ # dyntaskname=cfg_yml["dyntask"]
154
+
155
+ # if dyntaskname
156
+ # puts dyntaskname
157
+ # dyntaskname += "_task.dyn" unless dyntaskname=~/_task.dyn$/
158
+ # dyntaskpath=dyntaskname
159
+ # is_dyntask=File.exists? dyntaskpath
160
+ # unless is_dyntask
161
+ # dyntaskpath=File.join(ENV["HOME"],"dyndoc","tasks",dyntaskname)
162
+ # is_dyntask=File.exists? dyntaskpath
163
+ # end
164
+ # unless is_dyntask
165
+ # share_path=File.expand_path("../../share", __FILE__)
166
+ # dyntaskpath=File.join(share_path,"dyntasks",dyntaskname)
167
+ # is_dyntask=File.exists? dyntaskpath
168
+ # end
169
+ # if is_dyntask
170
+ # dynfile=docname+".dyn"
171
+ # FileUtils.cp dyntaskpath, dynfile
172
+ # $params=cfg_yml["params"]
173
+ # $dyntask=dyntaskname
174
+ # cfg_yml["params"].each do |key,val|
175
+ # Settings["cfg_dyn.user_input"] << [key,val]
176
+ # end
177
+
178
+ # d=Dyndoc::TemplateDocument.new(dynfile)
179
+ # d.make_all
180
+ # end
181
+ # end
@@ -255,8 +255,9 @@ module Dyndoc
255
255
  options={first: true}
256
256
  ## To put inside yaml config file!
257
257
  root ||= cfg["root"] || HtmlServers.cfg["root"] || File.join(ENV["HOME"],"RCqls","RodaServer")
258
- dyn_root = cfg["dyn_root"] || HtmlServers.cfg["dyn_root"] || File.join(root ,"edit")
258
+ dyn_root = cfg["dyn_root"] || HtmlServers.cfg["dyn_root"] || File.join(root ,"edit")
259
259
  public_root = cfg["public_root"] || HtmlServers.cfg["public_root"] || File.join(root ,"public")
260
+ dyn_public_edit_root = File.join(public_root,"users","*",".edit","**","*.dyn")
260
261
  pages_root = File.join(public_root ,"pages")
261
262
  current_email = cfg["email"] || HtmlServers.cfg["email"] || "rdrouilh@gmail.com" #default email user can be overriden by -u option
262
263
  host=(cfg["html-srv-host"] || HtmlServers.cfg["html-srv-host"] || "http://localhost").to_s
@@ -269,9 +270,9 @@ module Dyndoc
269
270
  user: nil #current_email
270
271
  }
271
272
 
272
- puts "watching "+ dyn_root
273
+ puts "watching "+ dyn_root+ " and " + dyn_public_edit_root
273
274
  old_html_file=""
274
- ::FileWatcher.new(dyn_root).watch() do |filename, event|
275
+ ::FileWatcher.new([dyn_root,dyn_public_edit_root]).watch() do |filename, event|
275
276
  ##p [:filename,filename,event]
276
277
  if [:changed,:updated,:new].include? event and File.extname(filename) == ".dyn"
277
278
  ##p [:filename_event,event,filename]
@@ -279,7 +280,19 @@ module Dyndoc
279
280
  ## do not process preload, postload, lib and layout files
280
281
  unless filename =~ /(?:_pre|_post|_lib|_layout)\.dyn$/
281
282
  ## find dyn_file (relative path from root)
282
- dyn_file="/"+Pathname(filename).relative_path_from(Pathname(dyn_root)).to_s
283
+ dyn_public_edit_file=""
284
+ dyn_file=Pathname(filename).relative_path_from(Pathname(dyn_root)).to_s
285
+ if dyn_file[0,2] == '..' # try the public_root
286
+ dyn_public_edit_file=Pathname(filename).relative_path_from(Pathname(public_root)).to_s
287
+ dyn_public_edit_file=dyn_public_edit_file.split("/")
288
+ if dyn_public_edit_file[0]=="users" and dyn_public_edit_file[2]==".edit"
289
+ dyn_file="/"+File.join(dyn_public_edit_file[1],dyn_public_edit_file[3..-1])
290
+ dyn_public_edit_file=dyn_public_edit_file.join("/")
291
+ end
292
+ else
293
+ dyn_file="/"+dyn_file
294
+ end
295
+
283
296
  unless HtmlServers.unwatched?(dyn_file[1..-1]).empty?
284
297
  if RUBY_PLATFORM =~ /darwin/
285
298
  `osascript -e 'display notification "Warning: #{dyn_file} unwatched by #{HtmlServers.unwatched?(dyn_file[1..-1])}!" with title "dyn-ctl unwatch"'`
@@ -303,7 +316,7 @@ module Dyndoc
303
316
  end
304
317
  html_file = "erb"+$1
305
318
  end
306
- puts dyn_file[1..-1]+" processed => "+html_file+" created!"
319
+ puts dyn_file[1..-1]+(dyn_public_edit_file.empty? ? "" : "*")+" processed => "+html_file+" created!"
307
320
  options[:first] = html_file != old_html_file
308
321
  if html_file != old_html_file
309
322
  old_html_file = html_file
@@ -0,0 +1,130 @@
1
+ require 'filewatcher'
2
+ #if RUBY_VERSION >= "2.4"
3
+ class FileWatcher < Filewatcher
4
+ end
5
+ #end
6
+
7
+
8
+ module DyndocTasks
9
+
10
+ def DyndocTasks.dyn_yml(doc)
11
+
12
+ require 'yaml'
13
+ require 'fileutils'
14
+
15
+ doc =~ /^(.*)_dyn\.yml$/
16
+ docname=$1
17
+
18
+ cfg_lines=File.readlines(doc)
19
+ i=0
20
+ i += 1 if cfg_lines[i][0,3] == "---"
21
+
22
+ if cfg_lines[i][0,9] == "dyntask: "
23
+ ## regular _dyn.yml file
24
+ cfg_yml=YAML::load(cfg_lines.join(""))
25
+ else
26
+ cfg_txt = cfg_lines[0..i].join("\n")
27
+ ## deal with possible common params
28
+ cfg_common=""
29
+ while cfg_lines[i+1][0,2] == " "
30
+ i += 1
31
+ cfg_common << cfg_lines[i]
32
+ end
33
+ unless cfg_common.empty?
34
+ cfg_txt << "common:\n" << cfg_common
35
+ end
36
+ ## deal with tasks
37
+ cfg_lines[(i+1)..-1].each do |line|
38
+ if line[0,2] == " "
39
+ cfg_txt << line
40
+ else
41
+ tn,td=line.split(":")
42
+ cfg_txt << tn.strip << ": |\n"
43
+ cfg_txt << " " << td.strip << "\n"
44
+ end
45
+ end
46
+ ##DEBUG: puts cfg_txt.strip
47
+ cfg_yml=YAML::load(cfg_txt.strip)
48
+ end
49
+
50
+
51
+ unless cfg_yml["dyntask"]
52
+ #attempt to know if format is the simplified one for workflow
53
+ ks=cfg_yml.keys
54
+ cfg2={"dyntask" => "workflow", "params" => {"id" => ks[0], "workdir" => cfg_yml[ks[0]]}}
55
+ tasks={}
56
+ i=1
57
+ if ks[1] == "common"
58
+ i+=1
59
+ cfg2["params"]["params"]=cfg_yml["common"] # common params for tasks
60
+ end
61
+ ks[i..-1].each do |t|
62
+ kt,*pt=cfg_yml[t].strip.split("\n")
63
+ wt,tn=kt.strip.split("->").map{|e| e.strip if e}
64
+ if tn
65
+ tasks[t]={"dyntask" => tn}
66
+ wt="init" if wt.empty?
67
+ tasks[t]["wait"]=wt
68
+ pt=YAML::load(pt.join("\n"))
69
+ tasks[t]["params"]=pt
70
+ else
71
+ puts "Warning: task "+ t + " not considered because malformed"
72
+ end
73
+ end
74
+ cfg2["params"]["tasks"]=tasks
75
+ cfg_yml=cfg2
76
+ end
77
+
78
+ dyntaskname=cfg_yml["dyntask"]
79
+
80
+ if dyntaskname
81
+ puts dyntaskname
82
+ ##DEBUG: p [:cfg_yml,cfg_yml]
83
+ dyntaskname += "_task.dyn" unless dyntaskname=~/_task.dyn$/
84
+ dyntaskpath=dyntaskname
85
+ is_dyntask=File.exists? dyntaskpath
86
+ unless is_dyntask
87
+ dyntaskpath=File.join(ENV["HOME"],"dyndoc","tasks",dyntaskname)
88
+ is_dyntask=File.exists? dyntaskpath
89
+ end
90
+ unless is_dyntask
91
+ share_path=File.expand_path("../../share", __FILE__)
92
+ dyntaskpath=File.join(share_path,"dyntasks",dyntaskname)
93
+ is_dyntask=File.exists? dyntaskpath
94
+ end
95
+ if is_dyntask
96
+ dynfile=docname+".dyn"
97
+ FileUtils.cp dyntaskpath, dynfile
98
+ $params=cfg_yml["params"]
99
+ $dyntask=dyntaskname
100
+ cfg_yml["params"].each do |key,val|
101
+ Settings["cfg_dyn.user_input"] << [key,val]
102
+ end
103
+
104
+ d=Dyndoc::TemplateDocument.new(dynfile)
105
+ d.make_all
106
+ end
107
+ end
108
+ end
109
+
110
+ def DyndocTasks.filewatcher(cfg={}) #cfg
111
+ require 'dyndoc/document'
112
+
113
+ Settings['cfg_dyn.ruby_only']=true
114
+ Settings["cfg_dyn.model_doc"] = "Content"
115
+ Settings["cfg_dyn.exec_mode"] = "yes"
116
+
117
+ require 'dyndoc-linter'
118
+
119
+ dyntasks_root=cfg["dyntasks_root"] || File.join(ENV["HOME"],".dyndoc-world","reactzone")
120
+
121
+ puts "watching tasks inside "+ dyntasks_root
122
+ ::FileWatcher.new(dyntasks_root).watch() do |filename, event|
123
+ ##DEBUG:
124
+ puts filename + "->" + event.to_s+"\n"
125
+ if [:changed,:updated,:new].include? event and File.extname(filename) == ".yml"
126
+ DyndocTasks.dyn_yml filename
127
+ end
128
+ end
129
+ end
130
+ end
@@ -46,6 +46,7 @@ shscript=""
46
46
  prj_id=#{=prj_id}
47
47
  # Creation of dyn tasks (_dyn.yml files)
48
48
  tasks=$params["tasks"]
49
+ common_params=$params["params"]
49
50
  #p [:tasks,tasks.keys]
50
51
  ## shell fcts
51
52
  tasks.keys.each do |task| #
@@ -69,6 +70,9 @@ tasks.keys.each do |task| #
69
70
  dyntask=(tasks[task].is_a? String) ? tasks[tasks[task]] : tasks[task]
70
71
  dyntask=dyntask.select{|k| ["dyntask","params"].include? k}
71
72
  #p [:dyntask,dyntask,dyntask.empty?]
73
+ if common_params
74
+ dyntask["params"] = common_params.dup.merge dyntask["params"]
75
+ end
72
76
  File.open(task_yml,"w") {|f| f << dyntask.to_yaml } unless dyntask.empty?
73
77
  rescue
74
78
  puts "Task not created\n"
@@ -0,0 +1,12 @@
1
+ [Unit]
2
+ Description=Dyndoc Task service
3
+
4
+ [Service]
5
+ User=conf
6
+ ExecStart=/usr/local/bin/dyn-task run
7
+ Restart=on-failure
8
+ SuccessExitStatus=3 4
9
+ RestartForceExitStatus=3 4
10
+
11
+ [Install]
12
+ WantedBy=default.target
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dyndoc-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - RCqls
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-08 00:00:00.000000000 Z
11
+ date: 2019-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: R4rb
@@ -178,6 +178,7 @@ executables:
178
178
  - dpm
179
179
  - dyn-html
180
180
  - dyn-http
181
+ - dyn-task
181
182
  - dyn-init
182
183
  - dyn-scan
183
184
  - dyn-lint
@@ -201,6 +202,7 @@ files:
201
202
  - bin/dyn-lint
202
203
  - bin/dyn-scan
203
204
  - bin/dyn-srv
205
+ - bin/dyn-task
204
206
  - bin/dyn-x
205
207
  - bin/dyn-yml
206
208
  - install/README.md
@@ -210,6 +212,7 @@ files:
210
212
  - lib/dyndoc-edit.rb
211
213
  - lib/dyndoc-html-servers.rb
212
214
  - lib/dyndoc-linter.rb
215
+ - lib/dyndoc-tasks.rb
213
216
  - lib/dyndoc/cli/interactive-client.rb
214
217
  - lib/dyndoc/srv/interactive-server.rb
215
218
  - lib/dyndoc/srv/tilt.rb
@@ -236,6 +239,7 @@ files:
236
239
  - share/etc/systemd/dyn-html.service
237
240
  - share/etc/systemd/dyn-http.service
238
241
  - share/etc/systemd/dyn-srv.service
242
+ - share/etc/systemd/dyn-task.service
239
243
  - share/etc/uv/render/README
240
244
  - share/etc/uv/render/latex/-h.yaml
241
245
  - share/etc/uv/render/latex/active4d.render