r878 - in /trunk/packages/vim-addon-manager: ./ debian/ doc/ src/ src/vim/

zack at users.alioth.debian.org zack at users.alioth.debian.org
Sun Feb 4 12:14:36 CET 2007


Author: zack
Date: Sun Feb  4 12:14:35 2007
New Revision: 878

URL: http://svn.debian.org/wsvn/pkg-vim/?sc=1&rev=878
Log:
draft packaging of vim-addon-manager

Added:
    trunk/packages/vim-addon-manager/
    trunk/packages/vim-addon-manager/debian/
    trunk/packages/vim-addon-manager/debian/changelog
    trunk/packages/vim-addon-manager/debian/compat
    trunk/packages/vim-addon-manager/debian/control
    trunk/packages/vim-addon-manager/debian/copyright
    trunk/packages/vim-addon-manager/debian/rules   (with props)
    trunk/packages/vim-addon-manager/debian/vim-addon-manager.docs
    trunk/packages/vim-addon-manager/debian/vim-addon-manager.install
    trunk/packages/vim-addon-manager/debian/vim-addon-manager.manpages
    trunk/packages/vim-addon-manager/doc/
    trunk/packages/vim-addon-manager/doc/addons-proposal.txt
    trunk/packages/vim-addon-manager/doc/registry-format.txt
    trunk/packages/vim-addon-manager/src/
    trunk/packages/vim-addon-manager/src/Makefile
    trunk/packages/vim-addon-manager/src/vim/
    trunk/packages/vim-addon-manager/src/vim-addons   (with props)
    trunk/packages/vim-addon-manager/src/vim/addon-manager.rb
    trunk/packages/vim-addon-manager/src/vim/common.rb
    trunk/packages/vim-addon-manager/src/vim/constants.rb
    trunk/packages/vim-addon-manager/src/vim/registry.rb

Added: trunk/packages/vim-addon-manager/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/debian/changelog?rev=878&op=file
==============================================================================
--- trunk/packages/vim-addon-manager/debian/changelog (added)
+++ trunk/packages/vim-addon-manager/debian/changelog Sun Feb  4 12:14:35 2007
@@ -1,0 +1,6 @@
+vim-addon-manager (0.1) unstable; urgency=low
+
+  * Initial release
+
+ -- Stefano Zacchiroli <zack at debian.org>  Sun, 28 Jan 2007 21:23:08 +0100
+

Added: trunk/packages/vim-addon-manager/debian/compat
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/debian/compat?rev=878&op=file
==============================================================================
--- trunk/packages/vim-addon-manager/debian/compat (added)
+++ trunk/packages/vim-addon-manager/debian/compat Sun Feb  4 12:14:35 2007
@@ -1,0 +1,1 @@
+5

Added: trunk/packages/vim-addon-manager/debian/control
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/debian/control?rev=878&op=file
==============================================================================
--- trunk/packages/vim-addon-manager/debian/control (added)
+++ trunk/packages/vim-addon-manager/debian/control Sun Feb  4 12:14:35 2007
@@ -1,0 +1,24 @@
+Source: vim-addon-manager
+Section: editors
+Priority: extra
+Maintainer: Stefano Zacchiroli <zack at debian.org>
+Build-Depends: cdbs, debhelper (>= 5), rdtool
+Standards-Version: 3.7.2
+
+Package: vim-addon-manager
+Architecture: all
+Depends: ruby, ${misc:Depends}
+Recommends: vim-tiny | vim | gvim
+Description: command line manager of Vim addons
+ vim-addon-manager is a tool for managing addons for the Vim
+ editor.
+ .
+ Using the vim-addons command line the user can list the addons
+ installed on its system (i.e. which are registered in the vim
+ addons registry) and install or uninstall each of them in its
+ per-user configuration directory (~/.vim).
+ .
+ Override of addons which are enabled per default on the system,
+ so that they are not enabled for the current user, is possible
+ too.
+

