spiderfw 0.6.16 → 0.6.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/CHANGELOG +9 -0
  2. data/Rakefile +8 -5
  3. data/VERSION +1 -1
  4. data/apps/core/auth/data/locale/it/LC_MESSAGES/spider_auth.mo +0 -0
  5. data/apps/core/auth/po/it/spider_auth.po +3 -3
  6. data/apps/core/auth/po/spider_auth.pot +3 -3
  7. data/apps/core/components/data/locale/it/LC_MESSAGES/spider_components.mo +0 -0
  8. data/apps/core/components/po/it/spider_components.po +7 -7
  9. data/apps/core/components/po/spider_components.pot +7 -7
  10. data/apps/core/components/public/js/spider.js +4 -2
  11. data/apps/core/forms/data/locale/it/LC_MESSAGES/spider_forms.mo +0 -0
  12. data/apps/core/forms/po/it/spider_forms.po +2 -2
  13. data/apps/core/forms/po/spider_forms.pot +2 -2
  14. data/apps/core/forms/widgets/form/form.rb +20 -6
  15. data/apps/master/_init.rb +0 -1
  16. data/apps/master/data/locale/it/LC_MESSAGES/master.mo +0 -0
  17. data/apps/master/master.rb +4 -0
  18. data/apps/master/po/it/master.po +62 -25
  19. data/apps/master/po/master.pot +45 -20
  20. data/apps/messenger/_init.rb +2 -21
  21. data/apps/messenger/backends/sms/test.rb +25 -0
  22. data/apps/messenger/config/test.config.yml +6 -1
  23. data/apps/messenger/controllers/mixins/messenger_helper.rb +30 -5
  24. data/apps/messenger/data/locale/it/LC_MESSAGES/spider_messenger.mo +0 -0
  25. data/apps/messenger/messenger.rb +40 -2
  26. data/apps/servant/lib/commands_processor.rb +1 -1
  27. data/apps/worker/worker.rb +15 -10
  28. data/data/locale/it/LC_MESSAGES/spider.mo +0 -0
  29. data/lib/spiderfw/app.rb +3 -3
  30. data/lib/spiderfw/cache/template_cache.rb +4 -0
  31. data/lib/spiderfw/cmd/cmd.rb +0 -2
  32. data/lib/spiderfw/cmd/commands/app.rb +89 -6
  33. data/lib/spiderfw/cmd/commands/setup.rb +13 -40
  34. data/lib/spiderfw/config/configuration.rb +1 -0
  35. data/lib/spiderfw/config/options/spider.rb +9 -8
  36. data/lib/spiderfw/controller/mixins/http_mixin.rb +9 -0
  37. data/lib/spiderfw/env.rb +3 -1
  38. data/lib/spiderfw/i18n/cldr.rb +39 -13
  39. data/lib/spiderfw/i18n/i18n.rb +9 -0
  40. data/lib/spiderfw/i18n/javascript_parser.rb +1 -1
  41. data/lib/spiderfw/i18n/shtml_parser.rb +1 -1
  42. data/lib/spiderfw/model/base_model.rb +1 -1
  43. data/lib/spiderfw/model/inline_model.rb +13 -1
  44. data/lib/spiderfw/model/mappers/db_mapper.rb +5 -0
  45. data/lib/spiderfw/model/mappers/mapper.rb +9 -4
  46. data/lib/spiderfw/model/migrations/drop_element.rb +26 -0
  47. data/lib/spiderfw/model/migrations/irreversible_migration.rb +9 -0
  48. data/lib/spiderfw/model/migrations/migration.rb +7 -0
  49. data/lib/spiderfw/model/migrations/replace.rb +32 -0
  50. data/lib/spiderfw/model/migrations.rb +21 -0
  51. data/lib/spiderfw/model/model.rb +4 -1
  52. data/lib/spiderfw/model/storage/db/db_storage.rb +1 -1
  53. data/lib/spiderfw/setup/app_manager.rb +281 -200
  54. data/lib/spiderfw/setup/setup_task.rb +80 -35
  55. data/lib/spiderfw/spider.rb +28 -13
  56. data/lib/spiderfw/templates/layout.rb +40 -8
  57. data/lib/spiderfw/templates/resources/sass.rb +21 -0
  58. data/lib/spiderfw/test.rb +1 -1
  59. data/lib/spiderfw/utils/events/event_source.rb +1 -2
  60. data/lib/spiderfw/utils/gems.rb +5 -1
  61. metadata +11 -4
