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

Antonio Terceiro terceiro at debian.org
Tue Jan 31 23:32:59 UTC 2012


The following commit has been merged in the master branch:
commit d02b75b66300e9212fdc74d249a62aa90300e424
Author: Antonio Terceiro <terceiro at debian.org>
Date:   Sun Jan 22 08:20:05 2012 -0200

    Reorganize library code

diff --git a/bin/vim-addons b/bin/vim-addons
index e83c9e7..469c672 100755
--- a/bin/vim-addons
+++ b/bin/vim-addons
@@ -154,9 +154,8 @@ option) any later version.
 
 require 'getoptlong'
 
-require 'vim/addon-manager'
-require 'vim/common'
-require 'vim/registry'
+require 'vim/addon_manager'
+require 'vim/addon_manager/registry'
 
 def die_usage
   print <<EOS
@@ -235,7 +234,7 @@ def parse_cmdline
 end
 
 cmd, args, options = parse_cmdline
-registry = Vim::AddonRegistry.new(options[:registry_dir], options[:source_dir])
+registry = Vim::AddonManager::Registry.new(options[:registry_dir], options[:source_dir])
 selected_addons =
   args.empty? ? registry.to_a : registry.select {|a| args.member? a.name}
 unknown = args.select {|name| not (registry.any? {|a| a.name == name})}
diff --git a/lib/vim/addon-manager.rb b/lib/vim/addon_manager.rb
similarity index 73%
rename from lib/vim/addon-manager.rb
rename to lib/vim/addon_manager.rb
index 725fdc6..8320b0e 100644
--- a/lib/vim/addon-manager.rb
+++ b/lib/vim/addon_manager.rb
@@ -11,8 +11,9 @@
 
 require 'fileutils'
 
-require 'vim/common'
-require 'vim/constants'
+require 'vim/addon_manager/constants'
+require 'vim/addon_manager/addon'
+require 'vim/addon_manager/logger'
 
 module Vim
 
@@ -26,6 +27,23 @@ module Vim
     attr_accessor :source_dir
     attr_accessor :target_dir
 
+    def self.override_file(dir)
+      File.join dir, OVERRIDE_FILE
+    end
+
+    def self.system(cmd)
+      logger.info "executing '#{cmd}'" if logger.verbose?
+      Kernel::system cmd
+    end
+
+    def self.logger
+      @logger ||= Vim::AddonManager::Logger.new
+    end
+
+    def logger
+      self.class.logger
+    end
+
     def install(addons)
       installed_files = []
       addons.each do |addon|
@@ -39,19 +57,19 @@ module Vim
         status = addon.status(@target_dir)
         case status.status
         when :broken
-          Vim.info "installing broken addon '#{addon}' to #{@target_dir}"
+          logger.info "installing broken addon '#{addon}' to #{@target_dir}"
           status.missing_files.each(&symlink)
           installed_files.concat(status.missing_files.to_a)
         when :not_installed
-          Vim.info "installing removed addon '#{addon}' to #{@target_dir}"
+          logger.info "installing removed addon '#{addon}' to #{@target_dir}"
           addon.files.each(&symlink)
           installed_files.concat(addon.files.to_a)
         when :unavailable
           s = "ignoring '#{addon}' which is missing source files"
-          s << "\n- #{status.missing_files.join "\n- "}" if Vim.verbose?
-          Vim.warn s
+          s << "\n- #{status.missing_files.join "\n- "}" if logger.verbose?
+          logger.warn s
         else
-          Vim.info "ignoring '#{addon}' which is neither removed nor broken"
+          logger.info "ignoring '#{addon}' which is neither removed nor broken"
         end
       end
       rebuild_tags(installed_files)
@@ -76,16 +94,16 @@ module Vim
         status = addon.status(@target_dir)
         case status.status
         when :installed
-          Vim.info "removing installed addon '#{addon}' from #{@target_dir}"
+          logger.info "removing installed addon '#{addon}' from #{@target_dir}"
           addon.files.each(&rmdirs)
           removed_files.concat(addon.files.to_a)
         when :broken
-          Vim.info "removing broken addon '#{addon}' from #{@target_dir}"
+          logger.info "removing broken addon '#{addon}' from #{@target_dir}"
           files = (addon.files - status.missing_files)
           files.each(&rmdirs)
           removed_files.concat(files.to_a)
         else
-          Vim.info "ignoring '#{addon}' which is neither installed nor broken"
+          logger.info "ignoring '#{addon}' which is neither installed nor broken"
         end
       end
       # Try to clean up the tags file and doc dir if it's empty
@@ -104,14 +122,14 @@ module Vim
       map_override_lines do |lines|
         addons.each do |addon|  # disable each not yet disabled addon
           if not addon.disabled_by_line
