[SCM] vim-addon-manager packaging branch, master, updated. v0.4.4-65-g995b8fc

Antonio Terceiro terceiro at debian.org
Wed Mar 14 01:09:06 UTC 2012


The following commit has been merged in the master branch:
commit 72bbdc46e9077015c2de96baddcf80fe789aba19
Author: Antonio Terceiro <terceiro at debian.org>
Date:   Tue Mar 6 08:36:27 2012 -0300

    upgrade-from-legacy action

diff --git a/bin/vim-addons b/bin/vim-addons
index 6b2ec79..8076c57 100755
--- a/bin/vim-addons
+++ b/bin/vim-addons
@@ -198,7 +198,7 @@ def parse_cmdline
     :query        => false,
     :system_wide  => false,
   }
-  cmds = %w{install remove disable enable list status files show}
+  cmds = %w{install remove disable enable list status files show upgrade-from-legacy}
   req_arg_cmds = # commands requiring >= 1 arg
     %w{install remove disable amend files}
   cmdline =
@@ -269,6 +269,9 @@ when 'status'
   end
 when 'files'
   selected_addons.each {|a| puts a.files.to_a}
+when 'upgrade-from-legacy'
+  mgr = Vim::AddonManager.new options[:target_dir]
+  mgr.upgrade_from_legacy(registry.to_a)
 else
   mgr = Vim::AddonManager.new options[:target_dir]
   mgr.send cmd, selected_addons
diff --git a/features/step_definitions/steps.rb b/features/step_definitions/steps.rb
index 5d19341..61b41a5 100644
--- a/features/step_definitions/steps.rb
+++ b/features/step_definitions/steps.rb
@@ -75,3 +75,15 @@ Then /^the documentation should be indexed$/ do
   Dir.glob(File.join($tmpdir, 'doc', 'tags')).should_not be_empty
 end
 
+Given /^(\S*) was previously installed as an old\-style addon$/ do |addon|
+  Dir.chdir $tmpdir do
+    FileUtils.mkdir_p 'syntax'
+    FileUtils.ln_s '/not/existing/syntax', "syntax/#{addon}.vim"
+    FileUtils.mkdir_p 'ftplugin'
+    FileUtils.ln_s '/not/existing/ftplugin', "ftplugin/#{addon}.vim"
+  end
+end
+
+Given /^there should be no broken symlinks$/ do
+  Dir.glob(File.join($tmpdir, '**/*')).select { |f| File.symlink?(f) && !File.exists?(f) }.should be_empty
+end
diff --git a/features/upgrade_from_legacy.feature b/features/upgrade_from_legacy.feature
new file mode 100644
index 0000000..7e440ed
--- /dev/null
+++ b/features/upgrade_from_legacy.feature
@@ -0,0 +1,7 @@
+Feature: upgrading legacy addons
+
+  Scenario: upgrading newstylemigrated
+    Given newstylemigrated was previously installed as an old-style addon
+    When I run `vim-addons upgrade-from-legacy`
+    Then there should be no broken symlinks
+    And newstylemigrated should be installed
diff --git a/lib/vim/addon_manager.rb b/lib/vim/addon_manager.rb
index 81617b5..0508ac9 100644
--- a/lib/vim/addon_manager.rb
+++ b/lib/vim/addon_manager.rb
@@ -12,6 +12,7 @@ require 'fileutils'
 require 'vim/addon_manager/constants'
 require 'vim/addon_manager/addon'
 require 'vim/addon_manager/logger'
+require 'vim/addon_manager/upgrade_from_legacy'
 
 module Vim
 
diff --git a/lib/vim/addon_manager/addon.rb b/lib/vim/addon_manager/addon.rb
index 4739919..9ce887d 100644
--- a/lib/vim/addon_manager/addon.rb
+++ b/lib/vim/addon_manager/addon.rb
@@ -22,6 +22,8 @@ module Vim
       # initialized.
       #
       def initialize(yaml, basedir)