@@ -3,53 +3,33 @@ require 'fileutils'
3
3
 
4
4
  module Spider
5
5
 
6
- module AppManager
6
+ class AppManager
7
7
 
8
- def self.install_or_update(apps, options={})
8
+ def self.installed?(app)
9
9
  require 'spiderfw/home'
10
- home = Spider::Home.new(Dir.pwd)
11
- installed = {}
12
10
  Spider.init_base
13
- active = Spider.config.get('apps')
14
- Spider.home.apps.each do |app, info|
15
- installed[app] = {
16
- :active => active.include?(app)
17
- }
18
- if spec = info[:spec]
19
- installed[app].merge!({
20
- :version => spec.version
21
- })
22
- end
23
- end
24
- to_inst = apps.select{ |a| !installed[a] }
25
- to_upd = apps.select{ |a| installed[a] }
26
- install_apps(to_inst, options)
27
- update_apps(to_upd, options)
28
- return {:installed => to_inst, :updated => to_upd}
11
+ @home_apps ||= Spider.home.apps
12
+ @home_apps[app]
29
13
  end
30
14
 
31
- def self.install_apps(apps, options={})
32
- return if apps.empty?
33
- require 'spiderfw/setup/app_server_client'
34
- use_git = false
35
- if options[:git]
36
- begin
37
- require 'git'
38
- use_git = true
39
- rescue LoadError => exc
40
- Spider.output exc.message, :ERROR
41
- Spider.output "git gem not available; install git gem for Git support", :ERROR
42
- end
43
- end
44
-
45
- existent = []
46
- apps.each do |app|
47
- if File.exist?("apps/#{app}")
48
- Spider.output _("%s already exists, skipping") % app
49
- existent << app
50
- end
15
+ def self.git_available?
16
+ begin
17
+ require 'git'
18
+ return true
19
+ rescue LoadError => exc
20
+ return false
51
21
  end
52
- require 'spiderfw/setup/app_manager'
22
+ end
23
+
24
+ def self.tmp_path(home_path)
25
+ tmp_path = File.join(home_path, 'tmp', 'app_update')
26
+ end
27
+
28
+ def tmp_path
29
+ self.class.tmp_path(@home_path)
30
+ end
31
+
32
+ def self.resolve(apps, options={})
53
33
  specs = []
54
34
  url = options[:url]
55
35
  unless url
@@ -57,152 +37,100 @@ module Spider
57
37
  Spider.init_base
58
38
  url = Spider.config.get('app_server.url')
59
39
  end
40
+ install = []
41
+ update = []
42
+ res = {:install => install, :update => update}
43
+ return res if apps.empty?
44
+ require 'spiderfw/setup/app_server_client'
60
45
  client = Spider::AppServerClient.new(url)
61
46
  if options[:no_deps]
62
47
  specs = client.get_specs(apps)
63
48
  else
64
49
  specs = client.get_deps(apps, :no_optional => !options[:optional])
65
50
  end
66
- deps = specs.map{ |s| s.app_id }
67
- unless (deps - apps).empty?
68
- Spider.output _("The following apps will be installed as a dependency:")
69
- Spider.output((deps - apps).inspect)
70
- end
71
- i_options = {
72
- :use_git => use_git,
73
- :no_gems => options[:no_gems],
74
- :no_optional_gems => options[:no_optional_gems]
75
- }
76
- i_options[:ssh_user] = options[:ssh_user] if options[:ssh_user]
77
- inst_specs = specs.reject{ |s| existent.include? s.app_id }
78
- Spider::AppManager.install(inst_specs, Dir.pwd, i_options)
79
- unless options[:no_activate]
80
- require 'spiderfw/spider'
81
- specs_hash = {}
82
- specs.each{ |s| specs_hash[s.app_id] = s }
83
- Spider.activate_apps(deps, specs_hash)
51
+ specs.each do |spec|
52
+ if prev = installed?(spec.app_id)
53
+ if (options[:refresh] && options[:refresh].include?(spec.app_id) ) || (prev[:spec] && prev[:spec].version < spec.version)
54
+ update << spec
55
+ end
56
+ else
57
+ install << spec
58
+ end
84
59
  end
85
-
60
+ return res
86
61
  end
87
62
 
