r859 - in /trunk/utils/addons/src: vim-addons vim/addon-manager.rb
vim/registry.rb
zack at users.alioth.debian.org
zack at users.alioth.debian.org
Sat Jan 20 15:17:21 UTC 2007
Author: zack
Date: Sat Jan 20 16:17:21 2007
New Revision: 859
URL: http://svn.debian.org/wsvn/?sc=1&rev=859
Log:
snapshot
- better source structure and naming
- initial support for disable/amend commands
Added:
trunk/utils/addons/src/vim/addon-manager.rb (with props)
Modified:
trunk/utils/addons/src/vim-addons
trunk/utils/addons/src/vim/registry.rb
Modified: trunk/utils/addons/src/vim-addons
URL: http://svn.debian.org/wsvn/trunk/utils/addons/src/vim-addons?rev=859&op=diff
==============================================================================
--- trunk/utils/addons/src/vim-addons (original)
+++ trunk/utils/addons/src/vim-addons Sat Jan 20 16:17:21 2007
@@ -9,6 +9,12 @@
#
# Created: Tue, 16 Jan 2007 10:04:20 +0100 zack
# Last-Modified: $Id$
+#
+# TODO: implement usage string
+# TODO: support usage of system-wide plugins
+# TODO: create a vim-addons-manager package shipping vim-addons
+# TODO: rework the README.Debian ov vim-scripts pointing to vim-addons
+#
#++
# == Synopsis
#
@@ -16,10 +22,13 @@
#
# == Usage
#
-# vim-addons [OPTION ...] enable ADDON ...
+# vim-addons [OPTION ...] list
+# vim-addons [OPTION ...] status [ADDON ...]
+# vim-addons [OPTION ...] install ADDON ...
+# vim-addons [OPTION ...] remove ADDON ...
# vim-addons [OPTION ...] disable ADDON ...
-# vim-addons [OPTION ...] list
-# vim-addons [OPTION ...] status
+# vim-addons [OPTION ...] amend ADDON ...
+# vim-addons [OPTION ...] files ADDON ...
#
# -h, --help
# show this usage message
@@ -45,10 +54,10 @@
$LOAD_PATH << File.join(ENV['HOME'], 'pkg-vim/utils/addons/src')
-require 'find'
require 'getoptlong'
require 'rdoc/usage'
+require 'vim/addon-manager'
require 'vim/registry'
def die_usage
@@ -61,7 +70,9 @@
:target_dir => File.join(ENV['HOME'], '.vim'),
:registry_dir => '/usr/share/vim/registry',
}
- commands = ['enable', 'disable', 'list', 'status']
+ 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],
['--source-dir', '-s', GetoptLong::REQUIRED_ARGUMENT],
@@ -77,54 +88,25 @@
end
end
die_usage unless cmd = ARGV.shift
- cmd = 'enable' if cmd == 'install' # command aliases a-la-apt
- cmd = 'disable' if cmd == 'remove'
- die_usage unless commands.member? cmd
- die_usage if ['enable', 'disable'].member? cmd and ARGV.empty?
+ die_usage unless cmds.member? cmd
+ die_usage if req_arg_cmds.member? cmd and ARGV.empty?
[cmd, ARGV, options]
end
-cmd, arguments, options = parse_cmdline
-registry = Vim::Addons::Registry.new(options[:registry_dir])
-selected_addons = \
- if arguments.empty?
- registry.to_a
- else
- registry.select {|a| arguments.member? a.name}
- end
+cmd, args, options = parse_cmdline
+registry = Vim::AddonRegistry.new(options[:registry_dir])
+selected_addons =
+ args.empty? ? registry.to_a : registry.select {|a| args.member? a.name}
case cmd
when 'list'
puts registry.sort
when 'status'
selected_addons.sort.each {|a| puts "#{a}: #{a.status(options[:target_dir])}"}
-when 'enable'
- selected_addons.each do |a|
- src_dir = (a.basedir or options[:source_dir])
- symlink = lambda do |f|
- dest = File.join(options[:target_dir], f)
- dest_dir = File.dirname dest
- FileUtils.mkdir_p dest_dir unless File.directory? dest_dir
- File.symlink(File.join(src_dir, f), dest)
- end
- status = a.status(options[:target_dir])
- case status.status
- when :broken
- status.missing_files.each(&symlink)
- when :not_installed
- a.files.each(&symlink)
- end
- end
-when 'disable'
- rmlink = lambda {|f| File.delete(File.join(options[:target_dir], f)) }
- selected_addons.each do |a|
- status = a.status(options[:target_dir])
- case status.status
- when :installed
- a.files.each(&rmlink)
- when :broken
- (a.files - status.missing_files).each(&rmlink)
- end
- end
+when 'files'
+ selected_addons.each {|a| puts a.files.to_a}
+else
+ Vim::AddonManager.send cmd, selected_addons,
+ options[:source_dir], options[:target_dir]
end
Added: trunk/utils/addons/src/vim/addon-manager.rb
URL: http://svn.debian.org/wsvn/trunk/utils/addons/src/vim/addon-manager.rb?rev=859&op=file
==============================================================================
--- trunk/utils/addons/src/vim/addon-manager.rb (added)
+++ trunk/utils/addons/src/vim/addon-manager.rb Sat Jan 20 16:17:21 2007
@@ -1,0 +1,55 @@
+#--
+# 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$
+#++
+
+require 'fileutils'
+
+module Vim
+
+ class AddonManager
+
+ def AddonManager.install(addons, src_dir, target_dir)
+ addons.each do |a|
+ src_dir = (a.basedir or src_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(src_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 AddonManager.remove(addons, src_dir, target_dir)
+ # 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
+
+ end
+
+end
+
Propchange: trunk/utils/addons/src/vim/addon-manager.rb
------------------------------------------------------------------------------
svn:keywords = Id
Modified: trunk/utils/addons/src/vim/registry.rb
URL: http://svn.debian.org/wsvn/trunk/utils/addons/src/vim/registry.rb?rev=859&op=diff
==============================================================================
--- trunk/utils/addons/src/vim/registry.rb (original)
+++ trunk/utils/addons/src/vim/registry.rb Sat Jan 20 16:17:21 2007
@@ -9,31 +9,30 @@
# $Id$
#++
+require 'find'
+require 'set'
require 'yaml'
-require 'set'
module Vim
-
- module Addons
# an addon status is one of the following
# - :not_installed
# - :installed
# - :broken (missing_files attribute is then used to list not installed
# files)
- Status = Struct.new(:status, :missing_files)
- class Status
+ AddonStatus = Struct.new(:status, :missing_files)
+ class AddonStatus
def to_s
case status
- when :installed ; "installed"
- when :not_installed ; "not installed"
+ when :installed ; 'installed'
+ when :not_installed ; 'removed'
when :broken ; "broken (missing: #{missing_files.join ', '})"
end
end
def ===(other)
case other
- when Status ; self.status == other.status
+ when AddonStatus ; self.status == other.status
else false
end
end
@@ -56,17 +55,17 @@
# addon is only partially installed)
def status(target_dir)
expected = @files.collect {|f| File.join(target_dir, f)}
- installed = expected.select {|f| File.exists? f and File.file? f}
+ installed = expected.select {|f| File.symlink? f}
if installed.size == expected.size
- Status.new :installed
+ AddonStatus.new :installed
elsif installed.size == 0
- Status.new :not_installed
+ AddonStatus.new :not_installed
else
missing = expected - installed
prefix = /^#{Regexp.escape target_dir}\/+/o
missing.collect! {|f| f.gsub(prefix, '')}
- Status.new(:broken, missing)
+ AddonStatus.new(:broken, missing)
end
end
@@ -85,13 +84,13 @@
alias_method :addon, :name
end
- class Registry
+ class AddonRegistry
include Enumerable
def initialize(registry_dir)
@dir = registry_dir
@addons = {}
- Registry.each_addon(@dir) {|a| @addons[a.name] = a}
+ AddonRegistry.each_addon(@dir) {|a| @addons[a.name] = a}
end
def [](name)
@@ -102,7 +101,7 @@
@addons.each_value {|a| yield a}
end
- def Registry.each_addon(dir)
+ def AddonRegistry.each_addon(dir)
Find.find(dir) do |path|
# selects .yaml files (non-recursively) contained in dir
next if path == dir
@@ -120,7 +119,5 @@
end
- end
-
end
More information about the pkg-vim-maintainers
mailing list