-            Vim.warn \
+            logger.warn \
               "#{addon} can't be disabled (since it has no 'disabledby' field)"
             next
           end
           if lines.any? {|line| addon.is_disabled_by? line}
-            Vim.info "ignoring addon '#{addon}' which is already disabled"
+            logger.info "ignoring addon '#{addon}' which is already disabled"
           else
-            Vim.info "disabling enabled addon '#{addon}'"
+            logger.info "disabling enabled addon '#{addon}'"
             lines << addon.disabled_by_line + "\n"
           end
         end
@@ -122,22 +140,22 @@ module Vim
       map_override_lines do |lines|
         addons.each do |addon|
           if not addon.disabled_by_line
-            Vim.warn \
+            logger.warn \
               "#{addon} can't be enabled (since it has no disabledby field)"
             next
           end
           if lines.any? {|line| addon.is_disabled_by? line}
-            Vim.info "enabling disabled addon '#{addon}'"
+            logger.info "enabling disabled addon '#{addon}'"
             lines.reject! {|line| addon.is_disabled_by? line}
           else
-            Vim.info "ignoring addon '#{addon}' which is enabled"
+            logger "ignoring addon '#{addon}' which is enabled"
           end
         end
       end
     end
 
     def amend(addons)
-      Vim.warn "the 'amend' command is deprecated and will disappear in a " +
+      logger   "the 'amend' command is deprecated and will disappear in a " +
                "future release.  Please use the 'enable' command instead."
       enable(addons)
     end
@@ -155,7 +173,7 @@ module Vim
 
     def map_override_lines
       override_lines = []
-      override_file = Vim.override_file @target_dir
+      override_file = logger.override_file @target_dir
       if File.exist? override_file
         File.open(override_file) do |file|
           override_lines += file.to_a
