dyndoc-ruby 0.9.11 → 0.9.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e794529323a9dab819dac71b1b6de1e6eceaa36
4
- data.tar.gz: d49314105fb3bdaa7be8c583b488631c1fe413a5
3
+ metadata.gz: b521fb0e195336e4655811606b2db0dbfadf7304
4
+ data.tar.gz: 39675c51acf5d462806dc98edf8342a345f78731
5
5
  SHA512:
6
- metadata.gz: 8d232669a147dab82f11839801dd78c5183deb154969a3678fad3e445fe159138efa55868a33cd5fbc0e757e6aaf21f11d1c78b1f6b3d1cea687cd1d2f1ea6b0
7
- data.tar.gz: 7f525ea4329a3a372d71cf14e68df190d886dd33a2e75e1f0cd52a78bd28e392f0c59a06dbb3a9d085ff3d1ba547f6e1943c0d83c07db6c462ce621cfb58b59c
6
+ metadata.gz: 5cd340b92b6bde1373fa311495b4644e49b53e5ccc7ffc64769e53a6653a4daefa570539fdb9a295519906679072215f31199dc0817114bfda3e776225d94084
7
+ data.tar.gz: 4ff34548e8446d36ed38a9d13a3de25d282a461db22bee7f52048373fb495a96148f123744cc385b106aa105737ff0999c171985a0231be50205a409dfd98676
data/bin/dyn-4ever ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'forever'
4
+ require 'fileutils'
5
+
6
+ CMD="dyn-4ever"
7
+ SRVS=["dyn-srv","dyn-html","dyn-http"]
8
+ DYN4EVER_DIR=File.join(ENV["HOME"],"dyndoc","dyn-4ever")
9
+ FileUtils.mkdir_p DYN4EVER_DIR
10
+
11
+ Forever.run do
12
+ dir DYN4EVER_DIR
13
+ every 10.seconds do
14
+ status=SRVS.map do |srv|
15
+ `#{srv} status`.empty?
16
+ end
17
+ if status.any?
18
+ message="at #{Time.now}: " + status.each_with_index.map { |e,i| e ? SRVS[i] : nil}.compact.join("+") + " stopped and restarted!"
19
+ if RUBY_PLATFORM =~ /darwin/
20
+ ##p lint_error
21
+ cmd_to_display="display notification \"#{message}\" with title \"dyn status\""
22
+ `osascript -e '#{cmd_to_display}'`
23
+ end
24
+ puts message
25
+ status.each_with_index { |e,i| `#{SRVS[i]} start` if e }
26
+ end
27
+ end
28
+ after :all do
29
+ SRVS.each {|srv| `#{srv} stop`}
30
+ end
31
+ end
data/bin/dyn-ctl ADDED
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+
5
+ SRVS=["dyn-srv","dyn-html","dyn-http"]
6
+ CMD="dyn-ctl"
7
+ DYNCTL_PLIST=File.expand_path("~/Library/LaunchAgents/local.dyn-ctl.plist")
8
+
9
+
10
+
11
+ case (ARGV[0] || "start").downcase
12
+ when "start"
13
+ status=SRVS.map do |srv|
14
+ `#{srv} status`.empty?
15
+ end
16
+ if status.any?
17
+ message="at #{Time.now}: " + status.each_with_index.map { |e,i| e ? SRVS[i] : nil}.compact.join("+") + " stopped and restarted!"
18
+ if RUBY_PLATFORM =~ /darwin/
19
+ ##p lint_error
20
+ cmd_to_display="display notification \"#{message}\" with title \"dyn status\""
21
+ `osascript -e '#{cmd_to_display}'`
22
+ end
23
+ puts message
24
+ status.each_with_index { |e,i| `#{SRVS[i]} start` if e }
25
+ end
26
+
27
+ when "stop"
28
+ SRVS.each {|srv| `#{srv} stop`}
29
+
30
+ when "new"
31
+
32
+ if RUBY_PLATFORM =~ /darwin/
33
+ ## launchctl seems to work but actually: dyn-srv, dyn-html and dyn-http started but noit properly
34
+
35
+ DYNCTL_ERR_FILE = File.join(ENV["HOME"],"dyndoc","log","")+CMD+".err"
36
+ DYNCTL_OUT_FILE = File.join(ENV["HOME"],"dyndoc","log","")+CMD+".out"
37
+ FileUtils.mkdir_p File.join(ENV["HOME"],"dyndoc",'log')
38
+
39
+ unless File.exists? DYNCTL_PLIST
40
+ plist= <<-END.sub(/CMD/,CMD).sub(/DYN_CMD/,`which #{CMD}`.strip).sub(/ERR_FILE/,DYNCTL_ERR_FILE).sub(/OUT_FILE/,DYNCTL_OUT_FILE).sub(/DYN_PATH/,ENV["PATH"]).sub(/DYN_LANG/,ENV["LANG"])
41
+ <?xml version="1.0" encoding="UTF-8"?>
42
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
43
+ <plist version="1.0">
44
+ <dict>
45
+ <key>EnvironmentVariables</key>
46
+ <dict>
47
+ <key>PATH</key>
48
+ <string>DYN_PATH</string>
49
+ <key>LANG</key>
50
+ <string>DYN_LANG</string>
51
+ </dict>
52
+ <key>Label</key>
53
+ <string>CMD</string>
54
+ <key>ProgramArguments</key>
55
+ <array>
56
+ <string>DYN_CMD</string>
57
+ </array>
58
+ <key>RunAtLoad</key>
59
+ <true/>
60
+ <key>StartInterval</key>
61
+ <integer>10</integer>
62
+ <key>StandardErrorPath</key>
63
+ <string>ERR_FILE</string>
64
+ <key>StandardOutPath</key>
65
+ <string>OUT_FILE</string>
66
+ </dict>
67
+ </plist>
68
+ END
69
+ File.open(DYNCTL_PLIST,"w") do |f|
70
+ f << plist
71
+ end
72
+ end
73
+ end
74
+
75
+ when "load"
76
+ `launchctl load #{DYNCTL_PLIST}` if RUBY_PLATFORM =~ /darwin/ and File.exists? DYNCTL_PLIST
77
+
78
+ when "unload"
79
+ `launchctl unload #{DYNCTL_PLIST}` if RUBY_PLATFORM =~ /darwin/ and File.exists? DYNCTL_PLIST
80
+ when "delete"
81
+ if RUBY_PLATFORM =~ /darwin/ and File.exists? DYNCTL_PLIST
82
+ `launchctl unload #{DYNCTL_PLIST}`
83
+ FileUtils.rm DYNCTL_PLIST
84
+ end
85
+
86
+ end
@@ -67,7 +67,8 @@ module Dyndoc
67
67
 
