[SCM] vim-addon-manager packaging branch, master, updated. v0.4.4-52-geef7258

Antonio Terceiro terceiro at debian.org
Tue Jan 31 23:33:24 UTC 2012


The following commit has been merged in the master branch:
commit faa5d4eeaecbde25264483fc85dfa1b5a1b9c414
Author: Antonio Terceiro <terceiro at debian.org>
Date:   Sun Jan 22 11:59:15 2012 -0200

    Move legacy addon bahavior to a separate class
    
    The idea is that the "new style" addons will be implemented by a new
    subclass, with it's own logic for installing, removing and retrieving
    the status.

diff --git a/lib/vim/addon_manager/addon.rb b/lib/vim/addon_manager/addon.rb
index 40c8827..83417ef 100644
--- a/lib/vim/addon_manager/addon.rb
+++ b/lib/vim/addon_manager/addon.rb
@@ -25,38 +25,36 @@ module Vim
 
       # return the status of the self add-on wrt a target installation
       # directory, and the system wide installation directory.
-      # A status is a ternary value: :not_installed (the addon is not installed
-      # at all), :installed (the addon is completely installed), :broken (the
-      # addon is only partially installed), :unavailable (source files are
-      # missing)
+      #
+      # A status may be one of the following values
+      #  * :not_installed (the addon is not installed at all)
+      #  * :installed (the addon is completely installed)
+      #  * :broken (the addon is only partially installed)
+      #  * :unavailable (source files are missing)
+      #  * :unkonwn (the addon is unkonwn to the system)
+      #
+      # This method must be overriden by subclasses.
       #
       def status(target_dir)
-        expected_dest = @files.collect {|f| File.join(target_dir, f)}
-        installed = expected_dest.select do |f|
-          File.exist? f
-        end
-        expected_src = @files.collect {|f| File.join(@basedir, f)}
-        available = expected_src.select do |f|
-          File.exist? f
-        end
+        :unkonwn
+      end
+
+      # Installs addon files into +target_dir+ and returns a list of installed
+      # files.
+      #
+      # This method must be overriden by subclasses.
+      #
+      def install(target_dir)
+        []
+      end
 
-        status =
-          if available.size != expected_src.size
-            missing = expected_src - available
-            AddonStatus.new(:unavailable, missing)
-          elsif installed.size == expected_dest.size
-            AddonStatus.new :installed
-          elsif installed.size == 0
-            AddonStatus.new :not_installed
-          else
-            missing = expected_dest - installed
-            prefix = /^#{Regexp.escape target_dir}\/+/o
-            missing.collect! {|f| f.gsub(prefix, '')}
-            AddonStatus.new(:broken, missing)
-          end
-
-        status.disabled = is_disabled_in? target_dir
-        status
+      # Removes addon files from +target_dir+ and returns a list of installed
+      # files.
+      #
+      # This method must be overriden by subclasses.
+      #
+      def remove(target_dir)
+        []
       end
 
       def to_s
@@ -76,55 +74,6 @@ module Vim
         line =~ @disabled_by_RE ? true : false
       end
 
-      # Installs addon files into +target_dir+ and returns a list of installed
-      # files.
-      def install(target_dir)
-        installed_files = []
-        symlink = lambda do |file|
-          dest = File.join(target_dir, file)
-          dest_dir = File.dirname dest
-          FileUtils.mkdir_p dest_dir
-          FileUtils.ln_sf(File.join(basedir, file), dest)
-        end
-        status = self.status(target_dir)
-        case status.status
-        when :broken
-          logger.info "installing broken addon '#{self}' to #{target_dir}"
-          status.missing_files.each(&symlink)
-          installed_files.concat(status.missing_files.to_a)
-        when :not_installed
-          logger.info "installing removed addon '#{self}' to #{target_dir}"
-          self.files.each(&symlink)
-          installed_files.concat(self.files.to_a)
-        when :unavailable
-          s = "ignoring '#{self}' which is missing source files"
-          s << "\n- #{status.missing_files.join "\n- "}" if logger.verbose?
-          logger.warn s
-        else
-          logger.info "ignoring '#{self}' which is neither removed nor broken"
-        end
-        installed_files
-      end
-
-      def remove(target_dir)
-        removed_files = []
-        status = self.status(target_dir)
-        case status.status
-        when :installed
-          logger.info "removing installed addon '#{self}' from #{target_dir}"
-          self.files.each { |f| rmdirs(target_dir, f) }
-          removed_files.concat(self.files.to_a)
-        when :broken
-          logger.info "removing broken addon '#{self}' from #{target_dir}"
-          files = (self.files - status.missing_files)
-          files.each { |f| rmdirs(target_dir, f) }
-          removed_files.concat(files.to_a)
-        else
-          logger.info "ignoring '#{self}' which is neither installed nor broken"
-        end
-        removed_files
-      end
-
       attr_reader :basedir
       attr_reader :description
       attr_reader :files
@@ -132,6 +81,10 @@ module Vim
       attr_reader :disabled_by_line
       alias_method :addon, :name
 