88
- def self.update_apps(apps, options={})
89
- require 'spiderfw/spider'
90
- require 'spiderfw/setup/app_server_client'
91
- Spider.init_base
92
- url = options[:url] || Spider.conf.get('app_server.url')
93
- if options[:all]
94
- require 'spiderfw/home'
95
- home = Spider::Home.new(Dir.pwd)
96
- apps = home.list_apps
97
- end
98
- if apps.empty?
99
- Spider.output _("No app to update")
100
- exit
101
- end
102
- specs = []
103
- client = Spider::AppServerClient.new(url)
104
- if options[:no_deps]
105
- specs = client.get_specs(apps)
106
- else
107
- specs = client.get_deps(apps, :no_optional => options[:no_optional])
108
- end
109
- deps = specs.map{ |s| s.app_id }
110
- unless (deps - apps).empty?
111
- Spider.output _("The following apps will be updated as a dependency:")
112
- Spider.output((deps - apps).inspect)
113
- end
114
- Spider::AppManager.update(specs, Dir.pwd, {
115
- :use_git => !options[:no_git],
116
- :no_gems => options[:no_gems],
117
- :no_optional_gems => options[:no_optional_gems]
118
- })
63
+ def self.get_apps(apps, options={})
64
+ specs = resolve(apps, options)
65
+ manager = self.new(options)
66
+ manager.install(specs)
67
+ return specs
119
68
  end
120
69
 
121
- def self.install(specs, home_path, options)
122
- options[:home_path] = home_path
123
- specs = [specs] if specs && !specs.is_a?(Array)
124
- specs ||= []
125
- pre_setup(specs, options)
126
- specs.each do |spec|
127
- app_path = File.join(home_path, "apps/#{spec.app_id}")
128
- if File.directory?(app_path)
129
- if File.directory?(File.join(app_path, '.git'))
130
- git_update(spec, home_path, options)
131
- else
132
- pack_update(spec, home_path, options)
133
- end
134
- else
135
- if spec.git_repo && options[:use_git]
136
- git_install(spec, home_path, options)
137
- else
138
- pack_install(spec, home_path, options)
139
- end
70
+
71
+ def install(specs, options)
72
+ options[:home_path] ||= Dir.pwd
73
+ @home_path = options[:home_path]
74
+ all_specs = specs[:install] + specs[:update]
75
+
76
+ pre_run(all_specs, options)
77
+ specs[:install].each do |spec|
78
+ do_install(spec, options)
79
+ end
80
+ pre_update(specs[:update], options)
81
+ begin
82
+ specs[:update].each do |spec|
83
+ do_update(spec, options)
140
84
  end
85
+ post_update(specs[:update], options)
86
+ rescue => exc
87
+ rollback_update
88
+ raise
89
+ end
90
+ unless options[:no_activate]
91
+ require 'spiderfw/spider'
92
+ specs_hash = {}
93
+ all_specs.each{ |s| specs_hash[s.app_id] = s }
94
+ Spider.activate_apps(specs[:install].map{ |s| s.app_id }, specs_hash)
141
95
  end
142
- post_setup(specs, options)
96
+ Spider.output _("Install done.")
143
97
  end
144
98
 
145
- def self.git_install(spec, home_path, options={})
146
- require 'git'
147
- if ::File.exist?("apps/#{spec.id}")
148
- Spider.output _("%s already installed, skipping") % spec.id
149
- return
99
+ def do_install(spec, options)
100
+ app_path = File.join(@home_path, "apps/#{spec.app_id}")
101
+ raise "App #{spec.app_id} is already installed" if File.exists?(app_path)
102
+ use_git = false
103
+ if spec.git_repo && options[:use_git]
104
+ use_git = true
150
105
  end
151
- repo = Git.open(home_path)
152
- repo_url = spec.git_repo_rw || spec.git_repo
153
- Spider.output _("Fetching %s from %s") % [spec.app_id, repo_url]
154
-
155
- if options[:ssh_user] && repo_url =~ /ssh:\/\/([^@]+@)?(.+)/
156
- repo_url = "ssh://#{options[:ssh_user]}@#{$2}"
106
+ if use_git && !self.class.git_available?
107
+ Spider.output _("Can't install app #{spec.id} via git, since git gem is not available") % spec.app_id, :ERROR
157
108
  end
158
-
159
- ENV['GIT_WORK_TREE'] = nil
160
- Dir.chdir(home_path) do
161
- `git submodule add #{repo_url} apps/#{spec.id}`
162
- `git submodule init`
163
- `git submodule update`
109
+ if use_git
110
+ git_install(spec, options)
111
+ else
112
+ pack_install(spec, options)
164
113
  end
165
- repo.add(['.gitmodules', "apps/#{spec.id}"])
166
- repo.commit(_("Added app %s") % spec.id)
167
114
  end