68
68
  return unless opts[:dyn_root]
69
69
 
70
- dyn_libs,dyn_tags,dyn_layout,dyn_pre_code,dyn_post_code=nil,nil,nil,nil,nil
70
+ dyn_libs,dyn_tags,dyn_layout=nil,nil,nil
71
+ dyn_pre_code,dyn_post_code="",""
71
72
 
72
73
  ## requirement: dyn_file is provided relatively to the opts[:dyn_root] (for security reason too)
73
74
 
@@ -112,16 +113,6 @@ module Dyndoc
112
113
  ## add info related to dyn file
113
114
  cfg.merge!(cfg_files)
114
115
 
115
- ## Dyn layout
116
- dyn_layout=dyn_file[0...i]+"_layout.dyn" if File.exist? dyn_file[0...i]+"_layout.dyn"
117
-
118
- ## Dyn pre
119
- dyn_pre_code=File.read(dyn_file[0...i]+"_pre.dyn") if File.exist? dyn_file[0...i]+"_pre.dyn"
120
-
121
- ## Dyn post
122
- dyn_post_code=File.read(dyn_file[0...i]+"_post.dyn") if File.exist? dyn_file[0...i]+"_post.dyn"
123
-
124
-
125
116
  if File.exist? dyn_file[0...i]+".dyn_cfg" and (yml=YAML::load_file(dyn_file[0...i]+".dyn_cfg"))
126
117
  cfg.merge!(yml)
127
118
  else # try do find (in the Zope spirit) a config file in the nearest folder
@@ -145,40 +136,82 @@ module Dyndoc
145
136
  # dyn_root can be overwritten by cfg
146
137
  dyn_root= cfg["dyn_root"] || opts[:dyn_root] || File.expand_path("..",dyn_file)
147
138
  html_root= cfg["html_root"] || opts[:html_root] || File.expand_path("..",dyn_file)
139
+ sys_root = cfg["sys_root"] || opts[:sys_root] || File.expand_path('..',dyn_root)
140
+ ##p [:sys_root,dyn_root,sys_root]
141
+
142
+ ## Dyn Model: generally helps to define a style (layout, preload, postload)
143
+ if cfg["model"]
144
+ ## do not aggregate layout
145
+ cfg["layout"] = cfg["model"]
146
+ ## aggregate model to pre and load
147
+ cfg["pre"] = ([cfg["model"]] + ((cfg["pre"] || "").split(","))).join(",")
148
+ cfg["post"] = ([cfg["model"]] + ((cfg["post"] || "").split(","))).join(",")
149
+ end
148
150
 
149
- cfg["layout"] = cfg["pre"] = cfg["post"] = cfg["model"] if cfg["model"]
150
-
151
+ ## Dyn layout
152
+ dyn_layout=dyn_file[0...i]+"_layout.dyn" if File.exist? dyn_file[0...i]+"_layout.dyn"
151
153
  if cfg["layout"]
