lib/spiderfw/cmd/commands/setup.rb in spiderfw-0.6.16 vs lib/spiderfw/cmd/commands/setup.rb in spiderfw-0.6.17

- old
+ new

@@ -1,7 +1,5 @@ -require 'spiderfw/setup/setup_task' - class SetupCommand < CmdParse::Command def initialize super( 'setup', false, true ) @@ -21,14 +19,17 @@ @version = Gem::Version.new(v) } opt.on("--all", _("Setup all active apps")){ |all| @all = true } + opt.on("--no-cleanup", _("Don't cleanup"), "-C"){ |no_cleanup| @no_cleanup = true } end set_execution_block do |apps| - require 'spiderfw' + $SPIDER_INTERACTIVE = true + require 'spiderfw/spider' + Spider.init_base apps = Spider.apps.keys if @all if (apps.length > 1) && (@to || @from || @version) raise "Can't use --from, --to or --version with multiple apps" end if apps.length == 0 @@ -36,51 +37,23 @@ wizard = Spider::SpiderSetupWizard.new wizard.implementation(Spider::ConsoleWizard) wizard.run end + tasks = [] apps.each do |name| - Spider.load_app(name) unless Spider.apps[name] - app = Spider.apps[name] - path = app.setup_path - current = @from || app.installed_version - new_version = @to || app.version - next unless File.exist?(path) - tasks = [] - if @version - tasks = ["#{@version}.rb"] - else - tasks = Dir.entries(path).reject{ |p| p[0].chr == '.'}.sort{ |a, b| - va = Gem::Version.new(File.basename(a, '.rb')) - vb = Gem::Version.new(File.basename(b, '.rb')) - va <=> vb - } - if @from || @to - tasks.reject!{ |t| - v = Gem::Version.new(File.basename(t, '.rb')) - true if @from && v < @from - true if @to && v > @to - false - } - end - end - done_tasks = [] - Spider::Model::Managed.no_set_dates = true - tasks.each do |task| - Spider.logger.info("Running setup task #{path+'/'+task}") - t = Spider::SetupTask.load("#{path}/#{task}") - t.app = app + require 'spiderfw/setup/app_manager' + tasks += Spider::AppManager.new.setup(name) + end + unless @no_cleanup + tasks.each do |t| begin - done_tasks << t - t.do_up + t.do_cleanup rescue => exc - done_tasks.each{ |dt| dt.do_down } # FIXME: rescue and log errors in down - raise + Spider.logger.error(exc) end end - Spider::Model::Managed.no_set_dates = false - app.installed_version = app.version - end + end end end \ No newline at end of file