commit 817efdf91da35c42cbf003ee24fecdcc9a3fa3da
parent 9ae66dc7cca5f99473a477eea7af0fc89003e6ef
Author: Whyme Lyu <callme5long@gmail.com>
Date: Wed, 29 May 2013 00:09:30 +0800
Now sources.yaml migration is just load & save
Diffstat:
2 files changed, 13 insertions(+), 34 deletions(-)
diff --git a/bin/sup-psych-ify-config-files b/bin/sup-psych-ify-config-files
@@ -1,37 +1,16 @@
#!/usr/bin/env ruby
-unless RUBY_VERSION =~ /^1.9/ then
- STDERR.puts "This tool is made for MRI 1.9"
- exit 1
-end
+$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
-require 'fileutils'
-require 'yaml'
-begin
- require 'psych'
- require 'syck'
-rescue LoadError => e
- STDERR.puts 'sup-psych-ify-config-files: We need to be able to require both psych and syck for this conversion'
- raise
-end
+require "sup"
+require "fileutils"
-# From: http://darwinweb.net/articles/convert-syck-to-psych-yaml-format
-def use_syck
- YAML::ENGINE.yamler = 'syck'
- raise "Oops! Something went horribly wrong." unless YAML == Syck
-end
-def use_psych
- YAML::ENGINE.yamler = 'psych'
- raise "Oops! Something went horribly wrong." unless YAML == Psych
-end
-#
+Redwood.start
-Dir.glob(Dir.home + "/.sup/*yaml").each do |yaml_file|
- print "Converting #{yaml_file}..."
- use_syck
- y = YAML.load(File.read yaml_file)
- FileUtils.cp yaml_file, "#{yaml_file}.syck_bak"
- use_psych
- File.open(yaml_file, 'w'){ |file| file.write(YAML.dump(y)) }
- puts "Done."
-end
+fn = Redwood::SOURCE_FN
+FileUtils.cp fn, "#{fn}.syck_bak"
+
+Redwood::SourceManager.load_sources fn
+Redwood::SourceManager.save_sources fn, true
+
+Redwood.finish
diff --git a/lib/sup/source.rb b/lib/sup/source.rb
@@ -209,9 +209,9 @@ class SourceManager
end
end
- def save_sources fn=Redwood::SOURCE_FN
+ def save_sources fn=Redwood::SOURCE_FN, force=false
@source_mutex.synchronize do
- if @sources_dirty
+ if @sources_dirty || force
Redwood::save_yaml_obj sources, fn, false, true
end
@sources_dirty = false