152
- if cfg["layout"][0] == "~" #user mode
154
+ if cfg["layout"][-4,4] != ".dyn" ## Main use now! Added to put layout outside /edit folder
155
+ if cfg["layout"][0] == "~"
156
+ user,*pa=cfg["layout"][1..-1].split("/")
157
+ cfg_tmp=File.join(sys_root,"public","users",user,"layout",pa)+".dyn"
158
+ else
159
+ cfg_tmp=File.join(sys_root,"system","layout",cfg["layout"]+".dyn")
160
+ end
161
+ elsif cfg["layout"][0] == "~" #user mode
153
162
  cfg_tmp=File.join(opts[:dyn_root],'users',cfg["layout"][1] == "/" ? File.join(opts[:user],cfg["layout"][1..-1]) : cfg["layout"][1..-1])
154
163
  else
155
164
  cfg_tmp=File.join(dyn_root,cfg["layout"][0] == "/" ? cfg["layout"][1..-1] : ["layout",cfg["layout"]])
156
165
  end
166
+ ##p [:cfg_tmp_layout,cfg_tmp]
157
167
  cfg_tmp+= ".dyn" if File.extname(cfg_tmp).empty?
158
168
  ##Dyndoc.warn :layout,cfg_tmp
159
169
  dyn_layout=cfg_tmp if !dyn_layout and File.exist? cfg_tmp
160
170
  end
171
+
172
+ ## Dyn pre
161
173
  if cfg["pre"]
162
- if cfg["pre"][0] == "~" #user mode
163
- cfg_tmp=File.join(opts[:dyn_root],'users',cfg["pre"][0] == "/" ? cfg["pre"][1..-1] : ["pre",cfg["pre"]])
164
- else
165
- #cfg_tmp=File.join(dyn_root,cfg["pre"])
166
- cfg_tmp=File.join(dyn_root,cfg["pre"][0] == "/" ? cfg["pre"][1..-1] : ["preload",cfg["pre"]])
174
+ cfg["pre"].split(",").map{|e| e.strip}.each do |pre|
175
+ if pre[-4,4] != ".dyn" ## Main use now! Added to put preload outside /edit folder
176
+ if pre[0] == "~"
177
+ user,*pa=pre[1..-1].split("/")
178
+ cfg_tmp=File.join(sys_root,"public","users",user,"preload",pa)+".dyn"
179
+ else
180
+ cfg_tmp=File.join(sys_root,"system","preload",pre+".dyn")
181
+ end
182
+ elsif pre[0] == "~" #user mode
183
+ cfg_tmp=File.join(opts[:dyn_root],'users',pre[0] == "/" ? pre[1..-1] : ["pre",pre])
184
+ else
185
+ #cfg_tmp=File.join(dyn_root,pre)
186
+ cfg_tmp=File.join(dyn_root,pre[0] == "/" ? pre[1..-1] : ["preload",pre])
187
+ end
188
+ cfg_tmp+= ".dyn" if File.extname(cfg_tmp).empty?
189
+ dyn_pre_code += File.read(cfg_tmp) if File.exist? cfg_tmp
167
190
  end
168
- cfg_tmp+= ".dyn" if File.extname(cfg_tmp).empty?
169
- dyn_pre_code=File.read(cfg_tmp) if !dyn_pre_code and File.exist? cfg_tmp
170
191
  end
192
+ dyn_pre_code += File.read(dyn_file[0...i]+"_pre.dyn") if File.exist? dyn_file[0...i]+"_pre.dyn"
171
193
 
194
+ ## Dyn post
172
195
  if cfg["post"]
173
- if cfg["post"][0] == "~" #user mode
174
- cfg_tmp=File.join(opts[:dyn_root],'users',cfg["post"][0] == "/" ? cfg["post"][1..-1] : ["post",cfg["post"]])
175
- else
176
- #cfg_tmp=File.join(dyn_root,cfg["post"])
177
- cfg_tmp=File.join(dyn_root,cfg["post"][0] == "/" ? cfg["post"][1..-1] : ["postload",cfg["post"]])
196
+ cfg["post"].split(",").map{|e| e.strip}.each do |post|
197
+ if post[-4,4] != ".dyn" ## Main use now! Added to put postload outside /edit folder
198
+ if post[0] == "~"
199
+ user,*pa=post[1..-1].split("/")
200
+ cfg_tmp=File.join(sys_root,"public","users",user,"postload",pa)+".dyn"
201
+ else
202
+ cfg_tmp=File.join(sys_root,"system","postload",post+".dyn")
203
+ end
204
+ elsif post[0] == "~" #user mode
205
+ cfg_tmp=File.join(opts[:dyn_root],'users',post[0] == "/" ? post[1..-1] : ["post",post])
206
+ else
207
+ #cfg_tmp=File.join(dyn_root,post)
208
+ cfg_tmp=File.join(dyn_root,post[0] == "/" ? post[1..-1] : ["postload",post])
209
+ end
210
+ cfg_tmp+= ".dyn" if File.extname(cfg_tmp).empty?
211
+ dyn_post_code += File.read(cfg_tmp) if File.exist? cfg_tmp
178
212
  end
