334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
# File 'lib/satops.rb', line 334
def initialize(params)
@command=""
@config_file=nil
@file_to_run=nil
@options=nil
@log_file=STDOUT
@sat_file=nil
@sat_source=nil
@sat_target=nil
@ssl=false
unless (params.include?('-s') && params.include?('-c')) || params.include?('show')
Launcher.usage
end
until params.empty?
case params[0]
when '-c', '--config='
params.shift
@config_file=params[0]
when '-d', '--debug'
$DEBUG=true
when '-h', '--help'
Launcher.usage
when '-t', '--tls'
@ssl=true
overwrite_net_http
when '-l', '--log='
params.shift
@log_file=params[0]
when '-s', '--satfile='
params.shift
@sat_file=params[0]
when '-w', '--warnings'
$VERBOSE=true
when 'clone'
operation_size?(params, 3)
@command='clone'
params.shift
@name=params[0].to_sym
params.shift
@new_name=params[0]
when 'destroy'
operation_size?(params, 1)
@command='destroy'
when 'sync'
operation_size?(params, 1)
@command='sync'
when 'extras'
operation_size?(params, 1)
@command='extra'
when 'export'
operation_size?(params, 3)
@command='export'
params.shift
@path=params[0]
params.shift
@format=params[0].to_sym
when 'import'
operation_size?(params, 3)
@command='import'
params.shift
@path=params[0]
params.shift
@format=params[0].to_sym
when 'run'
operation_size?(params, 2)
@command='run'
params.shift
@file_to_run=params[0]
when 'show'
params.shift
case params[0]
when 'sat'
puts satellites_syntax
when 'config'
puts config_syntax
else
puts "Use 'show sat' or 'show config' commands"
end
exit
else
Launcher.usage
end
params.shift
end
begin
@log = Logger.new(@log_file)
@log.datetime_format = "%d/%m/%Y %H:%M:%S"
if $DEBUG
@log.level = Logger::DEBUG
else
@log.level = Logger::INFO
end
@log.info("Starting #{@command.upcase} command")
File.open(@sat_file) do |f|
@sat_config = YAML.load(f)
end
File.open(@config_file) do |f|
@options = YAML.load(f)
end
case @command
when 'clone'
init_target
SatOperator.new(@options, @log).clone(@name, @new_name)
when 'destroy'
init_target
SatOperator.new(@options, @log).destroy(@sat_target)
when 'export'
init_source
SatOperator.new(@options, @log).export(@format, @sat_source, @path)
when 'extra'
init_source
init_target
SatOperator.new(@options, @log).(@sat_source, @sat_target)
when 'import'
init_target
SatOperator.new(@options, @log).import(@format, @sat_target, @path)
when 'sync'
init_source
init_target
SatOperator.new(@options, @log).sync(@sat_source, @sat_target)
when 'run'
def run
puts "###\nExcuting #@file_to_run\n###"
yield
end
init_source
init_target
lines=""
File.open(@file_to_run).each do |line|
lines << line
end
block=eval(lines)
run(&block)
end
rescue SystemCallError => e
@log.fatal "#{e}"
exit
ensure
if @sat_source
@sat_source.terminate
end
if @sat_target
@sat_target.terminate
end
@log.info("Finished #{@command.upcase} command")
@log.close
end
end
|