168
115
 
169
- def self.pack_install(spec, home_path, options={})
170
- require 'rubygems/package'
171
- client = AppServerClient.new(spec.app_server)
172
- print _("Fetching %s from server... ") % spec.app_id
173
- tmp_path = client.fetch_app(spec.app_id)
174
- Spider.output _("Fetched.")
175
- dest = File.join(home_path, "apps/#{spec.app_id}")
176
- FileUtils.mkdir_p(dest)
177
- open tmp_path, Gem.binary_mode do |io|
178
- Gem::Package::TarReader.new(io) do |reader|
179
- reader.each do |entry|
180
- dest_path = File.join(dest, entry.full_name)
181
- if entry.directory?
182
- FileUtils.mkdir(dest_path)
183
- elsif entry.file?
184
- File.open(dest_path, 'w') do |f|
185
- f << entry.read
186
- end
187
- end
188
- end
189
- end
116
+
117
+ def do_update(spec, options)
118
+ use_git = false
119
+ if spec.git_repo && !options[:no_git]
120
+ app_path = File.join(@home_path, "apps/#{spec.app_id}")
121
+ use_git = true if File.directory?(File.join(app_path, '.git'))
190
122
  end
191
- if File.directory?(File.join(home_path, '.git'))
192
- begin
193
- require 'git'
194
- rescue LoadError
195
- end
196
- begin
197
- repo = Git.open(home_path)
198
- repo.add("apps/#{spec.id}")
199
- repo.commit(_("Added app %s") % spec.id)
200
- rescue => exc
201
- end
123
+ if use_git && !self.class.git_available?
124
+ Spider.output _("Can't update app #{spec.id} via git, since git gem is not available") % spec.app_id, :ERROR
125
+ end
126
+ if use_git
127
+ git_update(spec, options)
128
+ else
129
+ pack_update(spec, options)
202
130
  end
203
131
  end
204
132
 
205
- def self.pre_setup(specs, options={})
133
+ def pre_run(specs, options={})
206
134
  require 'rubygems'
207
135
  require 'rubygems/command.rb'
208
136
  require 'rubygems/dependency_installer.rb'
@@ -244,47 +172,137 @@ module Spider
244
172
  end
245
173
  end
246
174
 
247
- def self.pre_update(specs, options={})
248
- end
249
-
250
- def self.post_setup(specs, options={})
175
+ def self.post_run(specs, options={})
251
176
  #require 'bundler'
252
177
  #Bundler::Installer.install(options[:home_path], Bundler.definitions, {})
253
178
  end
254
179
 
255
- def self.update(specs, home_path, options)
256
- specs = [specs] unless specs.is_a?(Array)
257
- pre_setup(specs, options)
258
- pre_update(specs, options)
259
- git_available = nil
180
+ def pre_update(specs, options={})
181
+ tmp_path = File.join(self.tmp_path, "update-#{DateTime.now.strftime('%Y%m%d-%H%M')}")
182
+ @backup_path = tmp_path
183
+ FileUtils.mkdir_p(tmp_path)
260
184
  specs.each do |spec|
261
- use_git = false
262
- if spec.git_repo && options[:use_git]
263
- app_path = File.join(home_path, "apps/#{spec.id}")
264
- use_git = true if File.directory?(File.join(app_path, '.git'))
265
- end
266
- use_git = false if git_available == false
267
- if use_git && git_available.nil?
185
+ app_path = File.join(@home_path, 'apps', spec.id)
186
+ FileUtils.cp_r(app_path, tmp_path)
187
+ end
188
+ end
189
+
190
+ def post_update(specs, options)
191
+ return if specs.empty?
192
+ require 'spiderfw/home'
193
+ Spider.init_base
194
+ @done_tasks = {}
195
+ specs.each do |spec|
196
+ prev_spec = Spider.home.apps[spec.app_id][:spec]
197
+ prev_v = prev_spec.version if prev_spec
198
+ @done_tasks[spec.app_id] = setup(spec.app_id, prev_v, spec.version)
199
+ end
200
+ Spider.output _("Doing cleanup...")
201
+ @done_tasks.each do |app, tasks|
202
+ next unless tasks
203
+ tasks.each do |task|
268
204
  begin
269
- require 'git'
270
- use_git = true
271
- rescue LoadError => exc
272
- Spider.output "git gem not available; install git gem for Git support"
273
- use_git = false
205
+ task.do_cleanup
206
+ rescue => exc
207
+ Spider.logger.error("Cleanup failed for #{app}:")
208
+ Spider.logger.error(exc)
274
209
  end
