/usr/lib/ruby/1.8/vim/addon-manager.rb is in vim-addon-manager 0.4.4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | # 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: addon-manager.rb 866 2007-01-24 21:27:58Z zack $
require 'fileutils'
require 'vim/common'
require 'vim/constants'
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)
installed_files = []
addons.each do |addon|
base_dir = (addon.basedir or @source_dir)
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(base_dir, file), dest)
end
status = addon.status(@target_dir)
case status.status
when :broken
Vim.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}"
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
else
Vim.info "ignoring '#{addon}' which is neither removed nor broken"
end
end
rebuild_tags(installed_files)
end
def remove(addons)
removed_files = []
rmdirs = lambda do |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
addons.each do |addon|
status = addon.status(@target_dir)
case status.status
when :installed
Vim.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}"
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"
end
end
# Try to clean up the tags file and doc dir if it's empty
tagfile = File.join(@target_dir, 'doc', 'tags')
if File.exists? tagfile
File.unlink tagfile
begin
FileUtils.rmdir File.join(@target_dir, 'doc')
rescue Errno::ENOTEMPTY
rebuild_tags(removed_files)
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
if lines.any? {|line| addon.is_disabled_by? line}
Vim.info "ignoring addon '#{addon}' which is already disabled"
else
Vim.info "disabling enabled addon '#{addon}'"
lines << addon.disabled_by_line + "\n"
end
end
end
end
def enable(addons)
map_override_lines do |lines|
addons.each do |addon|
if not addon.disabled_by_line
Vim.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}'"
lines.reject! {|line| addon.is_disabled_by? line}
else
Vim.info "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 " +
"future release. Please use the 'enable' command instead."
enable(addons)
end
def show(addons)
addons.each do |addon|
puts "Addon: #{addon}"
puts "Status: #{addon.status(@target_dir)}"
puts "Description: #{addon.description}"
puts ""
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
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.'
end
end
end
end
|