rsence-pre 2.2.0.28 → 2.2.0.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/VERSION +1 -1
  2. data/conf/default_conf.yaml +8 -6
  3. data/conf/rsence_command_strings.yaml +8 -6
  4. data/lib/rsence.rb +4 -4
  5. data/lib/rsence/argv.rb +218 -0
  6. data/lib/rsence/argv/argv_util.rb +58 -0
  7. data/lib/rsence/argv/env_check.rb +58 -0
  8. data/lib/rsence/argv/help_argv.rb +15 -0
  9. data/lib/rsence/argv/initenv_argv.rb +218 -0
  10. data/lib/rsence/argv/save_argv.rb +92 -0
  11. data/lib/rsence/argv/startup_argv.rb +118 -0
  12. data/lib/rsence/argv/status_argv.rb +132 -0
  13. data/lib/rsence/argv/test_port.rb +32 -0
  14. data/lib/{daemon → rsence}/daemon.rb +21 -6
  15. data/lib/{conf/default.rb → rsence/default_config.rb} +0 -1
  16. data/lib/{plugins → rsence}/dependencies.rb +0 -0
  17. data/lib/{util → rsence}/gzstring.rb +0 -0
  18. data/lib/rsence/http.rb +3 -0
  19. data/lib/{http → rsence/http}/broker.rb +12 -3
  20. data/lib/{http → rsence/http}/rackup.rb +0 -0
  21. data/lib/{http → rsence/http}/request.rb +0 -4
  22. data/lib/{http → rsence/http}/response.rb +0 -1
  23. data/lib/{session → rsence}/msg.rb +1 -1
  24. data/lib/{plugins → rsence}/pluginmanager.rb +2 -2
  25. data/lib/{plugins → rsence}/plugins.rb +7 -7
  26. data/lib/{plugins → rsence/plugins}/gui_plugin.rb +0 -0
  27. data/lib/{plugins → rsence/plugins}/guiparser.rb +0 -0
  28. data/lib/{plugins → rsence/plugins}/plugin.rb +0 -0
  29. data/lib/{plugins → rsence/plugins}/plugin_base.rb +0 -0
  30. data/lib/{plugins → rsence/plugins}/plugin_plugins.rb +0 -0
  31. data/lib/{plugins → rsence/plugins}/plugin_sqlite_db.rb +0 -0
  32. data/lib/{plugins → rsence/plugins}/servlet.rb +0 -0
  33. data/lib/{session → rsence}/sessionmanager.rb +2 -2
  34. data/lib/{session → rsence}/sessionstorage.rb +1 -1
  35. data/lib/{daemon → rsence}/sigcomm.rb +0 -0
  36. data/lib/{transporter → rsence}/transporter.rb +3 -3
  37. data/lib/{values/hvalue.rb → rsence/value.rb} +0 -0
  38. data/lib/{values → rsence}/valuemanager.rb +1 -1
  39. metadata +100 -91
  40. data/lib/conf/argv.rb +0 -842