+      def self.build(yaml, basedir)
+        Vim::AddonManager::Addon::Legacy.new(yaml, basedir)
+      end
+
       private
 
       def logger
@@ -148,22 +101,10 @@ module Vim
         end
       end
 
-      def rmdirs(target_dir, file)
-        File.delete(File.join(target_dir, file))
-        dir = File.dirname(file)
-        paths = (dir.include? File::Separator) ? File.split(dir) : [dir]
-        while paths.size > 0
-          begin
-            FileUtils.rmdir(File.join(target_dir, paths))
-          rescue Errno::ENOTEMPTY
-            break
-          end
-          paths.pop
-        end
-      end
-
     end
 
   end
 
 end
+
+require 'vim/addon_manager/addon/legacy'
diff --git a/lib/vim/addon_manager/addon/legacy.rb b/lib/vim/addon_manager/addon/legacy.rb
new file mode 100644
index 0000000..b76c674
--- /dev/null
+++ b/lib/vim/addon_manager/addon/legacy.rb
@@ -0,0 +1,107 @@
+module Vim
+
+  class AddonManager
+
+    class Addon
+
+      class Legacy < Addon
+
+        def status(target_dir)
+          expected_dest = @files.collect {|f| File.join(target_dir, f)}
+          installed = expected_dest.select do |f|
+            File.exist? f
+          end
+          expected_src = @files.collect {|f| File.join(@basedir, f)}
+          available = expected_src.select do |f|
+            File.exist? f
+          end
+
+          status =
+            if available.size != expected_src.size
+              missing = expected_src - available
+              AddonStatus.new(:unavailable, missing)
+            elsif installed.size == expected_dest.size
+              AddonStatus.new :installed
+            elsif installed.size == 0
+              AddonStatus.new :not_installed
+            else
+              missing = expected_dest - installed
+              prefix = /^#{Regexp.escape target_dir}\/+/o
+              missing.collect! {|f| f.gsub(prefix, '')}
+              AddonStatus.new(:broken, missing)
+            end
+
+          status.disabled = is_disabled_in? target_dir
+          status
+        end
+
+        def install(target_dir)
+          installed_files = []
+          symlink = lambda do |file|
+            dest = File.join(target_dir, file)
+            dest_dir = File.dirname dest
+            FileUtils.mkdir_p dest_dir
+            FileUtils.ln_sf(File.join(basedir, file), dest)
+          end
+          status = self.status(target_dir)
+          case status.status
+          when :broken
+            logger.info "installing broken addon '#{self}' to #{target_dir}"
+            status.missing_files.each(&symlink)
+            installed_files.concat(status.missing_files.to_a)
+          when :not_installed
+            logger.info "installing removed addon '#{self}' to #{target_dir}"
+            self.files.each(&symlink)
+            installed_files.concat(self.files.to_a)
+          when :unavailable
+            s = "ignoring '#{self}' which is missing source files"
+            s << "\n- #{status.missing_files.join "\n- "}" if logger.verbose?
+            logger.warn s
+          else
+            logger.info "ignoring '#{self}' which is neither removed nor broken"
+          end
+          installed_files
+        end
+
+        def remove(target_dir)
+          removed_files = []
+          status = self.status(target_dir)
+          case status.status
+          when :installed
+            logger.info "removing installed addon '#{self}' from #{target_dir}"
+            self.files.each { |f| rmdirs(target_dir, f) }
+            removed_files.concat(self.files.to_a)
+          when :broken
+            logger.info "removing broken addon '#{self}' from #{target_dir}"
+            files = (self.files - status.missing_files)
+            files.each { |f| rmdirs(target_dir, f) }
+            removed_files.concat(files.to_a)
+          else
+            logger.info "ignoring '#{self}' which is neither installed nor broken"
+          end
+          removed_files
+        end
+
+        private
+
+        def rmdirs(target_dir, file)
+          File.delete(File.join(target_dir, file))
+          dir = File.dirname(file)
+          paths = (dir.include? File::Separator) ? File.split(dir) : [dir]
+          while paths.size > 0
+            begin
+              FileUtils.rmdir(File.join(target_dir, paths))
+            rescue Errno::ENOTEMPTY
+              break
+            end
+            paths.pop
+          end
+        end
+
+      end
+
+    end
+
+  end
+
+end
diff --git a/lib/vim/addon_manager/registry.rb b/lib/vim/addon_manager/registry.rb
index fdb6029..c9e6d44 100644
--- a/lib/vim/addon_manager/registry.rb
+++ b/lib/vim/addon_manager/registry.rb
@@ -43,7 +43,7 @@ module Vim
           stream = stream.documents if stream.respond_to?(:documents) # Ruby 1.8 compatibility
           if stream
             stream.each do |ydoc|
-              yield(Addon.new(ydoc, basedir)) if ydoc
+              yield(Addon.build(ydoc, basedir)) if ydoc
             end
           end
         end

-- 
vim-addon-manager packaging



More information about the pkg-vim-maintainers mailing list