275
210
  end
276
- if use_git
277
- git_update(spec, home_path, options)
278
- else
279
- pack_update(spec, home_path, options)
211
+ end
212
+ if options[:clear_cache]
213
+ Spider.output _("Clearing cache...")
214
+ Spider::Template.cache.clear!
215
+ Spider::Layout.clear_compiled_folder!
216
+ end
217
+ if options[:restart]
218
+ Spider.output _("Restarting server...")
219
+ Spider.restart!
220
+ end
221
+ Spider.output _("Post-update done")
222
+ end
223
+
224
+ def rollback_update
225
+ Dir.new(@backup_path).each do |app|
226
+ next if app[0].chr == '.'
227
+ installed = File.join(@home_path, 'apps', app)
228
+ FileUtils.rm_rf(installed) if File.exists?(installed)
229
+ FileUtils.mv(File.join(@backup_path, app), installed)
230
+ end
231
+ if @done_tasks
232
+ @done_tasks.each do |app, tasks|
233
+ next unless tasks
234
+ tasks.reverse.each do |task|
235
+ task.down
236
+ end
280
237
  end
281
238
  end
282
239
  end
283
240
 
284
- def self.git_update(spec, home_path, options={})
241
+
242
+ def git_install(spec, options={})
243
+ require 'git'
244
+ if ::File.exist?("apps/#{spec.id}")
245
+ Spider.output _("%s already installed, skipping") % spec.id
246
+ return
247
+ end
248
+ repo = Git.open(@home_path)
249
+ repo_url = spec.git_repo_rw || spec.git_repo
250
+ Spider.output _("Fetching %s from %s") % [spec.app_id, repo_url]
251
+
252
+ if options[:ssh_user] && repo_url =~ /ssh:\/\/([^@]+@)?(.+)/
253
+ repo_url = "ssh://#{options[:ssh_user]}@#{$2}"
254
+ end
255
+
256
+ ENV['GIT_WORK_TREE'] = nil
257
+ Dir.chdir(@home_path) do
258
+ `git submodule add #{repo_url} apps/#{spec.id}`
259
+ `git submodule init`
260
+ `git submodule update`
261
+ end
262
+ repo.add(['.gitmodules', "apps/#{spec.id}"])
263
+ repo.commit(_("Added app %s") % spec.id)
264
+ end
265
+
266
+ def pack_install(spec, options={})
267
+ require 'rubygems/package'
268
+ client = AppServerClient.new(spec.app_server)
269
+ print _("Fetching %s from server... ") % spec.app_id
270
+ tmp_path = client.fetch_app(spec.app_id)
271
+ Spider.output _("Fetched.")
272
+ dest = File.join(@home_path, "apps/#{spec.app_id}")
273
+ FileUtils.mkdir_p(dest)
274
+ open tmp_path, Gem.binary_mode do |io|
275
+ Gem::Package::TarReader.new(io) do |reader|
276
+ reader.each do |entry|
277
+ dest_path = File.join(dest, entry.full_name)
278
+ if entry.directory?
279
+ FileUtils.mkdir(dest_path)
280
+ elsif entry.file?
281
+ File.open(dest_path, 'w') do |f|
282
+ f << entry.read
283
+ end
284
+ end
285
+ end
286
+ end
287
+ end
288
+ if File.directory?(File.join(@home_path, '.git'))
289
+ begin
290
+ require 'git'
291
+ rescue LoadError
292
+ end
293
+ begin
294
+ repo = Git.open(home_path)
295
+ repo.add("apps/#{spec.id}")
296
+ repo.commit(_("Added app %s") % spec.id)
297
+ rescue => exc
298
+ end
299
+ end
300
+ end
301
+
302
+ def git_update(spec, options={})
285
303
  require 'git'
286
- home_repo = Git.open(home_path)
287
- app_path = File.join(home_path, "apps/#{spec.id}")
304
+ home_repo = Git.open(@home_path)
305
+ app_path = File.join(@home_path, "apps", spec.id)
288
306
  app_repo = Git.open(app_path)
289
307
  Spider.output _("Updating %s from %s") % [spec.app_id, spec.git_repo]
290
308
  Dir.chdir(app_path) do
@@ -292,11 +310,12 @@ module Spider
292
310
  end
293
311
  response = err = nil
294
312
  Dir.chdir(app_path) do
295
- `git --git-dir='#{app_path}/.git' pull origin master`
313
+ response = `git --git-dir='#{app_path}/.git' pull origin master`
296
314
  end