+        @metadata = yaml
+
         @basedir = (yaml['basedir'] or basedir)
         @description = yaml['description']
         @name = yaml['addon']
@@ -94,6 +96,7 @@ module Vim
         line =~ @disabled_by_RE ? true : false
       end
 
+      attr_reader :metadata
       attr_reader :basedir
       attr_reader :description
       attr_reader :name
diff --git a/lib/vim/addon_manager/upgrade_from_legacy.rb b/lib/vim/addon_manager/upgrade_from_legacy.rb
new file mode 100644
index 0000000..94b3cb8
--- /dev/null
+++ b/lib/vim/addon_manager/upgrade_from_legacy.rb
@@ -0,0 +1,29 @@
+module Vim
+
+  class AddonManager
+
+    def upgrade_from_legacy(addons)
+      addons.each do |addon|
+        upgrade_addon_from_legacy(addon, @target_dir)
+      end
+    end
+
+    def upgrade_addon_from_legacy(addon, target_dir)
+      if addon.metadata['legacy_files']
+        links = addon.metadata['legacy_files'].map do |f|
+          File.join(target_dir, f)
+        end.select do |f|
+          File.symlink?(f)
+        end
+        unless links.empty?
+          links.each do |f|
+            File.unlink(f)
+          end
+          addon.install(target_dir)
+        end
+      end
+    end
+
+  end
+
+end
diff --git a/spec/data/registry/newstylemigrated.yaml b/spec/data/registry/newstylemigrated.yaml
new file mode 100644
index 0000000..f07069f
--- /dev/null
+++ b/spec/data/registry/newstylemigrated.yaml
@@ -0,0 +1,5 @@
+addon: newstylemigrated
+description: "new style addon that had a previous old-style version"
+legacy_files:
+  - syntax/newstylemigrated.vim
+  - ftplugin/newstylemigrated.vim
diff --git a/spec/data/registry/bogus1.yaml b/spec/data/scripts/vambundle/newstylemigrated/ftplugin/newstylemigrated.vim
similarity index 100%
copy from spec/data/registry/bogus1.yaml
copy to spec/data/scripts/vambundle/newstylemigrated/ftplugin/newstylemigrated.vim
diff --git a/spec/data/registry/bogus1.yaml b/spec/data/scripts/vambundle/newstylemigrated/syntax/newstylemigrated.vim
similarity index 100%
copy from spec/data/registry/bogus1.yaml
copy to spec/data/scripts/vambundle/newstylemigrated/syntax/newstylemigrated.vim
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 38c36ff..fa6bc24 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -21,6 +21,9 @@ module VimAddonManagerSpecHelper
     def has_file?(file)
       File.exists?(File.join(path, file))
     end
+    def has_symlink?(file)
+      File.symlink?(File.join(path, file))
+    end
     def rm(file)
       FileUtils.rm(File.join(path, file))
     end
diff --git a/spec/vim/addon_manager_spec.rb b/spec/vim/addon_manager_spec.rb
index 874ef6f..f0bb86f 100644
--- a/spec/vim/addon_manager_spec.rb
+++ b/spec/vim/addon_manager_spec.rb
@@ -19,4 +19,15 @@ describe Vim::AddonManager do
     target_dir.should_not have_file('syntax/foo.vim')
   end
 
+  it 'fixes broken addons after they are upgraded to the new style' do
+    Dir.chdir target_dir.path do
+      FileUtils.mkdir_p 'syntax'
+      FileUtils.ln_s '/non/existing/path', 'syntax/newstylemigrated.vim'
+    end
+    addon_manager.upgrade_from_legacy(registry.to_a)
+
+    target_dir.should_not have_symlink('syntax/newstylemigrated.vim')
+    target_dir.should have_file('vambundle/newstylemigrated/syntax/newstylemigrated.vim')
+  end
+
 end

-- 
vim-addon-manager packaging



More information about the pkg-vim-maintainers mailing list