data/lib/conf/argv.rb DELETED
@@ -1,842 +0,0 @@
1
- ## RSence
2
- # Copyright 2010 Riassence Inc.
3
- # http://riassence.com/
4
- #
5
- # You should have received a copy of the GNU General Public License along
6
- # with this software package. If not, contact licensing@riassence.com
7
- ##
8
-
9
- module RSence
10
-
11
- # @private ARGVParser is the "user interface" as a command-line argument parser.
12
- # It parses the command-line arguments and sets up things accordingly.
13
- class ARGVParser
14
-
15
- # The RSence version string, read from the VERSION file in
16
- # the root directory of RSence.
17
- @@version = File.read( File.join( SERVER_PATH, 'VERSION' ) ).strip
18
-
19
- # Makes various commands available depending on the platform.
20
- # The status/start/stop/restart/save -commands depend on an operating
21
- # system that fully implements POSIX standard signals.
22
- # These are necessary to send signals to the background process.
23
- if not RSence.pid_support?
24
- @@cmds = [ :run, :init, :initenv, :version, :help ]
25
- else
26
- @@cmds = [ :run, :status, :start, :stop, :restart, :save,
27
- :init, :initenv, :version, :help ]
28
- end
29
-
30
- help_avail_cmds = @@cmds.map{|cmd|cmd.to_s}.join("\n ")
31
-
32
- # Load the strings from the strings file.
33
- strs_path = File.join( SERVER_PATH, 'conf',
34
- 'rsence_command_strings.yaml' )
35
- strs_data = File.read( strs_path )
36
- require 'erb'
37
-
38
- strs_data = ERB.new( strs_data ).result( binding )
39
-
40
- require 'yaml'
41
- @@strs = YAML.load( strs_data )
42
-
43
- @@strs[:help][:run] += @@strs[:help][:path]+@@strs[:help][:options]
44
- @@strs[:help][:start] += @@strs[:help][:path]+@@strs[:help][:options]
45
- @@strs[:help][:stop] += @@strs[:help][:path]+@@strs[:help][:options]
46
- @@strs[:help][:restart] += @@strs[:help][:path]+@@strs[:help][:options]
47
- @@strs[:help][:status] += @@strs[:help][:path]
48
- @@strs[:help][:save] += @@strs[:help][:path]
49
-
50
-
51
- # Returns true if one of the 'start' -type commands were supplied
52
- # and the environment seems valid.
53
- def startable?; @startable; end
54
-
55
- # Parses an argument of the 'help' command
56
- def parse_help_argv
57
- if @argv.length >= 2
58
- help_cmd = @argv[1].to_sym
59
- else
60
- help_cmd = :help_main
61
- end
62
- help( help_cmd )
63
- exit
64
- end
65
-
66
- # Creates the default and initial @args hash.
67
- def init_args
68
- @args = {
69
- :env_path => Dir.pwd,
70
- :conf_files => [ ], # --conf
71
- :debug => false, # -d --debug
72
- :verbose => false, # -v --verbose
73
- :log_fg => false, # -f --log-fg
74
- :trace_js => false, # --trace-js
75
- :trace_delegate => false, # --trace-delegate
76
- :port => nil, # --port
77
- :addr => nil, # --addr --bind
78
- :server => nil, # --server
79
- :reset_ses => false, # -r --reset-sessions
80
- :autoupdate => false, # -a --auto-update
81
- :latency => 0, # --latency
82
- :say => false, # -S --say
83
- :http_delayed_start => nil, # --http-delayed-start
84
-
85
- # client_pkg (not supported yet)
86
- :client_pkg_no_gzip => false, # --disable-gzip
87
- :client_pkg_no_obfuscation => false, # --disable-obfuscation
88
- :client_pkg_no_whitespace_removal => false, # --disable-jsmin
89
- :suppress_build_messages => true, # --build-report
90
-
91
- }
92
- end
93
-
94
- def set_client_pkg_arg( arg_name )
95
- if arg_name == '--disable-gzip'
96
- @args[:client_pkg_no_gzip] = true
97
- elsif arg_name == '--disable-obfuscation'
98
- @args[:client_pkg_no_obfuscation] = true
99
- elsif arg_name == '--disable-jsmin'
100
- @args[:client_pkg_no_whitespace_removel] = true
101
- elsif arg_name == '--build-report'
102
- @args[:suppress_build_messages] = false
103
- else
104
- invalid_option( arg_name )
105
- end
106
- end
107
-
108
- # Main argument parser for all 'start' -type commands.
109
- def parse_startup_argv
110
- init_args
111
- expect_option = false
112
- option_name = false
113
- if @argv.length >= 2
114
- @argv[1..-1].each_with_index do |arg,i|
115
- if expect_option
116
- if [ :port, :latency, :http_delayed_start ].include?(option_name) and arg.to_i.to_s != arg
117
- puts ERB.new( @@strs[:messages][:invalid_option_expected_number] ).result( binding )
118
- exit
119
- elsif option_name == :conf_files
120
- if not File.exists?( arg ) or not File.file?( arg )
121
- puts ERB.new( @@strs[:messages][:no_such_configuration_file] ).result( binding )
122
- exit
123
- else
124
- @args[:conf_files].push( arg )
125
- end
126
- elsif option_name == :http_delayed_start
127
- @args[:http_delayed_start] = arg.to_i
128
- else
129
- arg = arg.to_i if option_name == :latency
130
- @args[option_name] = arg
131
- end
132
- expect_option = false
133
- else
134
- if arg.start_with?('--')
135
- if arg == '--profile'
136
- true
137
- elsif arg == '--debug'
138
- set_debug
139
- elsif arg == '--verbose'
140
- set_verbose
141
- elsif arg == '--log-fg'
142
- set_log_fg
143
- elsif arg == '--trace-js'
144
- @args[:trace_js] = true
145
- elsif arg.start_with?( '--client-' )
146
- set_client_pkg_arg( arg )
147
- elsif arg == '--trace-delegate'
148
- @args[:trace_delegate] = true
149
- elsif arg == '--port'
150
- expect_option = true
151
- option_name = :port
152
- elsif arg == '--addr'
153
- expect_option = true
154
- option_name = :addr
155
- elsif arg == '--http-delayed-start' or arg == '--delayed-start'
156
- expect_option = true
157
- option_name = :http_delayed_start
158
- elsif arg == '--server'
159
- expect_option = true
160
- option_name = :server
161
- elsif arg == '--conf' or arg == '--config'
162
- expect_option = true
163
- option_name = :conf_files
164
- elsif arg == '--reset-sessions'
165
- set_reset_ses
166
- elsif arg == '--auto-update'
167
- set_autoupdate
168
- elsif arg == '--latency'
169
- expect_option = true
170
- option_name = :latency
171
- elsif arg == '--say'
172
- set_say
173
- else
174
- invalid_option(arg)
175
- end
176
- elsif arg.start_with?('-')
177
- arg.split('')[1..-1].each do |chr|
178
- if chr == 'd'
179
- set_debug
180
- elsif chr == 'v'
181
- set_verbose
182
- elsif chr == 'f'
183
- set_log_fg
184
- elsif chr == 'r'
185
- set_reset_ses
186
- elsif chr == 'a'
187
- set_autoupdate
188
- elsif chr == 'S'
189
- set_say
190
- else
191
- invalid_option(arg,chr)
192
- end
193
- end
194
- elsif valid_env?(arg)
195
- @args[:env_path] = File.expand_path(arg)
196
- @args[:conf_files].push( File.expand_path( File.join( arg, 'conf', 'config.yaml' ) ) )
197
- else
198
- invalid_env( arg )
199
- end
200
- end
201
- end
202
- if expect_option
203
- puts ERB.new( @@strs[:messages][:no_value_for_option] ).result( binding )
204
- exit
205
- end
206
- end
207
- if valid_env?(@args[:env_path])
208
- conf_file = File.expand_path( File.join( @args[:env_path], 'conf', 'config.yaml' ) )
209
- @args[:conf_files].unshift( conf_file ) unless @args[:conf_files].include?( conf_file )
210
- else
211
- invalid_env
212
- end
213
- @startable = true
214
- end
215
-
216
- # Sets various debug-related options on.
217
- def set_debug
218
- @args[:debug] = true
219
- @args[:verbose] = true
220
- @args[:autoupdate] = true
221
- @args[:client_pkg_no_obfuscation] = true
222
- @args[:client_pkg_no_whitespace_removal] = true
223
- @args[:suppress_build_messages] = false
224
- end
225
-
226
- # Set the verbose argument on
227
- def set_verbose
228
- @args[:verbose] = true
229
- end
230
-
231
- # Set the foreground logging argument on
232
- def set_log_fg
233
- @args[:log_fg] = true
234
- end
235
-
236
- # Sets the session reset argument on
237
- def set_reset_ses
238
- @args[:reset_ses] = true
239
- end
240
-
241
- # Sets the auto-update argument on
242
- def set_autoupdate
243
- @args[:autoupdate] = true
244
- end
245
-
246
- # Sets the speech synthesis argument on
247
- def set_say
248
- @args[:say] = true
249
- end
250
-
251
- # Tests for a valid environment
252
- def valid_env?( arg, quiet=false )
253
-
254
- # Checks, if the top-level path exists and is a directory
255
- path = File.expand_path( arg )
256
- if not File.exists?( path )
257
- puts ERB.new( @@strs[:messages][:no_such_directory] ).result( binding ) unless quiet
258
- return false
259
- elsif not File.directory?( path )
260
- puts ERB.new( @@strs[:messages][:not_a_directory] ).result( binding ) unless quiet
261
- return false
262
- end
263
-
264
- # Checks, if the conf path exists and is a directory
265
- conf_path = File.join( path, 'conf' )
266
- if not File.exists?( conf_path )
267
- puts ERB.new( @@strs[:messages][:missing_conf_directory] ).result( binding ) unless quiet
268
- return false
269
- elsif not File.directory?( conf_path )
270
- puts ERB.new( @@strs[:messages][:invalid_conf_directory] ).result( binding ) unless quiet
271
- return false
272
- end
273
-
274
- # Checks, if the conf/config.yaml file exists and is a directory
275
- conf_file = File.join( path, 'conf', 'config.yaml' )
276
- if not File.exists?(conf_file)
277
- puts ERB.new( @@strs[:messages][:missing_conf_file] ).result( binding ) unless quiet
278
- return false
279
- elsif not File.file?( conf_file )
280
- puts ERB.new( @@strs[:messages][:invalid_conf_file_not_file] ).result( binding ) unless quiet
281
- return false
282
- end
283
-
284
- # Checks, if the plugins path exists and is a directory
285
- plugin_path = File.join( path, 'plugins' )
286
- if not File.exists?( plugin_path )
287
- warn ERB.new( @@strs[:messages][:warn_no_plugin_directory_in_project] ).result( binding ) if @args[:verbose]
288
- elsif not File.directory?( plugin_path )
289
- puts ERB.new( @@strs[:messages][:plugin_directory_not_a_directory] ).result( binding ) unless quiet
290
- return false
291
- end
292
-
293
- # Checks (and automatically creates if missing) the run, db and log directories
294
- ['run','log','db'].each do |dir_name|
295
- dir_path = File.join( path, dir_name )
296
- unless File.exists?( dir_path )
297
- warn ERB.new( @@strs[:messages][:warn_no_directory_creating] ).result( binding ) if @args[:verbose]
298
- Dir.mkdir( dir_path )
299
- end
300
- end
301
- return true
302
- end
303
-
304
- # Error message when an invalid environment is encountered, exits.
305
- def invalid_env( env_path=false )
306
- env_path = @args[:env_path] unless env_path
307
- puts ERB.new( @@strs[:messages][:invalid_environment] ).result( binding )
308
- exit
309
- end
310
-
311
- # Error message when an invalid option is encountered, exits.
312
- def invalid_option(arg,chr=false)
313
- if chr
314
- puts ERB.new( @@strs[:messages][:invalid_option_chr] ).result( binding )
315
- else
316
- puts ERB.new( @@strs[:messages][:invalid_option] ).result( binding )
317
- end
318
- exit
319
- end
320
-
321
- # Tests, if the port on addr responds or refuses the connection.
322
- # Automatically replaces '0.0.0.0' with '127.0.0.1'
323
- def test_port( port, addr='127.0.0.1' )
324
- require 'socket'
325
- begin
326
- addr = '127.0.0.1' if addr == '0.0.0.0'
327
- if RUBY_VERSION.to_f >= 1.9
328
- sock = TCPSocket.open( addr, port )
329
- else
330
- begin
331
- sock = TCPsocket.open( addr, port )
332
- rescue NameError => e
333
- warn "TCPsocket not available, trying TCPSocket.."
334
- sock = TCPSocket.open( addr, port )
335
- end
336
- end
337
- sock.close
338
- return true
339
- rescue Errno::ECONNREFUSED
340
- return false
341
- rescue => e
342
- warn e.inspect
343
- return false
344
- end
345
- end
346
-
347
- # Main argument parser for the status command, sends the INFO (or PWR on linux) POSIX signal to
348
- # the process, if running.
349
- # Checks if the process responds on the port and address it's configured for.
350
- def parse_status_argv
351
- init_args
352
- expect_option = false
353
- option_name = false
354
- if @argv.length >= 2
355
- @argv[1..-1].each_with_index do |arg,i|
356
- if expect_option
357
- if [:port].include?(option_name) and arg.to_i.to_s != arg
358
- puts ERB.new( @@strs[:messages][:invalid_option_expected_number] ).result( binding )
359
- exit
360
- elsif option_name == :conf_files
361
- if not File.exists?( arg ) or not File.file?( arg )
362
- puts ERB.new( @@strs[:messages][:no_such_configuration_file] ).result( binding )
363
- exit
364
- else
365
- @args[:conf_files].push( arg )
366
- end
367
- else
368
- @args[option_name] = arg
369
- end
370
- expect_option = false
371
- else
372
- if arg.start_with?('--')
373
- if arg == '--debug'
374
- set_debug
375
- elsif arg == '--verbose'
376
- set_verbose
377
- elsif arg == '--port'
378
- expect_option = true
379
- option_name = :port
380
- elsif arg == '--addr'
381
- expect_option = true
382
- option_name = :addr
383
- elsif arg == '--conf' or arg == '--config'
384
- expect_option = true
385
- option_name = :conf_files
386
- else
387
- invalid_option(arg)
388
- end
389
- elsif arg.start_with?('-')
390
- arg.split('')[1..-1].each do |chr|
391
- if chr == 'd'
392
- set_debug
393
- elsif chr == 'v'
394
- set_verbose
395
- else
396
- invalid_option(arg,chr)
397
- end
398
- end
399
- elsif valid_env?(arg)
400
- @args[:env_path] = File.expand_path(arg)
401
- @args[:conf_files].unshift( File.expand_path( File.join( arg, 'conf', 'config.yaml' ) ) )
402
- else
403
- invalid_env( arg )
404
- end
405
- end
406
- end
407
- if expect_option
408
- puts ERB.new( @@strs[:messages][:no_value_for_option] ).result( binding )
409
- exit
410
- end
411
- end
412
- if valid_env?(@args[:env_path])
413
- conf_file = File.expand_path( File.join( @args[:env_path], 'conf', 'config.yaml' ) )
414
- @args[:conf_files].unshift( conf_file ) unless @args[:conf_files].include?( conf_file )
415
- else
416
- invalid_env
417
- end
418
- require 'conf/default'
419
- config = Configuration.new(@args).config
420
- port = config[:http_server][:port]
421
- addr = config[:http_server][:bind_address]
422
- port_status = test_port( port, addr )
423
- if RSence.pid_support?
424
- pid_fn = config[:daemon][:pid_fn]
425
- if File.exists?( pid_fn )
426
- pid = File.read( pid_fn ).to_i
427
- sig_name = RSence.info_signal_name
428
- pid_status = RSence::SIGComm.wait_signal_response(
429
- pid, pid_fn, sig_name, 3
430
- )
431
- else
432
- warn @@strs[:messages][:no_pid_file] if @args[:verbose]
433
- pid_status = nil
434
- end
435
- else
436
- warn @@strs[:messages][:no_pid_support] if @args[:verbose]
437
- pid_status = nil
438
- end
439
- if RSence.pid_support?
440
- if pid_status == nil
441
- puts @@strs[:messages][:no_pid]
442
- elsif pid_status == false
443
- if port_status
444
- puts ERB.new( @@strs[:messages][:no_process_running_but_something_responds] ).result( binding )
445
- else
446
- puts ERB.new( @@strs[:messages][:no_process_running_and_nothing_responds] ).result( binding )
447
- end
448
- else
449
- if port_status
450
- puts ERB.new( @@strs[:messages][:process_running_and_responds] ).result( binding )
451
- else
452
- puts ERB.new( @@strs[:messages][:process_running_but_nothing_responds] ).result( binding )
453
- end
454
- end
455
- end
456
- end
457
-
458
- # Main argument parser for the save command. Sends the USR1 POSIX signal to the process, if running.
459
- def parse_save_argv
460
- init_args
461
- expect_option = false
462
- option_name = false
463
- if @argv.length >= 2
464
- @argv[1..-1].each_with_index do |arg,i|
465
- if expect_option
466
- if option_name == :conf_files
467
- if not File.exists?( arg ) or not File.file?( arg )
468
- puts ERB.new( @@strs[:messages][:no_such_configuration_file] ).result( binding )
469
- exit
470
- else
471
- @args[:conf_files].push( arg )
472
- end
473
- else
474
- @args[option_name] = arg
475
- end
476
- expect_option = false
477
- else
478
- if arg.start_with?('--')
479
- if arg == '--debug'
480
- set_debug
481
- elsif arg == '--verbose'
482
- set_verbose
483
- elsif arg == '--conf' or arg == '--config'
484
- expect_option = true
485
- option_name = :conf_files
486
- else
487
- invalid_option(arg)
488
- end
489
- elsif arg.start_with?('-')
490
- arg.split('')[1..-1].each do |chr|
491
- if chr == 'd'
492
- set_debug
493
- elsif chr == 'v'
494
- set_verbose
495
- else
496
- invalid_option(arg,chr)
497
- end
498
- end
499
- elsif valid_env?(arg)
500
- @args[:env_path] = File.expand_path(arg)
501
- @args[:conf_files].unshift( File.expand_path( File.join( arg, 'conf', 'config.yaml' ) ) )
502
- else
503
- invalid_env( arg )
504
- end
505
- end
506
- end
507
- if expect_option
508
- puts ERB.new( @@strs[:messages][:no_value_for_option] ).result( binding )
509
- exit
510
- end
511
- end
512
- if valid_env?(@args[:env_path])
513
- conf_file = File.expand_path( File.join( @args[:env_path], 'conf', 'config.yaml' ) )
514
- @args[:conf_files].unshift( conf_file ) unless @args[:conf_files].include?( conf_file )
515
- else
516
- invalid_env
517
- end
518
- require 'conf/default'
519
- config = Configuration.new(@args).config
520
- if RSence.pid_support?
521
- pid_fn = config[:daemon][:pid_fn]
522
- if File.exists?( pid_fn )
523
- pid = File.read( pid_fn ).to_i
524
- saving_message = @@strs[:messages][:saving_message]
525
- pid_status = RSence::SIGComm.wait_signal_response(
526
- pid, pid_fn, 'USR2', 30, saving_message, '.', 0.1, true
527
- )
528
- else
529
- warn @@strs[:messages][:no_pid_file] if @args[:verbose]
530
- pid_status = nil
531
- end
532
- else
533
- warn @@strs[:messages][:no_pid_support] if @args[:verbose]
534
- pid_status = nil
535
- end
536
- if RSence.pid_support?
537
- if pid_status == nil
538
- puts @@strs[:messages][:no_pid_unable_to_save]
539
- elsif pid_status == false
540
- puts @@strs[:messages][:no_process_running]
541
- else
542
- puts @@strs[:messages][:session_data_saved]
543
- end
544
- end
545
- end
546
-
547
- # asks y/n and returns booleans,
548
- # the default tells if which one is for just enter
549
- def yesno(default=false)
550
- if default
551
- question = "Y/n? "
552
- else
553
- question = "y/N? "
554
- end
555
- print question
556
- answer = $stdin.gets.strip.downcase[0]
557
- answer = answer.chr if answer
558
- if answer == 'n'
559
- return false
560
- elsif answer == 'y'
561
- return true
562
- elsif answer == nil
563
- return default
564
- else
565
- return nil
566
- end
567
- end
568
-
569
- # The initenv command and its parser. Asks questions about the environment before doing anything else.
570
- def parse_initenv_argv
571
- init_args
572
- expect_option = false
573
- option_name = false
574
- valid_env = false
575
- interactive = true
576
- create_blank = false
577
- if @argv.length >= 2
578
- @argv[1..-1].each_with_index do |arg,i|
579
- if expect_option
580
- if [:port].include?(option_name) and arg.to_i.to_s != arg
581
- puts ERB.new( @@strs[:messages][:invalid_option_expected_number] ).result( binding )
582
- exit
583
- else
584
- @args[option_name] = arg
585
- end
586
- expect_option = false
587
- else
588
- if arg.start_with?('--')
589
- if arg == '--port'
590
- expect_option = true
591
- option_name = :port
592
- elsif arg == '--addr'
593
- expect_option = true
594
- option_name = :addr
595
- elsif arg == '--server'
596
- expect_option = true
597
- option_name = :server
598
- elsif arg == '--title'
599
- expect_option = true
600
- option_name = :title
601
- elsif arg == '--database'
602
- expect_option = true
603
- option_name = :db
604
- elsif arg == '--uri-prefix'
605
- expect_option = true
606
- option_name = :base_url
607
- elsif arg == '--blank'
608
- create_blank = true
609
- elsif arg == '--non-interactive'
610
- interactive = false
611
- else
612
- invalid_option(arg)
613
- end
614
- elsif arg.start_with?('-')
615
- arg.split('')[1..-1].each do |chr|
616
- if chr == 'q'
617
- interactive = false
618
- end
619
- end
620
- else
621
- @args[:env_path] = File.expand_path(arg)
622
- end
623
- end
624
- end
625
- if expect_option
626
- puts ERB.new( @@strs[:messages][:no_value_for_option] ).result( binding )
627
- exit
628
- end
629
- end
630
- if valid_env?(@args[:env_path],true)
631
- puts @@strs[:initenv][:env_already_initialized]
632
- exit
633
- end
634
- conf_file = File.expand_path( File.join( @args[:env_path], 'conf', 'config.yaml' ) )
635
- if File.exists?(@args[:env_path])
636
- env_empty = true # true while entries start with a dot
637
- env_clear = true # true while entries don't contain RSence project files
638
- env_entries = ['conf', 'db', 'log', 'plugins', 'run', 'README', 'VERSION']
639
- Dir.entries(@args[:env_path]).each do |entry|
640
- next if entry.start_with?('.')
641
- env_empty = false
642
- if env_entries.include? entry
643
- env_clear = false
644
- break
645
- end
646
- end
647
- unless env_clear
648
- puts ERB.new( @@strs[:initenv][:env_not_clear] ).result( binding )
649
- print @@strs[:initenv][:continue_question]
650
- exit unless yesno
651
- end
652
- unless env_empty
653
- puts ERB.new( @@strs[:initenv][:env_not_empty] ).result( binding )
654
- print @@strs[:initenv][:continue_question]
655
- exit unless yesno
656
- end
657
- end
658
-
659
- require 'conf/default'
660
- default_config = Configuration.new(@args,true).config
661
-
662
- config = {
663
- :base_url => (@args[:base_url] or default_config[:base_url]),
664
- :http_server => {
665
- :port => (@args[:port] or default_config[:http_server][:port]),
666
- :bind_address => (@args[:addr] or default_config[:http_server][:bind_address]),
667
- :rack_require => (@args[:server] or default_config[:http_server][:rack_require])
668
- },
669
- :index_html => {
670
- :title => (@args[:title] or default_config[:index_html][:title])
671
- },
672
- :database => {
673
- :ses_db => (@args[:db] or default_config[:database][:ses_db])
674
- }
675
- }
676
- Signal.trap 'INT' do
677
- puts
678
- puts "Configuration aborted."
679
- exit
680
- end
681
- if interactive
682
- answers_ok = false
683
- until answers_ok
684
- puts ERB.new( @@strs[:initenv][:creating_env] ).result( binding )
685
-
686
- require 'highline/import'
687
-
688
- say @@strs[:initenv][:enter_title]
689
- str_project_title = @@strs[:initenv][:project_title]
690
- config[:index_html][:title] = ask( str_project_title ) do |q|
691
- q.default = config[:index_html][:title]
692
- end
693
-
694
- say @@strs[:initenv][:enter_db_url]
695
- str_db_url = @@strs[:initenv][:db_url]
696
- config[:database][:ses_db] = ask(str_db_url) do |q|
697
- q.default = config[:database][:ses_db]
698
- end
699
-
700
- say @@strs[:initenv][:enter_http_port]
701
- str_http_port = @@strs[:initenv][:http_port]
702
- config[:http_server][:port] = ask(str_http_port) do |q|
703
- q.default = config[:http_server][:port]
704
- end
705
-
706
- say @@strs[:initenv][:enter_tcp_ip]
707
- str_tcp_ip = @@strs[:initenv][:tcp_ip]
708
- config[:http_server][:bind_address] = ask(str_tcp_ip) do |q|
709
- q.default = config[:http_server][:bind_address]
710
- end
711
-
712
- say @@strs[:initenv][:enter_root_dir]
713
- str_root_dir = @@strs[:initenv][:root_dir]
714
- config[:base_url] = ask(str_root_dir) do |q|
715
- q.default = config[:base_url]
716
- end
717
-
718
- test_url = "http://#{config[:http_server][:bind_address]}:#{config[:http_server][:port]}#{config[:base_url]}"
719
- say ERB.new( @@strs[:initenv][:config_summary] ).result( binding )
720
- print @@strs[:initenv][:confirm_config]
721
- answers_ok = yesno(true)
722
- end
723
- else
724
- test_url = "http://#{config[:http_server][:bind_address]}:#{config[:http_server][:port]}#{config[:base_url]}"
725
- end
726
-
727
- puts @@strs[:initenv][:creating_dirs]
728
- env_dir = @args[:env_path]
729
- require 'fileutils'
730
- FileUtils.mkdir_p( env_dir ) unless File.exists?( env_dir )
731
- conf_dir = File.expand_path( 'conf', env_dir )
732
- Dir.mkdir( conf_dir )
733
- db_dir = File.expand_path( 'db', env_dir )
734
- Dir.mkdir( db_dir )
735
- log_dir = File.expand_path( 'log', env_dir )
736
- Dir.mkdir( log_dir )
737
- plugins_dir = File.expand_path( 'plugins', env_dir )
738
- Dir.mkdir( plugins_dir )
739
- run_dir = File.expand_path( 'run', env_dir )
740
- Dir.mkdir( run_dir )
741
- unless create_blank
742
- print @@strs[:initenv][:install_welcome]
743
- if yesno
744
- welcome_plugin_dir = File.join( SERVER_PATH, 'setup', 'welcome' )
745
- welcome_plugin_dst = File.join( plugins_dir, 'welcome' )
746
- puts ERB.new( @@strs[:initenv][:installing_welcome_plugin] ).result( binding )
747
- FileUtils.cp_r( welcome_plugin_dir, welcome_plugin_dst )
748
- end
749
- end
750
- puts @@strs[:initenv][:creating_files]
751
- conf_file = File.join( conf_dir, 'config.yaml' )
752
- File.open( conf_file, 'w' ) {|f| f.write( YAML.dump( config ) ) }
753
- readme_file = File.join( env_dir, 'README' )
754
- File.open( readme_file, 'w' ) {|f| f.write( ERB.new( @@strs[:initenv][:readme] ).result( binding ) ) }
755
- version_file = File.join( env_dir, 'VERSION' )
756
- File.open( version_file, 'w' ) {|f| f.write( "RSence Environment Version #{version.to_f}" ) }
757
- puts ERB.new( @@strs[:initenv][:congratulations] ).result( binding )
758
- exit
759
- end
760
-
761
- # Main parser for the help command
762
- def help( cmd )
763
- cmd.to_sym! if cmd.class != Symbol
764
- puts @@strs[:help][:head]
765
- if @@strs[:help].has_key?(cmd)
766
- puts @@strs[:help][cmd]
767
- else
768
- puts @@strs[:help][:help_main]
769
- end
770
- puts @@strs[:help][:tail]
771
- end
772
-
773
- # Returns the version of RSence
774
- def version
775
- @@version
776
- end
777
-
778
- # Returns the command the process was started with.
779
- def cmd
780
- @cmd
781
- end
782
-
783
- # Returns the parsed optional arguments
784
- def args
785
- @args
786
- end
787
-
788
- # Top-level argument parser, checks for command and calls sub-parser, if valid command.
789
- def parse_argv
790
- if @argv.empty?
791
- puts @@strs[:help][:help_help]
792
- exit
793
- else
794
- cmd = @argv[0].to_sym
795
- cmd = :help if [:h, :'-h', :'--help', :'-help'].include? cmd
796
- end
797
- if @@cmds.include?(cmd)
798
- @cmd = cmd
799
- unless [:help, :version].include?( cmd )
800
- puts "RSence #{@@version} -- Ruby #{RUBY_VERSION}"
801
- end
802
- if cmd == :help
803
- parse_help_argv
804
- elsif cmd == :version
805
- puts version
806
- exit
807
- elsif [:run,:start,:stop,:restart].include? cmd
808
- parse_startup_argv
809
- elsif cmd == :status
810
- parse_status_argv
811
- elsif cmd == :save
812
- parse_save_argv
813
- elsif cmd == :initenv or cmd == :init
814
- parse_initenv_argv
815
- end
816
- else
817
- puts @@strs[:help][:unknown] + cmd.to_s.inspect
818
- puts @@strs[:help][:help_help]
819
- exit
820
- end
821
- end
822
-
823
- # Entry point for ARGV parsing
824
- def parse( argv )
825
- @argv = argv
826
- @startable = false
827
- parse_argv
828
- end
829
-
830
- # The constructor sets the @startable flag as false. Use the #parse method with ARGV as the argument to start parsing the ARGV.
831
- def initialize
832
- @startable = false
833
- end
834
-
835
- end
836
-
837
- # @private The ARGVParser instance and its startup
838
- @@argv_parser = ARGVParser.new
839
- @@argv_parser.parse( ARGV )
840
-
841
- end
842
-