r862 - 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
Sun Jan 21 23:55:28 UTC 2007
Author: zack
Date: Mon Jan 22 00:55:28 2007
New Revision: 862
URL: http://svn.debian.org/wsvn/?sc=1&rev=862
Log:
snapshot (added verbosity, formatting of status output)
Modified:
trunk/utils/addons/src/vim-addons
trunk/utils/addons/src/vim/addon-manager.rb
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=862&op=diff
==============================================================================
--- trunk/utils/addons/src/vim-addons (original)
+++ trunk/utils/addons/src/vim-addons Mon Jan 22 00:55:28 2007
@@ -97,14 +97,20 @@
:-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)
-:-r, --registry-dir
- set the registry directory (default: /usr/share/vim/registry)
+:-v, --verbose
+ increase verbosity level
+
+:-w, --system-dir
+ set the system-wide target directory (default: /var/lib/vim/addons)
== AUTHOR
@@ -128,7 +134,6 @@
$LOAD_PATH << File.join(ENV['HOME'], 'pkg-vim/utils/addons/src')
require 'getoptlong'
-require 'rdoc/usage'
require 'vim/addon-manager'
require 'vim/registry'
@@ -139,12 +144,15 @@
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)
+ (default: /usr/share/vim/addons)
-t, --target-dir set the addons target directory
- (default: $HOME/.vim)
- -r, --registry-dir set the registry directory
- (default: /usr/share/vim/registry)
+ (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
@@ -160,20 +168,25 @@
%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],
- ['--registry-dir', '-r', 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 '--registry-dir'
- options[:registry_dir] = arg
+ when '--verbose'
+ Vim.increase_verbosity
+ when '--system-dir'
+ options[:system_dir] = arg
end
end
die_usage unless cmd = ARGV.shift
@@ -191,11 +204,13 @@
when 'list'
puts registry.sort
when 'status'
- selected_addons.sort.each {|a| puts "#{a}: #{a.status(options[:target_dir])}"}
+ selected_addons.sort.each do |a|
+ printf "%-28s%s\n", a, a.status(options[:target_dir], options[:system_dir])
+ 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]
+ options[:source_dir], options[:target_dir], options[:system_dir]
end
Modified: trunk/utils/addons/src/vim/addon-manager.rb
URL: http://svn.debian.org/wsvn/trunk/utils/addons/src/vim/addon-manager.rb?rev=862&op=diff
==============================================================================
--- trunk/utils/addons/src/vim/addon-manager.rb (original)
+++ trunk/utils/addons/src/vim/addon-manager.rb Mon Jan 22 00:55:28 2007
@@ -13,7 +13,7 @@
class AddonManager
- def AddonManager.install(addons, src_dir, target_dir)
+ def AddonManager.install(addons, src_dir, target_dir, system_dir)
addons.each do |a|
src_dir = (a.basedir or src_dir)
symlink = lambda do |f|
@@ -22,7 +22,7 @@
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)
+ status = a.status(target_dir, system_dir)
case status.status
when :broken
status.missing_files.each(&symlink)
@@ -32,12 +32,12 @@
end
end
- def AddonManager.remove(addons, src_dir, target_dir)
+ def AddonManager.remove(addons, src_dir, target_dir, system_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)
+ status = a.status(target_dir, system_dir)
case status.status
when :installed
a.files.each(&rmlink)
Modified: trunk/utils/addons/src/vim/registry.rb
URL: http://svn.debian.org/wsvn/trunk/utils/addons/src/vim/registry.rb?rev=862&op=diff
==============================================================================
--- trunk/utils/addons/src/vim/registry.rb (original)
+++ trunk/utils/addons/src/vim/registry.rb Mon Jan 22 00:55:28 2007
@@ -13,109 +13,135 @@
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)
- AddonStatus = Struct.new(:status, :missing_files)
- class AddonStatus
- def to_s
- case status
- when :installed ; 'installed'
- when :not_installed ; 'removed'
- when :broken ; "broken (missing: #{missing_files.join ', '})"
- end
+ @verbosity = 0
+
+ class << self
+ def increase_verbosity
+ @verbosity += 1
+ end
+
+ def verbose?
+ @verbosity >= 1
+ end
+ end
+
+
+ # an addon status is one of the following
+ # - :not_installed
+ # - :installed
+ # - :broken (missing_files attribute is then used to list not installed
+ # files)
+ #
+ AddonStatus = Struct.new(:status, :missing_files)
+ class AddonStatus
+ def to_s
+ case status
+ when :installed
+ 'installed'
+ when :not_installed
+ 'removed'
+ when :broken
+ s = 'broken'
+ s << " (missing: #{missing_files.join ', '})" if Vim.verbose?
+ s
end
+ end
- def ===(other)
- case other
- when AddonStatus ; self.status == other.status
- else false
+ def ===(other)
+ case other
+ when AddonStatus
+ self.status == other.status
+ else
+ false
+ end
+ end
+ end
+
+
+ class Addon
+ def initialize(yaml)
+ @basedir = yaml['basedir']
+ @description = yaml['description']
+ @files = Set.new yaml['files']
+ @name = yaml['addon']
+ @status = nil
+
+ raise ArgumentError.new('empty addon') if @files.size == 0
+ 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, system_dir)
+ expected = @files.collect {|f| File.join(target_dir, f)}
+ installed = expected.select {|f| File.symlink? f}
+
+ 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
+ end
+
+ def to_s
+ name
+ end
+
+ def <=>(other)
+ self.name <=> other.name
+ end
+
+ attr_reader :basedir
+ attr_reader :description
+ attr_reader :files
+ attr_reader :name
+ alias_method :addon, :name
+ end
+
+
+ class AddonRegistry
+ include Enumerable
+
+ def initialize(registry_dir)
+ @dir = registry_dir
+ @addons = {}
+ AddonRegistry.each_addon(@dir) {|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)
+ 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)) if ydoc
+ end
+ end
end
end
end
- class Addon
- def initialize(yaml)
- @basedir = yaml['basedir']
- @description = yaml['description']
- @files = Set.new yaml['files']
- @name = yaml['addon']
- @status = nil
+ end
- raise ArgumentError.new('empty addon') if @files.size == 0
- end
-
- # return the status of the self add-on wrt a target 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 {|f| File.symlink? f}
-
- 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
- end
-
- def to_s
- name
- end
-
- def <=>(other)
- self.name <=> other.name
- end
-
- attr_reader :basedir
- attr_reader :description
- attr_reader :files
- attr_reader :name
- alias_method :addon, :name
- end
-
- class AddonRegistry
- include Enumerable
-
- def initialize(registry_dir)
- @dir = registry_dir
- @addons = {}
- AddonRegistry.each_addon(@dir) {|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)
- 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)) if ydoc
- end
- end
- end
- end
- end
-
- end
end
More information about the pkg-vim-maintainers
mailing list