315
+ require 'ruby-debug'
297
316
  if response =~ /Aborting/
298
317
  Spider.output err, :ERROR
299
- return
318
+ raise "Unable to update"
300
319
  end
301
320
  Dir.chdir(app_path) do
302
321
  app_repo.reset('HEAD', :hard => true)
@@ -304,20 +323,24 @@ module Spider
304
323
  end
305
324
 
306
325
  home_repo.add("apps/#{spec.id}")
307
- home_repo.commit(_("Updated app %s") % spec.id)
326
+ begin
327
+ home_repo.commit(_("Updated app %s") % spec.id)
328
+ rescue => exc
329
+ raise unless exc.message =~ /no changes added to commit/
330
+ end
308
331
  end
309
332
 
310
- def self.pack_update(spec, home_path, options={})
333
+ def pack_update(spec, options={})
311
334
  require 'fileutils'
312
335
  require 'date'
313
336
  require 'time'
314
- app_path = File.join(home_path, "apps/#{spec.id}")
315
- tmp_path = File.join(home_path, 'tmp')
337
+ app_path = File.join(@home_path, "apps/#{spec.id}")
338
+ tmp_path = self.tmp_path
316
339
  FileUtils.mkdir_p(tmp_path)
317
340
  tmp_app_path = File.join(tmp_path, "#{spec.id}-update-#{DateTime.now.strftime('%Y%m%d-%H%M')}")
318
341
  begin
319
342
  FileUtils.mv(app_path, tmp_app_path)
320
- rescue Errno::EACCESS
343
+ rescue Errno::EACCES
321
344
  if RUBY_PLATFORM =~ /win32|mingw/
322
345
  Spider.output(
323
346
  _("Can't update #{spec.id} app: ensure you have no files or folders of this app open"),
@@ -326,19 +349,77 @@ module Spider
326
349
  else
327
350
  Spider.output exc, :ERROR
328
351
  end
352
+ exit
329
353
  end
330
354
  begin
331
- pack_install(spec, home_path)
355
+ pack_install(spec, options)
332
356
  FileUtils.rm_rf(tmp_app_path)
333
357
  rescue => exc
334
358
  Spider.output _("Update of %s failed") % spec.id, :ERROR
335
359
  Spider.output exc, :ERROR
336
360
  FileUtils.rm_rf(app_path)
337
361
  FileUtils.mv(tmp_app_path, app_path)
362
+ raise
338
363
  end
339
364
  end
340
365
 
366
+ def setup(name, from=nil, to=nil)
367
+ require 'spiderfw/setup/setup_task'
368
+ Spider.init
369
+ Spider.load_app(name) unless Spider.apps[name]
370
+ app = Spider.apps_by_short_name[name]
371
+ path = app.setup_path
372
+ unless to
373
+ version = from
374
+ from = nil
375
+ end
376
+ current = from || app.installed_version
377
+ new_version = to || app.version
378
+ return unless File.exist?(path)
379
+ tasks = []
380
+ if version
381
+ tasks = ["#{@version}.rb"]
382
+ else
383
+ tasks = Dir.entries(path).reject{ |p| p[0].chr == '.'}.sort{ |a, b|
384
+ va = Gem::Version.new(File.basename(a, '.rb'))
385
+ vb = Gem::Version.new(File.basename(b, '.rb'))
386
+ va <=> vb
387
+ }
388
+ if from || to
389
+ tasks.reject!{ |t|
390
+ v = Gem::Version.new(File.basename(t, '.rb'))
391
+ if from && v <= from
392
+ true
393
+ elsif to && v > to
394
+ true
395
+ else
396
+ false
397
+ end
398
+ }
399
+ end
400
+ end
401
+ done_tasks = []
402
+
403
+ tasks.each do |task|
404
+ Spider.output _("Running setup task #{path+'/'+task}...")
405
+ t = Spider::SetupTask.load("#{path}/#{task}")
406
+ t.app = app
407
+ begin
408
+ done_tasks << t
409
+ t.do_sync
410
+ t.do_up
411
+ Spider.output _("Setup task done")
412
+ rescue => exc
413
+ Spider.output exc, :ERROR
414
+ done_tasks.reverse.each{ |dt| dt.do_down } # FIXME: rescue and log errors in down
415
+ raise
416
+ end
417
+ end
418
+ app.installed_version = app.version
419
+ done_tasks
420
+ end
421
+
341
422
 
342
423
  end
343
424
 
344
- end
425
+ end