Added: trunk/packages/vim-addon-manager/debian/copyright
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/debian/copyright?rev=878&op=file
==============================================================================
--- trunk/packages/vim-addon-manager/debian/copyright (added)
+++ trunk/packages/vim-addon-manager/debian/copyright Sun Feb  4 12:14:35 2007
@@ -1,0 +1,20 @@
+This package was debianized by Stefano Zacchiroli <zack at debian.org> on
+Sun, 28 Jan 2007 21:23:08 +0100.
+
+This package is a native Debian package, its most recent source code is
+available at:
+
+  svn://svn.debian.org/svn/pkg-vim/trunk/packages/vim-addon-manager
+
+Upstream Author: Stefano Zacchiroli <zack at debian.org>
+
+Copyright: 2007 Stefano Zacchiroli <zack at debian.org>
+
+License:
+
+  This program (together with its packaging) is free software, you can
+  redistribute it and/or modify it under the terms of the GNU General Public
+  License version 2 as published by the Free Software Foundation; either
+  version 2 of the License, or (at your option) any later version.
+  
+  See `/usr/share/common-licenses/GPL' for the license text.

Added: trunk/packages/vim-addon-manager/debian/rules
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/debian/rules?rev=878&op=file
==============================================================================
--- trunk/packages/vim-addon-manager/debian/rules (added)
+++ trunk/packages/vim-addon-manager/debian/rules Sun Feb  4 12:14:35 2007
@@ -1,0 +1,14 @@
+#!/usr/bin/make -f
+  
+include /usr/share/cdbs/1/rules/debhelper.mk
+
+common-build-indep:: debian/stamp-local-build
+debian/stamp-local-build::
+	make -C src/
+	touch $@
+
+clean:: local-clean
+local-clean::
+	make -C src/ clean
+	rm -rf debian/stamp-local-build
+

Propchange: trunk/packages/vim-addon-manager/debian/rules
------------------------------------------------------------------------------
    svn:executable = *

Added: trunk/packages/vim-addon-manager/debian/vim-addon-manager.docs
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/debian/vim-addon-manager.docs?rev=878&op=file
==============================================================================
--- trunk/packages/vim-addon-manager/debian/vim-addon-manager.docs (added)
+++ trunk/packages/vim-addon-manager/debian/vim-addon-manager.docs Sun Feb  4 12:14:35 2007
@@ -1,0 +1,1 @@
+doc/*

Added: trunk/packages/vim-addon-manager/debian/vim-addon-manager.install
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/debian/vim-addon-manager.install?rev=878&op=file
==============================================================================
--- trunk/packages/vim-addon-manager/debian/vim-addon-manager.install (added)
+++ trunk/packages/vim-addon-manager/debian/vim-addon-manager.install Sun Feb  4 12:14:35 2007
@@ -1,0 +1,2 @@
+src/vim-addons	    /usr/bin/
+src/vim		    /usr/lib/ruby/1.8/

Added: trunk/packages/vim-addon-manager/debian/vim-addon-manager.manpages
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/debian/vim-addon-manager.manpages?rev=878&op=file
==============================================================================
--- trunk/packages/vim-addon-manager/debian/vim-addon-manager.manpages (added)
+++ trunk/packages/vim-addon-manager/debian/vim-addon-manager.manpages Sun Feb  4 12:14:35 2007
@@ -1,0 +1,1 @@
+src/vim-addons.1

Added: trunk/packages/vim-addon-manager/doc/addons-proposal.txt
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/doc/addons-proposal.txt?rev=878&op=file
==============================================================================
--- trunk/packages/vim-addon-manager/doc/addons-proposal.txt (added)
+++ trunk/packages/vim-addon-manager/doc/addons-proposal.txt Sun Feb  4 12:14:35 2007
@@ -1,0 +1,94 @@
+
+Handling of Vim Addons
+======================
+
+Vim "Addons"
+------------
+
+With "addon" we will refer to every additional (set of) feature that can be
+added to Vim using its extension mechanisms (color schemes, syntaxes,
+indentation, plugins, ftplugins, ...)
+
+Present Issues
+--------------
+
+Every vim addon is currently installed in /usr/share/vim/addons/, directory
+which is in the runtimepath. As a consequence every installed addon is always
+enabled. The only way to choose which ones to load is to override the
+runtimepath so that /usr/share/vim/addons/ is not listed and manually load the
+desired one.
+
+The "vim-scripts" package is an exception to this rule installing everything
+under /usr/share/vim-scripts/ and requiring (as documented in the package's
+README.Debian) the sysadm (resp. local user) to symlink the desired addons to a
+system-wide directory (resp. ~/.vim). That is to say that none of the
+vim-scripts addons are enabled per default.
+
+Proposed Solution
+-----------------
+
+Keep on installing addons under /usr/share/vim/addons/ (no changes are needed
+for all packages which ship addons), but remove this directory from the
+runtimepath. Adds a directory /var/vim/addons/ to the runtimepath and implement
+a flexible symlink mechanism (a-la /etc/init.d/) to selectively enable addons.
+
+Implementation
+--------------
+
+1 registry, 2 tools.
+
+### The Addon Registry
+
+The registry keep track of all installed vim addons, associating to each addon
+name a list of files that should be in the runtimepath for the addon to be
+enabled. E.g., an entry in the registry can be (in YAML syntax):
+
+  addon: utl
+  description: "Universal Text Linking: URL-based hyperlinking"
+  basedir: /usr/share/vim-scripts/
+  files:
+    - plugin/utl.vim
+    - doc/utl_ref.txt
+    - doc/utl_usr.txt
+    - plugin/utl_arr.vim
+    - plugin/utl_rc.vim
+    - plugin/utl_scm.vim
+    - plugin/utl_uri.vim
+
+A single package can ship more than one addon. Still, it is recommended that
+each package named vim-<name> installs a single addon called <name> so that its
+easier for the user to know the canonical name of addons. The "vim-scripts"
+package is an exception to this rule being conceived as a bundle of addons.
+
+### Tool 1: update-vim-addons
+
+The tool "update-vim-addons" (to be used by sysadms) consumes as input the
+configuration file /etc/vim/addons which lists, one per line, the name of the
+addons which should be system-wide enabled. The invocation of
+"update-vim-addons" is idempotent.  Result of the invocation is the setting of
+all the needed symlinks pointing from /var/vim/addons/ to /usr/share/vim/addons/
+(or alternatively to the basedir specified in registry entries), and of course
+the removal of all the no longer needed symlinks.
+
+Companion tools which automatically add/remove lines to /etc/vim/addons and then
+invoke update-vim-addons (a la apache-modconf) can be made available to be
+invoked by package postints.
+
+All packages shipping vim addons should have in their postinst scripts
+(conditional) invocations of the above companion tools so that, if the vim addon
+infrastructure is installed on the target machine, after the installation a
+given vim-addon is enabled per default. The invocation is conditional so that
+the installation of the addon infrastructure does not become a vim dependency
+(since vim itself ships some addons, e.g. matchit).
+
+### Tool 2: vim-addons
+
+The tool "vim-addons" (to be used by users) can be used to enable/disable addons
+on a per user basis. It provides also inspecting facilities (e.g.: list the
+available addons or query their status for the current user). It additionally
+provides an override mechanism that let the user enable for her addons which are
+disabled system-wide and prevent the usage of addons which are enabled
+system-wide.
+
+--
+Tue, 23 Jan 2007 11:40:29 +0100 zack

Added: trunk/packages/vim-addon-manager/doc/registry-format.txt
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/doc/registry-format.txt?rev=878&op=file
==============================================================================
--- trunk/packages/vim-addon-manager/doc/registry-format.txt (added)
+++ trunk/packages/vim-addon-manager/doc/registry-format.txt Sun Feb  4 12:14:35 2007
@@ -1,0 +1,70 @@
+
+Vim Addon Registry
+==================
+
+On-Disk Format
+--------------
+
+The registry is stored on disk as a single directory directly (i.e. not in any
+sub-directory) containing a set of files in YAML [1] format. At the time of
+writing the directory containing the Vim addon registry is
+/usr/share/vim/registry/.
+
+Each file is a multi-document YAML file (i.e. it can be composed by several
+different YAML documents separated by "---" lines). Each YAML document represent
+a registry entry, that is the information describing a single addon.
+
+Ideally, the registry directory contains one file per package shipping addons;
+with a filename obeying to the convention PACKAGE-NAME.yaml. Hence a single
+package can contribute to the registry with multiple entries described in a
+single YAML file.
+
+For example, the "vim-scripts" package should ship a single
+/usr/share/vim/registry/vim-scripts.yaml file, containing one YAML document per
+shipped addon. The first lines of such file can look like the following (two
+space of indentation manually added to the present text file):
+
+  addon: alternate
+  description: "alternate pairing files (e.g. .c/.h) with short ex-commands"
+  basedir: /usr/share/vim-scripts/
+  files:
+    - plugin/a.vim
+    - doc/alternate.txt
+  ---
+  addon: whatdomain
+  description: "query the meaning of a Top Level Domain"
+  basedir: /usr/share/vim-scripts/
+  files:
+    - plugin/whatdomain.vim
+  ---
+
+Each registry entry may contain the following fields, to be typeset according to
+the YAML specification:
+
+  addon:
+  
+    name of the addon (required field)
+
+  description:
+  
+    human understandable textual description of the addon (required field)
+
+  files:
+  
+    list of the files which compose the addon and are required to be present in
+    a component of the Vim runtime path for the addon to be enabled.  Each file
+    is specified relative to a component of the Vim runtime path (required
+    field)
+
+  basedir:
+
+    directory where the files shipped by the addon (i.e. where the symlinks of
+    the user/sysadm should point to) reside on the filesystem (optional field,
+    default to: /usr/share/vim/addons)
+
+References
+----------
+
+[1] http://www.yaml.org/
+
+-- Tue, 23 Jan 2007 15:12:00 +0100 zack

Added: trunk/packages/vim-addon-manager/src/Makefile
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/src/Makefile?rev=878&op=file
==============================================================================
--- trunk/packages/vim-addon-manager/src/Makefile (added)
+++ trunk/packages/vim-addon-manager/src/Makefile Sun Feb  4 12:14:35 2007
@@ -1,0 +1,5 @@
+all: vim-addons.1
+clean:
+	rm -f vim-addons.1
+vim-addons.1: vim-addons
+	rd2 -r rd/rd2man-lib -o $(basename $@) $<

Added: trunk/packages/vim-addon-manager/src/vim-addons
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/src/vim-addons?rev=878&op=file
==============================================================================
--- trunk/packages/vim-addon-manager/src/vim-addons (added)
+++ trunk/packages/vim-addon-manager/src/vim-addons Sun Feb  4 12:14:35 2007
@@ -1,0 +1,219 @@
+#!/usr/bin/ruby -w
+#
+# 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 version 2 as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# Created:    Tue, 16 Jan 2007 10:04:20 +0100 zack
+# Last-Modified:  $Id: vim-addons 872 2007-01-28 18:31:41Z zack $
+#
+# TODO: create a vim-addons-manager package shipping vim-addons
+# TODO: rework the README.Debian of vim-scripts pointing to vim-addons
+#
+
+=begin
+
+== NAME
+
+vim-addons - command line manager of Vim add-ons
+
+== SYNOPSIS
+
+vim-addons [OPTION ...] { list | status | install | remove | disable | amend | files } [ADDON ...]
+
+== DESCRIPTION
+
+Manage Vim addons installed system-wide, enabling on a per-user basis their
+installation, removal, ...
+
+vim-addons is capable of managing all Vim addons registered in the system-wide
+registry of Vim addons (see vim-registry(5)). Each system-wide addon can be,
+with respect to a user Vim configuration, in one of the following states:
+
+:installed
+  all of the files composing the addon are installed (i.e. symlinked) somewhere
+  under ~/.vim. The addon is fully functional for the current user
+
+:removed
+  the files composing the addon are not installed under ~/.vim. The addon might
+  still be working for the current user if it is installed system-wide by the
+  local administrator
+
+:disabled
+  the files composing the addon are not installed under ~/.vim, but the addon
+  is installed system-wide. However, the addon has been disabled for the
+  current user explicitely requiring so via some configuration line in
+  ~/.vim/plugin/vim-addons.vim. The addon is not working for the current user
+
+:broken
+  only some of the files composing the addon are installed under ~/.vim. The
+  addon is probably not working for the current user
+
+The following commands can be given to vim-addons to inspect or alter the
+status of the addons:
+
+:list
+  list, one per line, the names of the addons available in the system (i.e. of
+  all the addons mentioned in the registry, not necessarily of all enabled
+  addons)
+
+:status
+  show, one per line, the status of the addons available in the system. If one
+  or more addon arguments are specified only show the status of those addons
+
+:install
+  install one or more addons under ~/.vim. Requires at least one addon argument
+
+:remove
+  remove one or more addons from ~/.vim. Requires at least one addon argument
+
+:disable
+  disable one or more addons to be used by the current user. Usually used for
+  addons which are system-wide enabled by the local administrator but that the
+  current user does not want to be used. Using this command will automatically
+  change the content of ~/.vim/plugin/vim-addons.vim, probably adding let
+  definitions which will inhibit the given addon to be used. Requires at least
+  one addon argument
+
+:amend
+  undo the effects of a previous disable command. Requires at least one addon
+  argument
+
+:files
+  linst, one per line, the files composing the specified addons. Files are
+  listed relative to components of the Vim runtimepath (see 'runtimepath' in
+  the Vim help). Requires at least one addon argument
+
+== OPTIONS
+
+All commands accept the following options:
+
+:-h, --help
+  show this usage message and exit
+
+:-r, --registry-dir
+  set the registry directory (default: /usr/share/vim/registry)
+
+:-s, --source-dir
+  set the addons source directory (default: /usr/share/vim/addons)
+
+:-t, --target-dir
+  set the addons target directory (default: $HOME/.vim)
+
+:-v, --verbose
+  increase verbosity level
+
+:-w, --system-dir
+  set the system-wide target directory (default: /var/lib/vim/addons)
+
+== AUTHOR
+
+Stefano Zacchiroli <zack at debian.org>
+
+== SEE ALSO
+
+vim(1), vim-registry(5)
+
+== COPYRIGHT
+
+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 version 2 as published by the
+Free Software Foundation; either version 2 of the License, or (at your
+option) any later version.
+
+=end
+
+require 'getoptlong'
+
+require 'vim/addon-manager'
+require 'vim/common'
+require 'vim/registry'
+
+def die_usage
+  print <<EOS
+Usage:
+  vim-addons [OPTION ...] { list | status | install | remove | disable | amend | files } [ADDON ...]
+Options:
+  -h, --help          show this usage message and exit
+  -r, --registry-dir  set the registry directory
+                        (default: /usr/share/vim/registry)
+  -s, --source-dir    set the addons source directory
+                        (default: /usr/share/vim/addons)
+  -t, --target-dir    set the addons target directory
+                        (default: $HOME/.vim)
+  -v, --verbose       increase verbosity
+  -w, --system-dir    set the system-wide target directory
+                        (default: /var/lib/vim/addons)
+EOS
+  exit 1
+end
+
+def parse_cmdline
+  options = { # defaults
+    :registry_dir => '/usr/share/vim/registry',
+    :source_dir => '/usr/share/vim/addons',
+    :system_dir => '/var/lib/vim/addons',
+    :target_dir => File.join(ENV['HOME'], '.vim'),
+  }
+  cmds = %w{install remove disable amend list status files}
+  req_arg_cmds = # commands requiring >= 1 arg
+    %w{install remove disable amend files}
+  cmdline =
+    GetoptLong.new(['--help', '-h', GetoptLong::NO_ARGUMENT],
+                   ['--registry-dir', '-r', GetoptLong::REQUIRED_ARGUMENT],
+                   ['--source-dir', '-s', GetoptLong::REQUIRED_ARGUMENT],
+                   ['--target-dir', '-t', GetoptLong::REQUIRED_ARGUMENT],
+                   ['--verbose', '-v', GetoptLong::NO_ARGUMENT],
+                   ['--system-dir', '-w', GetoptLong::REQUIRED_ARGUMENT])
+  cmdline.each do |opt, arg|
+    case opt
+    when '--help'
+      die_usage
+    when '--registry-dir'
+      options[:registry_dir] = arg
+    when '--source-dir'
+      options[:source_dir] = arg
+    when '--target-dir'
+      options[:target_dir] = arg
+    when '--verbose'
+      Vim.increase_verbosity
+    when '--system-dir'
+      options[:system_dir] = arg
+    end
+  end
+  die_usage unless cmd = ARGV.shift
+  die_usage unless cmds.member? cmd
+  die_usage if req_arg_cmds.member? cmd and ARGV.empty?
+  [cmd, ARGV, options]
+end
+
+cmd, args, options = parse_cmdline
+registry = Vim::AddonRegistry.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})}
+Vim.warn "Ignoring unknown addons: #{unknown.join ', '}" unless unknown.empty?
+
+case cmd
+when 'list'
+  puts registry.sort
+when 'status'
+  printf("# %-25s%-13s%-14s\n", 'Name', 'User Status', 'System Status')
+  selected_addons.sort.each do |a|
+    printf("%-28s%-14s%-14s\n", a, a.status(options[:target_dir]),
+           a.status(options[:system_dir]))
+  end
+when 'files'
+  selected_addons.each {|a| puts a.files.to_a}
+else
+  mgr = Vim::AddonManager.new options[:source_dir], options[:target_dir]
+  mgr.send cmd, selected_addons
+end
+

Propchange: trunk/packages/vim-addon-manager/src/vim-addons
------------------------------------------------------------------------------
    svn:executable = *

Added: trunk/packages/vim-addon-manager/src/vim/addon-manager.rb
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/src/vim/addon-manager.rb?rev=878&op=file
==============================================================================
--- trunk/packages/vim-addon-manager/src/vim/addon-manager.rb (added)
+++ trunk/packages/vim-addon-manager/src/vim/addon-manager.rb Sun Feb  4 12:14:35 2007
@@ -1,0 +1,116 @@
+# 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 version 2 as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# $Id: addon-manager.rb 866 2007-01-24 21:27:58Z zack $
+
+require 'fileutils'
+
+require 'vim/common'
+
+module Vim
+
+  class AddonManager
+
+    def initialize(source_dir, target_dir)
+      @source_dir = source_dir
+      @target_dir = target_dir
+    end
+
+    attr_accessor :source_dir
+    attr_accessor :target_dir
+
+    def install(addons)
+      addons.each do |a|
+	base_dir = (a.basedir or @source_dir)
+	symlink = lambda do |f|
+	  dest = File.join(@target_dir, f)
+	  dest_dir = File.dirname dest
+	  FileUtils.mkdir_p dest_dir unless File.directory? dest_dir
+	  FileUtils.ln_sf(File.join(base_dir, f), dest)
+	end
+	status = a.status(@target_dir)
+	case status.status
+	when :broken
+	  status.missing_files.each(&symlink)
+	when :not_installed
+	  a.files.each(&symlink)
+	end
+      end
+    end
+
+    def remove(addons)
+      # TODO remove empty directories (recursively toward the top of ~/.vim/,
+      # a la rmdir -p)
+      rmlink = lambda {|f| File.delete(File.join(@target_dir, f)) }
+      addons.each do |a|
+	status = a.status(@target_dir)
+	case status.status
+	when :installed
+	  a.files.each(&rmlink)
+	when :broken
+	  (a.files - status.missing_files).each(&rmlink)
+	end
+      end
+    end
+
+    def disable(addons)
+      map_override_lines do |lines|
+        addons.each do |addon|  # disable each not yet disabled addon
+          if not addon.disabled_by_line
+            Vim.warn \
+              "#{addon} can't be disabled (since it has no disabledby field)"
+            next
+          end
+          unless lines.any? {|line| addon.is_disabled_by? line}
+            lines << addon.disabled_by_line + "\n"
+          end
+        end
+      end
+    end
+
+    def amend(addons)
+      map_override_lines do |lines|
+        addons.each do |addon|
+          if not addon.disabled_by_line
+            Vim.warn \
+              "#{addon} can't be amended (since it has no disabledby field)"
+            next
+          end
+          lines.reject! {|line| addon.is_disabled_by? line}
+        end
+      end
+    end
+
+    private
+    
+    def map_override_lines
+      override_lines = []
+      override_file = Vim.override_file @target_dir
+      if File.exist? override_file
+        File.open(override_file) do |file|
+          override_lines += file.to_a
+        end
+      end
+      checksum = override_lines.hash
+
+      yield override_lines
+
+      if override_lines.empty?
+        FileUtils.rm override_file if File.exist? override_file
+      elsif override_lines.hash != checksum
+        File.open(override_file, 'w') do |file|
+          file.write override_lines
+        end
+      end
+    end
+
+  end
+
+end
+

Added: trunk/packages/vim-addon-manager/src/vim/common.rb
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/src/vim/common.rb?rev=878&op=file
==============================================================================
--- trunk/packages/vim-addon-manager/src/vim/common.rb (added)
+++ trunk/packages/vim-addon-manager/src/vim/common.rb Sun Feb  4 12:14:35 2007
@@ -1,0 +1,39 @@
+# 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 version 2 as published by the
+# Free Software Foundation; either version 2 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)
+      puts "Warning: #{s}"
+    end
+  end
+
+
+end

Added: trunk/packages/vim-addon-manager/src/vim/constants.rb
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/src/vim/constants.rb?rev=878&op=file
==============================================================================
--- trunk/packages/vim-addon-manager/src/vim/constants.rb (added)
+++ trunk/packages/vim-addon-manager/src/vim/constants.rb Sun Feb  4 12:14:35 2007
@@ -1,0 +1,16 @@
+# 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 version 2 as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# $Id: constants.rb 866 2007-01-24 21:27:58Z zack $
+
+module Vim
+
+  OVERRIDE_FILE = 'plugin/000-vim-addons.vim'
+
+end

Added: trunk/packages/vim-addon-manager/src/vim/registry.rb
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/src/vim/registry.rb?rev=878&op=file
==============================================================================
--- trunk/packages/vim-addon-manager/src/vim/registry.rb (added)
+++ trunk/packages/vim-addon-manager/src/vim/registry.rb Sun Feb  4 12:14:35 2007
@@ -1,0 +1,189 @@
+# 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 version 2 as published by the
+# Free Software Foundation; either version 2 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)
+  #
+  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'
+            s << " (missing: #{missing_files.join ', '})" if Vim.verbose?
+            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)
+    #
+    def status(target_dir)
+      expected = @files.collect {|f| File.join(target_dir, f)}
+      installed = expected.select do |f|
+        case
+        when (File.exist? f)
+          true
+        #when (File.symlink? f)
+          #(File.readlink f) ==
+          #(File.join @basedir, f.gsub(/^#{Regexp.escape target_dir}\/*/, ''))
+        #when (File.file? f)
+          #true
+        else
+          false
+        end
+      end
+
+      status =
+        if installed.size == expected.size
+          AddonStatus.new :installed
+        elsif installed.size == 0
+          AddonStatus.new :not_installed
+        else
+          missing = expected - 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
+




More information about the pkg-vim-maintainers mailing list