179
- cfg_tmp+= ".dyn" if File.extname(cfg_tmp).empty?
180
- dyn_post_code=File.read(cfg_tmp) if !dyn_post_code and File.exist? cfg_tmp
181
213
  end
214
+ dyn_post_code += File.read(dyn_file[0...i]+"_post.dyn") if File.exist? dyn_file[0...i]+"_post.dyn"
182
215
 
183
216
  ## deal with html_file
184
217
  html_file=File.join(html_root,cfg["html_file"] || html_file)
@@ -217,6 +250,8 @@ module Dyndoc
217
250
  ## add path for user
218
251
  code_path = "[#path]"+File.join(opts[:dyn_root],'users',opts[:user],"dynlib")
219
252
  code_path << "\n" << File.join(opts[:dyn_root],'users',opts[:user])
253
+ code_path << "\n" << File.join(sys_root,'public','users')
254
+ code_path << "\n" << File.join(sys_root,'system','dynlib')
220
255
  code_path << "\n" << File.join(opts[:dyn_root],'dynlib')
221
256
  code_path << "\n" << opts[:dyn_root] << "\n"
222
257
  code_path << "[#main][#<]\n"
@@ -231,7 +266,7 @@ module Dyndoc
231
266
  else
232
267
  (opts[:current_tags] || html_files.keys[1..-1]).each do |doc_tag|
233
268
  html_file=File.join(html_root,["users",opts[:user]] || [],cfg_files[:urls][doc_tag])
234
- p [:html_multi,doc_tag,html_file] #,code.gsub(/__ALL_DOC_TAG__/,doc_tag)]
269
+ ##p [:html_multi,doc_tag,html_file] #,code.gsub(/__ALL_DOC_TAG__/,doc_tag)]
235
270
  Dyndoc.process_html_file_from_dyn_file(code.gsub(/__ALL_DOC_TAG__/,doc_tag),html_file,dyn_file,dyn_layout,addr,dyndoc_start)
236
271
  end
237
272
  end
@@ -263,6 +298,7 @@ module Dyndoc
263
298
  ## This version tries to autoconvert a dyn_file of the form *_<format>.dyn to *.<format>
264
299
  ## Multi-documents is not considered here! The goal is to provide autoconversion for simple file (even though we can use template)
265
300
  ## :format_output => "html" is not a pb since it is mostly used for verbatim output and it is not the focus here!
301
+ ## TODO: think about existence or location of root of layout, preload, postload and dynlib
266
302
 
267
303
  def Dyndoc.auto_convert_from_file(dyn_file,opts={}) #ex: opts={dyn_root: , doc_tag: } #opts=obtained by commandline
268
304
  ## opts[:dyn_root] ||= ENV["HOME"]
@@ -287,7 +323,7 @@ module Dyndoc
287
323
  output_basename: dyn_basename+"."+dyn_extname
288
324
  }
289
325
 
290
- p [:cfg_files,cfg_files]
326
+ ## p [:cfg_files,cfg_files]
291
327
 
292
328
  cfg={}
293
329
 
@@ -41,6 +41,7 @@ module Dyndoc
41
41
  require 'dyndoc-edit'
42
42
  require 'filewatcher'
43
43
  require 'dyndoc-linter'
44
+
44
45
  $VERBOSE = nil
45
46
  options={first: true}
46
47
  ## To put inside yaml config file!
@@ -14,7 +14,7 @@ $public_root = cfg["public_root"] || File.join(root ,"public")
14
14
  class App < Roda
15
15
  use Rack::Session::Cookie, :secret => (secret="Thanks like!")
16
16
  ##TODO: use Rack::LiveReload
17
- plugin :static, ["/pages","/private","/tools"], :root => $public_root
17
+ plugin :static, ["/pages","/private","/tools","/users"], :root => $public_root
18
18
  #opts[:root]=File.expand_path("..",__FILE__),
19
19
  #plugin :static, ["/pages","/private"]
20
20
  plugin :multi_route
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: 0.9.11
4
+ version: 0.9.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - RCqls
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-20 00:00:00.000000000 Z
11
+ date: 2016-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: R4rb
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.5.3
111
+ - !ruby/object:Gem::Dependency
112
+ name: foreverb
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.3.3
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: 0.3.3
111
125
  description: |2
112
126
  Provide templating in text document.
113
127
  email: rdrouilh@gmail.com
@@ -122,22 +136,23 @@ executables:
122
136
  - dyn-lint
123
137
  - dyn-cli
124
138
  - dyn-auto
139
+ - dyn-ctl
140
+ - dyn-4ever
125
141
  extensions: []
126
142
  extra_rdoc_files: []
127
143
  files:
128
144
  - bin/dpm
129
145
  - bin/dyn
146
+ - bin/dyn-4ever
130
147
  - bin/dyn-auto