@@ -177,9 +195,9 @@ module Vim
     def rebuild_tags(files)
       needs_rebuilding = files.any? {|file| file =~ /^doc\//}
       if needs_rebuilding
-        Vim.info 'Rebuilding tags since documentation has been modified ...'
-        Vim.system "#{HELPZTAGS} #{File.join(@target_dir, 'doc/')}"
-        Vim.info 'done.'
+        logger.info 'Rebuilding tags since documentation has been modified ...'
+        Vim::AddonManager.system "#{HELPZTAGS} #{File.join(@target_dir, 'doc/')}"
+        logger.info 'done.'
       end
     end
 
diff --git a/lib/vim/addon_manager/addon.rb b/lib/vim/addon_manager/addon.rb
new file mode 100644
index 0000000..8859048
--- /dev/null
+++ b/lib/vim/addon_manager/addon.rb
@@ -0,0 +1,106 @@
+require 'vim/addon_manager/addon_status'
+
+module Vim
+
+  class AddonManager
+
+    class Addon
+
+      def initialize(yaml, basedir)
+        @basedir = (yaml['basedir'] or basedir)
+        @description = yaml['description']
+        @name = yaml['addon']
+
+        @files = Set.new yaml['files']
+        raise ArgumentError.new('empty addon') if @files.size == 0
+
+        @disabled_by_line = yaml['disabledby']
+        if @disabled_by_line then
+          @disabled_by_RE = /^\s*#{Regexp.escape @disabled_by_line}\s*$/
+        else
+          @disabled_by_RE = nil
+        end
+
+      end
+
+      # 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)
+      #
+      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 to_s
+        name
+      end
+
+      def <=>(other)
+        self.name <=> other.name
+      end
+
+      # checks if a given line (when present in a Vim configuration file) is
+      # suitable for disabling the addon
+      #
+      def is_disabled_by?(line)
+        return false unless @disabled_by_RE # the addon can't be disabled if no
+        # disabledby field has been provided
+        line =~ @disabled_by_RE ? true : false
+      end
+
+      attr_reader :basedir
+      attr_reader :description
+      attr_reader :files
+      attr_reader :name
+      attr_reader :disabled_by_line
+      alias_method :addon, :name
+
+      private
+
+      def logger
+        Vim::AddonManager.logger
+      end
+
+      # checks whether the addon is disabled wrt a given target installation dir
+      #
+      def is_disabled_in?(target_dir)
+        filename = Vim::AddonManager.override_file(target_dir)
+        return false unless File.exist?(filename)
+        File.open(filename) do |file|
+          file.any? {|line| is_disabled_by? line}
+        end
+      end
+
+    end
+
+  end
+
+end
diff --git a/lib/vim/addon_manager/addon_status.rb b/lib/vim/addon_manager/addon_status.rb
new file mode 100644
index 0000000..a137266
--- /dev/null
+++ b/lib/vim/addon_manager/addon_status.rb
@@ -0,0 +1,57 @@
+module Vim
+
+  class AddonManager
+
+    # an addon status is one of the following
+    # - :not_installed
+    # - :installed
+    # - :broken (missing_files attribute is then used to list not installed
+    # files)
+    # - :unavailable (missing_files attribute is then used to list source files
+    # that weren't found)
+    #
+    AddonStatusStruct = Struct.new(:status, :missing_files)
+
+    class AddonStatus < AddonStatusStruct
+
+      def initialize(*args)
+        super(*args)
+        @disabled = false
+      end
+
+      def logger
+        Vim::AddonManager.logger
+      end
+
+      attr_accessor :disabled
+
+      def to_s
+        if @disabled
+          'disabled'
+        else
+          case status
+          when :installed
+            'installed'
+          when :not_installed
+            'removed'
+          when :broken
+            s = 'broken'
+            if logger.verbose?
+              s << " (missing: #{missing_files.join ', '})"
+            end
+            s
+          when :unavailable
+            s = 'unavailable'
+            if logger.verbose?
+              s << " (missing source files: #{missing_files.join ', '})"
+            end
+            s
+          end
+        end
+      end
+
+    end
+
+  end
+
+end
diff --git a/lib/vim/constants.rb b/lib/vim/addon_manager/constants.rb
similarity index 78%
rename from lib/vim/constants.rb
rename to lib/vim/addon_manager/constants.rb
index 95c3b8b..6fe5d2e 100644
--- a/lib/vim/constants.rb
+++ b/lib/vim/addon_manager/constants.rb
@@ -11,7 +11,11 @@
 
 module Vim
 
-  OVERRIDE_FILE = 'plugin/000-vim-addons.vim'
-  HELPZTAGS = '/usr/bin/helpztags'
+  class AddonManager
+
+    OVERRIDE_FILE = 'plugin/000-vim-addons.vim'
+    HELPZTAGS = '/usr/bin/helpztags'
+
+  end
 
 end
diff --git a/lib/vim/addon_manager/logger.rb b/lib/vim/addon_manager/logger.rb
new file mode 100644
index 0000000..ffb5283
--- /dev/null
+++ b/lib/vim/addon_manager/logger.rb
@@ -0,0 +1,30 @@
+module Vim
+
+  class AddonManager
+
+    class Logger
+
+      def initialize
+        @verbosity = 0
+      end
+
+      def increase_verbosity
+        @verbosity += 1
+      end
+
+      def verbose?
+        @verbosity >= 1
+      end
+
+      def warn(s)
+        $stderr.puts "Warning: #{s}"
+      end
+
+      def info(s)
+        puts "Info: #{s}"
+      end
+
+    end
+
+  end
+end
diff --git a/lib/vim/addon_manager/registry.rb b/lib/vim/addon_manager/registry.rb
new file mode 100644
index 0000000..81e117d
--- /dev/null
+++ b/lib/vim/addon_manager/registry.rb
@@ -0,0 +1,61 @@
+# vim-addons: command line manager of Vim addons
+#
+# Copyright (C) 2007 Stefano Zacchiroli
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# $Id: registry.rb 866 2007-01-24 21:27:58Z zack $
+
+require 'find'
+require 'set'
+require 'yaml'
+
+require 'vim/addon_manager/addon'
+
+module Vim
+
+  class AddonManager
+
+    class Registry
+
+      include Enumerable
+
+      def initialize(registry_dir, source_dir)
+        @basedir = source_dir # default basedir, can be overridden by addons
+        @addons = {}
+        self.class.each_addon(registry_dir, @basedir) {|a| @addons[a.name] = a}
+      end
+
+      def [](name)
+        @addons[name]
+      end
+
+      def each
+        @addons.each_value {|a| yield a}
+      end
+
+      def self.each_addon(dir, basedir)
+        Find.find(dir) do |path|
+          # selects .yaml files (non-recursively) contained in dir
+          next if path == dir
+          Find.prune if File.directory? path
+          if File.file? path
+            Find.prune if path !~ /\.yaml$/
+              File.open path do |f|
+              YAML.load_documents f do |ydoc|
+                yield(Addon.new(ydoc, basedir)) if ydoc
+              end
+              end
+          end
+        end
+      end
+
+    end
+
+  end
+
+end
+
diff --git a/lib/vim/common.rb b/lib/vim/common.rb
deleted file mode 100644
index 2ccd641..0000000
--- a/lib/vim/common.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-# vim-addons: command line manager of Vim addons
-#
-# Copyright (C) 2007 Stefano Zacchiroli
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# $Id: common.rb 866 2007-01-24 21:27:58Z zack $
-
-require 'vim/constants'
-
-module Vim
-
-  def Vim.override_file(dir)
-    File.join dir, OVERRIDE_FILE
-  end
-
-
-  @verbosity = 0
-
-  class << self
-
-    def increase_verbosity
-      @verbosity += 1
-    end
-
-    def verbose?
-      @verbosity >= 1
-    end
-
-    def warn(s)
-      $stderr.puts "Warning: #{s}"
-    end
-
-    def info(s)
-      puts "Info: #{s}"
-    end
-
-    def system(cmd)
-      info "executing '#{cmd}'" if verbose?
-      Kernel::system cmd
-    end
-  end
-
-
-end
diff --git a/lib/vim/registry.rb b/lib/vim/registry.rb
deleted file mode 100644
index 45de91c..0000000
--- a/lib/vim/registry.rb
+++ /dev/null
@@ -1,197 +0,0 @@
-# vim-addons: command line manager of Vim addons
-#
-# Copyright (C) 2007 Stefano Zacchiroli
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# $Id: registry.rb 866 2007-01-24 21:27:58Z zack $
-
-require 'find'
-require 'set'
-require 'yaml'
-
-require 'vim/common'
-
-module Vim
-
-  # an addon status is one of the following
-  # - :not_installed
-  # - :installed
-  # - :broken (missing_files attribute is then used to list not installed
-  # files)
-  # - :unavailable (missing_files attribute is then used to list source files
-  # that weren't found)
-  #
-  AddonStatusStruct = Struct.new(:status, :missing_files)
-
-  class AddonStatus < AddonStatusStruct
-
-    def initialize(*args)
-      super(*args)
-      @disabled = false
-    end
-
-    attr_accessor :disabled
-
-    def to_s
-      if @disabled
-        'disabled'
-      else
-        case status
-        when :installed
-          'installed'
-        when :not_installed
-          'removed'
-        when :broken
-          s = 'broken'
-          if Vim.verbose?
-            s << " (missing: #{missing_files.join ', '})"
-          end
-          s
-        when :unavailable
-          s = 'unavailable'
-          if Vim.verbose?
-            s << " (missing source files: #{missing_files.join ', '})"
-          end
-          s
-        end
-      end
-    end
-
-  end
-
-
-  class Addon
-
-    def initialize(yaml, basedir)
-      @basedir = (yaml['basedir'] or basedir)
-      @description = yaml['description']
-      @name = yaml['addon']
-
-      @files = Set.new yaml['files']
-      raise ArgumentError.new('empty addon') if @files.size == 0
-
-      @disabled_by_line = yaml['disabledby']
-      if @disabled_by_line then
-        @disabled_by_RE = /^\s*#{Regexp.escape @disabled_by_line}\s*$/
-      else
-        @disabled_by_RE = nil
-      end
-
-    end
-
-    # 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)
-    #
-    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 to_s
-      name
-    end
-
-    def <=>(other)
-      self.name <=> other.name
-    end
-
-    # checks if a given line (when present in a Vim configuration file) is
-    # suitable for disabling the addon
-    #
-    def is_disabled_by?(line)
-      return false unless @disabled_by_RE # the addon can't be disabled if no
-                                          # disabledby field has been provided
-      line =~ @disabled_by_RE ? true : false
-    end
-
-    attr_reader :basedir
-    attr_reader :description
-    attr_reader :files
-    attr_reader :name
-    attr_reader :disabled_by_line
-    alias_method :addon, :name
-
-    private
-
-    # checks whether the addon is disabled wrt a given target installation dir
-    #
-    def is_disabled_in?(target_dir)
-      return false unless File.exist?(Vim.override_file(target_dir))
-      File.open(Vim.override_file(target_dir)) do |file|
-        file.any? {|line| is_disabled_by? line}
-      end
-    end
-
-  end
-
-
-  class AddonRegistry
-
-    include Enumerable
-
-    def initialize(registry_dir, source_dir)
-      @basedir = source_dir # default basedir, can be overridden by addons
-      @addons = {}
-      AddonRegistry.each_addon(registry_dir, @basedir) {|a| @addons[a.name] = a}
-    end
-
-    def [](name)
-      @addons[name]
-    end
-
-    def each
-      @addons.each_value {|a| yield a}
-    end
-
-    def AddonRegistry.each_addon(dir, basedir)
-      Find.find(dir) do |path|
-        # selects .yaml files (non-recursively) contained in dir
-        next if path == dir
-        Find.prune if File.directory? path
-        if File.file? path
-          Find.prune if path !~ /\.yaml$/
-          File.open path do |f|
-            YAML.load_documents f do |ydoc|
-              yield(Addon.new(ydoc, basedir)) if ydoc
-            end
-          end
-        end
-      end
-    end
-
-  end
-
-end
-

-- 
vim-addon-manager packaging



More information about the pkg-vim-maintainers mailing list