Class: PostRunner::Main
- Inherits:
-
Object
- Object
- PostRunner::Main
- Includes:
- DirUtils
- Defined in:
- lib/postrunner/Main.rb
Instance Method Summary collapse
-
#initialize ⇒ Main
constructor
A new instance of Main.
- #main(args) ⇒ Object
Methods included from DirUtils
Constructor Details
#initialize ⇒ Main
Returns a new instance of Main.
33 34 35 36 37 38 39 40 |
# File 'lib/postrunner/Main.rb', line 33 def initialize @filter = nil @name = nil @force = false @attribute = nil @value = nil @db_dir = File.join(ENV['HOME'], '.postrunner') end |
Instance Method Details
#main(args) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/postrunner/Main.rb', line 42 def main(args) return 0 if (args = (args)).nil? unless $DEBUG Kernel.trap('INT') do begin Log.fatal('Aborting on user request!') rescue RuntimeError exit 1 end end end begin create_directory(@db_dir, 'PostRunner data') @db = PEROBS::Store.new(File.join(@db_dir, 'database')) # Create a hash to store configuration data in the store unless it # exists already. cfg = (@db['config'] ||= @db.new(PEROBS::Hash)) cfg['unit_system'] ||= :metric cfg['version'] ||= VERSION # We always override the data_dir as the user might have moved the data # directory. The only reason we store it in the DB is to have it # available throught the application. cfg['data_dir'] = @db_dir # Always update html_dir setting so that the DB directory can be moved # around by the user. cfg['html_dir'] = File.join(@db_dir, 'html') setup_directories return execute_command(args) rescue Exception => e if e.is_a?(SystemExit) || e.is_a?(Interrupt) $stderr.puts e.backtrace.join("\n") if $DEBUG elsif e.is_a?(Fit4Ruby::Abort) # Programm execution error that does not warrant a backtrace to be # printed. return -1 else Log.error("#{e}\n#{e.backtrace.join("\n")}\n\n" + "#{'*' * 79}\nYou have triggered a bug in PostRunner " + "#{VERSION}!") end return -1 end end |