131
148
  - bin/dyn-cli
132
- - bin/dyn-forever
149
+ - bin/dyn-ctl
133
150
  - bin/dyn-html
134
- - bin/dyn-html-fw-onefile
135
151
  - bin/dyn-http
136
152
  - bin/dyn-init
137
153
  - bin/dyn-lint
138
154
  - bin/dyn-scan
139
155
  - bin/dyn-srv
140
- - bin/dyn-win-env
141
156
  - lib/dyndoc-convert.rb
142
157
  - lib/dyndoc-edit.rb
143
158
  - lib/dyndoc-html-servers.rb
data/bin/dyn-forever DELETED
@@ -1,166 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- ## THIS IS AN ADAPTATION OF FOREVERB (https://github.com/DAddYE/foreverb) TO DYN
4
- require 'rubygems' unless defined?(Gem)
5
- require 'thor'
6
- require 'yaml'
7
- require 'fileutils'
8
- require 'dyndoc/init/home'
9
-
10
- DYN_FOREVER_PATH = ENV['DYN_FOREVER_PATH'] ||= File.expand_path(Dyndoc.home,"etc","dyn-foreverb.yml") unless defined?(DYN_FOREVER_PATH)
11
-
12
- class CLI < Thor
13
-
14
- desc "list", "List Forever running daemons"
15
- method_option :monitor, :type => :boolean, :aliases => "-m", :default => false, :desc => "Show memory and cpu usage with ps"
16
- def list
17
- say "Your config is empty, so no deamons was found.", :red if config.empty? && !options.monitor
18
-
19
- if options.monitor
20
- print_table([%w(PID RSS CPU CMD), *ps])
21
- else
22
- config.each do |conf|
23
- status = begin
24
- pid = File.read(conf[:pid]).to_i
25
- Process.kill(0, pid)
26
- "RUNNING"
27
- rescue Errno::ESRCH, Errno::ENOENT
28
- "NOT RUNNING"
29
- rescue Errno::EPERM
30
- "RUNNING"
31
- end
32
- say_status status, conf[:file], status =~ /^RUNNING/ ? :green : :red
33
- end
34
- say "Reading config from: #{DYN_FOREVER_PATH}", :blue
35
- end
36
- end
37
-
38
- desc "stop [DAEMON] [--all] [--yes]", "Stop one or more matching daemons"
39
- method_option :all, :type => :boolean, :aliases => "-a", :desc => "All matching daemons"
40
- method_option :yes, :type => :boolean, :aliases => "-y", :desc => "Don't ask permission to kill daemon"
41
- def stop(daemon=nil)
42
- find(daemon, :multiple => options.all).each do |conf|
43
- stop_daemon(conf) if options.yes || yes?("Do you want really stop \e[1m#{conf[:file]}\e[0m?")
44
- end
45
- end
46
-
47
- desc "kill [DAEMON] [--all] [--yes]", "Kill one or more matching daemons"
48
- method_option :all, :type => :boolean, :aliases => "-a", :desc => "All matching daemons"
49
- method_option :yes, :type => :boolean, :aliases => "-y", :desc => "Don't ask permission to kill daemon"
50
- def kill(daemon=nil)
51
- find(daemon, :multiple => options.all).each do |conf|
52
- if options.yes || yes?("Do you want really kill \e[1m#{conf[:file]}\e[0m?")
53
- say_status "KILLING", conf[:file]
54
- begin
55
- pid = File.read(conf[:pid]).to_i
56
- Process.kill(:INT, pid)
57
- rescue Exception => e
58
- say_status "ERROR", e.message, :red
59
- end
60
- end
61
- end
62
- end
63
-
64
- desc "start [DAEMON] [--all] [--yes]", "Start one or more matching daemons"
65
- method_option :all, :type => :boolean, :aliases => "-a", :desc => "All matching daemons"
66
- method_option :yes, :type => :boolean, :aliases => "-y", :desc => "Don't ask permission to start the daemon"
67
- def start(daemon=nil)
68
- find(daemon, :multiple => options.all).each do |conf|
69
- system(conf[:file]) if options.yes || yes?("Do you want really start \e[1m#{conf[:file]}\e[0m?")
70
- end
71
- end
72
-
73
- desc "restart [DAEMON] [--all] [--yes]", "Restart one or more matching daemons"
74
- method_option :all, :type => :boolean, :aliases => "-a", :desc => "All matching daemons"
75
- method_option :yes, :type => :boolean, :aliases => "-y", :desc => "Don't ask permission to start the daemon"
76
- def restart(daemon=nil)
77
- invoke :start
78
- end
79
-
80
- desc "tail [DAEMON]", "Tail log of first matching daemon"
81
- method_option :lines, :aliases => "-n", :default => 150, :desc => "How many lines show?"
82
- def tail(daemon)
83
- found = find(daemon)[0]
84
- return unless found
85
- system "tail -f -n #{options.lines} #{found[:log]}"
86
- end
87
-
88
- desc "update [DAEMON] [--all] [--yes]", "Update config from one or more matching daemons"
89
- method_option :all, :type => :boolean, :aliases => "-a", :desc => "All matching daemons"
90
- method_option :yes, :type => :boolean, :aliases => "-y", :desc => "Don't ask permission to start the daemon"
91
- def update(daemon=nil)
92
- match = find(daemon, :multiple => options.all)
93
- return if match.empty?
94
- FileUtils.rm_rf(DYN_FOREVER_PATH)
95
- match.each do |conf|
96
- system(conf[:file], 'update') if options.yes || yes?("Do you want really update config from \e[1m#{conf[:file]}\e[0m?")
97
- end
98
- end
99
-
100
- desc "remove [DAEMON] [--all]", "Remove the config of a daemon from foreverb"
101
- method_option :all, :type => :boolean, :aliases => "-a", :desc => "All matching daemons"
102
- method_option :yes, :type => :boolean, :aliases => "-y", :desc => "Don't ask permission to remove the daemon"
103
- def remove(daemon=nil)
104
- say "You must provide a daemon name or provide --all option", :red and return if daemon.nil? && !options.all
105
- new_config = config.delete_if do |conf|
106
- if conf[:file] =~ /#{daemon}/
107
- if options.yes || yes?("Do you really want to remove the daemon \e[1m#{conf[:file]}\e[0m?")
108
- stop_daemon(conf)
109
- say "\e[1m#{conf[:file]}\e[0m removed."
110
- true
111
- else
112
- say "\e[1m#{conf[:file]}\e[0m remains on the list."
113
- false
114
- end
115
- else
116
- false
117
- end
118
- end
119
- write_config! new_config
120
- end
121
-
122
- private
123
- def find(daemon, options={})
124
- multiple = options.delete(:multiple)
125
- say "You must provide a daemon name or provide --all option", :red and return [] if daemon.nil? && !multiple
126
- found = multiple ? config : config.find_all { |conf| conf[:file] =~ /#{daemon}/ }
127
- say "Daemon(s) matching '#{daemon}' not found", :red if found.empty? && !daemon.nil?
128
- say "Daemons not found", :red if found.empty? && nil && daemon.nil?
129
- found
130
- end
131
-
132
- def find_all(daemon)
133
- find(daemon, :multiple => true)
134
- end
135
-
136
- def config
137
- File.exist?(DYN_FOREVER_PATH) ? YAML.load_file(DYN_FOREVER_PATH) : []
138
- end
139
-
140
- def ps
141
- # This is horrible command, but how we can keep compatiblity between darwin and *unix ?
142
- result = `ps axo pid,rss,pcpu,command | grep -vE "^USER|grep" | grep Forever: | awk '{print $1"\t"$2"\t"$3"\t"$4" "$5" "$6}'`
143
- result = result.chomp.split("\n").map { |line| line.split("\t") }
144
- result = result.sort { |a,b| b[1].to_i <=> a[1].to_i }
145
- result.each { |column| column[1] = "%d Mb" % [column[1].to_i / 1024] }
146
- result.each { |column| column[2] = "%s %" % [column[2]] }
147
- result
148
- end
149
-
150
- def write_config!(new_config)
151
- File.open(DYN_FOREVER_PATH, "w") { |f| f.write new_config.to_yaml }
152
- end
153
-
154
- def stop_daemon(conf)
155
- say_status "STOPPING", conf[:file]
156
- begin
157
- pid = File.read(conf[:pid]).to_i
158
- Process.kill(:INT, pid)
159
- rescue Exception => e
160
- say_status "ERROR", e.message, :red
161
- end
162
- end
163
- end
164
-
165
- ARGV << "-h" if ARGV.empty?
166
- CLI.start(ARGV)
@@ -1,143 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'dyndoc-convert'
3
- require 'dyndoc-edit'
4
- require 'dyndoc/init/home'
5
- dyndoc_home = Dyndoc.home
6
- #p Dyndoc.home
7
-
8
- ###############################################
9
- ## INFO: this file watch only one file and #
10
- ## it is now replaced with dyn-html watching #
11
- ## an entire directory! #
12
- ###############################################
13
- cfg_yml = File.join(dyndoc_home,"etc","dyn-html.yml")
14
-
15
- cfg={}
16
-
17
- cfg=YAML::load_file(cfg_yml) if File.exist? cfg_yml
18
-
19
-
20
- ## To put inside yaml config file!
21
- root = cfg["root"] || File.join(ENV["HOME"],"RCqls","RodaServer")
22
- edit_root = cfg["src_root"] || cfg["edit_root"] || File.join(root ,"edit")
23
- public_root = cfg["public_root"] || File.join(root ,"public")
24
- pages_root = File.join(public_root ,"pages")
25
- current_email = cfg["email"] || "rdrouilh@gmail.com" #default email user can be overriden by -u option
26
-
27
- args=ARGV
28
- args=["-h"] if args.empty?
29
-
30
- require 'optparse'
31
-
32
- $VERBOSE = nil
33
-
34
- ## Examples:
35
- ## 1) global mode:
36
- ## dyn-html /dev/R/test.dyn
37
- ## 2) user mode: relative path used instead of ~ since ~ is interpreted in bash mode!
38
- ## dyn-html cfies2017/index.dyn:index # -u <default_user_email>
39
- ## dyn-html -u remy.drouilhet@upmf-grenoble.fr cfies2017/index.dyn:index
40
- ## dyn-html -u remy.drouilhet@upmf-grenoble.fr cfies2017/index.dyn:all
41
-
42
- options={watching: nil, refresh: :auto, first: true}
43
-
44
- OptionParser.new do |opts|
45
- opts.banner = "Usage: dyn-html [-u email_user] [-w] [-r <url-to-refresh-when-watched>] [/]<relative_path>/<file>.dyn"
46
-
47
- opts.on( '-u', '--user EMAIL', 'user email' ) do |email|
48
- current_email=email
49
- end
50
-
51
- opts.on( '-w', '--watch', 'watch file') do
52
- options[:watching]=true
53
- end
54
-
55
- opts.on( '-r', '--refresh HTML', 'page to refresh (only for MacOsX)' ) do |html|
56
- options[:refresh]=html
57
- end
58
-
59
- opts.on('--no-refresh', 'no refresh page' ) do
60
- options[:refresh]=nil
61
- end
62
-
63
- end.parse!(args)
64
-
65
- ## Mandatory input
66
- dyn_file,doc_tag=args[0].split(":")
67
- doc_tag="" unless doc_tag
68
- doc_tag="__ALL_DOC_TAG__" if doc_tag.downcase == "all"
69
-
70
- ## Detect docs_tags_info
71
- dyn_file=File.join(["","users",current_email],dyn_file) unless dyn_file[0,1]=="/"
72
- filename=File.join(edit_root,dyn_file)
73
-
74
- doc_tags_info=Dyndoc::Edit.get_doc_tags_info(File.read(filename))
75
-
76
- if dyn_file and (dyn_file=~/(.*)(?:\.dyn|_html.dyn)$/)
77
- #p [:dyn_file,dyn_file,$1]
78
- html_files=Dyndoc::Edit.html_files({doc_tags_info: doc_tags_info , dyn_file: dyn_file },current_email)
79
- ##p [:html_files,html_files]
80
- html_file=html_files[doc_tag] || html_files[""]
81
-
82
- if options[:refresh] and options[:refresh] == :auto
83
- options[:refresh] = File.join(cfg["localhost_url"] || "http://localhost:9292",File.dirname(dyn_file),File.basename(dyn_file,".*"))
84
- end
85
-
86
- output=""
87
- output << "Watching "+dyn_file if options[:watching]
88
- output << (options[:watching] ? " and refreshing " : "Refreshing ")+options[:refresh] if options[:refresh]
89
- puts output unless output.empty?
90
-
91
- # Ex for opts:
92
- # rdrouilh : [:dyn_opts, {:dyn_root=>"/Users/remy/RCqls/RodaServer/edit", :html_root=>"/Users/remy/RCqls/RodaServer/public/pages", :user=>"rdrouilh@gmail.com", :doc_tag=>"bio", :html_files=>{""=>"/dev/R/test.html", "ssd"=>"/dev/R/ssd.html", "bio"=>"/dev/R/bio.html", "tmp"=>"/dev/R/tmp.html", "cours"=>"/dev/R/cours.html"}}]
93
- # remy.drouilhet : [:dyn_opts, {:dyn_root=>"/Users/remy/RCqls/RodaServer/edit", :html_root=>"/Users/remy/RCqls/RodaServer/public/pages", :user=>"remy.drouilhet@upmf-grenoble.fr", :doc_tag=>"index", :html_files=>{""=>"/users/remy.drouilhet@upmf-grenoble.fr/cfies2017/index.html", "index"=>"/users/remy.drouilhet@upmf-grenoble.fr/cfies2017/index.html", "dates"=>"/users/remy.drouilhet@upmf-grenoble.fr/cfies2017/dates.html", "sc"=>"/users/remy.drouilhet@upmf-grenoble.fr/cfies2017/sc.html", "orga"=>"/users/remy.drouilhet@upmf-grenoble.fr/cfies2017/orga.html"}}]
94
- opts = {
95
- dyn_root: edit_root,
96
- html_root: pages_root,
97
- user: current_email,
98
- doc_tag: doc_tag,
99
- html_files: html_files
100
- }
101
- ##p opts
102
- file_to_process=File.join(opts[:dyn_root],dyn_file)
103
- cmd_to_open=nil
104
- if options[:refresh] and RUBY_PLATFORM =~ /darwin/
105
- cmd_to_open='tell application "Safari" to set URL of current tab of front window to "'+options[:refresh]+'"'
106
- cmd_to_refresh='tell application "System Events"' + "\n" + 'tell process "Safari"' + "\n" + 'keystroke "r" using {command down}' + "\n" + 'delay 60' + "\n" + 'end tell' + "\n" + 'end tell'
107
- end
108
- unless options[:watching]
109
- ## dyn_file[1..-1] to have a relative path...
110
- if Dyndoc::Linter.check_file(file_to_process).empty?
111
- Dyndoc.cli_convert_from_file(dyn_file[1..-1],html_file, opts)
112
- else
113
- puts dyn_file[1..-1]+" not well-formed!"
114
- end
115
- else
116
- require 'filewatcher'
117
- require 'dyndoc-linter'
118
- FileWatcher.new([file_to_process]).watch() do |filename, event|
119
- if event == :changed
120
- if Dyndoc::Linter.check_file(file_to_process).empty?
121
- Dyndoc.cli_convert_from_file(dyn_file[1..-1],html_file, opts)
122
- puts dyn_file[1..-1]+" processed!"
123
- if options[:refresh] and RUBY_PLATFORM =~ /darwin/
124
- if options[:first]
125
- `osascript -e '#{cmd_to_open}'`
126
- options[:first]=nil
127
- else
128
- %x{osascript<<ENDREFRESH
129
- tell app "Safari" to activate
130
- tell application "System Events"
131
- keystroke "r" using {command down}
132
- end tell
133
- ENDREFRESH
134
- }
135
- end
136
- end
137
- else
138
- puts dyn_file[1..-1]+" not well-formed!"
139
- end
140
- end
141
- end
142
- end
143
- end
data/bin/dyn-win-env DELETED
@@ -1,82 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
- require 'rubygems' # if you use RubyGems
4
- require 'commander/import'
5
- require 'dyndoc/common/utils'
6
-
7
-
8
- # :name is optional, otherwise uses the basename of this executable
9
- program :name, 'dyndoc environment'
10
- program :version, '0.1.0'
11
- program :description, 'Dyndoc environment management.'
12
-
13
- highline= HighLine.new
14
-
15
- command :path do |c|
16
- c.syntax = 'dyndoc-envir path'
17
- c.description = 'Manage paths for Windows'
18
- c.action do |args, options|
19
- if Dyndoc::Utils.is_windows?
20
- dirsR=Dir[File.join(ENV['ProgramFiles'].split('\\'),'**','R.dll')].map{|e| File.dirname(e).split('/').join('\\').strip}.uniq
21
- if dirsR.empty?
22
- say("No R directory found in your Windows System!")
23
- else
24
- require 'win32/registry'
25
- paths=nil
26
- Win32::Registry::HKEY_CURRENT_USER.open('Environment') do |reg|
27
- paths=reg['path'].split(";").map{|l| l.strip}
28
- end
29
- save=false
30
- case args[0].downcase.to_sym
31
- when :r
32
- highline.choose do |menu|
33
- menu.prompt = "Please select the R directory to add to your PATH: "
34
- menu.choices(*dirsR) do |ch|
35
- paths << ch
36
- save=true
37
- say("#{ch} added to user PATH!")
38
- end
39
- menu.choice :quit do say("Nothing done!") end
40
- end
41
- when :add
42
- paths << args[1].split(";").map{|l| l.strip}
43
- say("#{args[1]} added to user PATH!")
44
- save=true
45
- when :del
46
- highline.choose do |menu|
47
- menu.prompt = "Please choose path to delete? "
48
- menu.choices(*paths) do |ch|
49
- paths.delete(ch)
50
- save=true
51
- say("#{ch} removed from user PATH!")
52
- end
53
- menu.choice :quit do say("Nothing done!") end
54
- end
55
- end
56
- if save
57
- Win32::Registry::HKEY_CURRENT_USER.open('Environment',Win32::Registry::KEY_WRITE) do |reg|
58
- reg['path'] = paths.join(";")
59
- puts reg['path']
60
- end
61
- end
62
- puts paths.join("\n")+"\n"
63
- end
64
- end
65
- end
66
- end
67
-
68
- command :link do |c|
69
- c.syntax = 'dyndoc-envir link'
70
- c.description = 'Create a link for Dyndoc Console2'
71
- c.action do |args, options|
72
- console=args[0] ? args[0] : "C:\\tools\\Console2\\Console.exe"
73
- require 'win32/shortcut'
74
- Win32::Shortcut.new(ENV["HOME"].split("/").join("\\")+"\\Desktop\\Dyndoc.lnk") do |s|
75
- s.description = 'Dyndoc'
76
- s.path = console
77
- s.window_style = Win32::Shortcut::SHOWNORMAL
78
- s.icon_location = console
79
- s.working_directory = ENV["HOME"].split("/").join("\\")
80
- end
81
- end
82
- end