/usr/lib/ruby/vendor_ruby/vim/addon_manager.rb is in vim-addon-manager 0.5.3.
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 | # 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.
require 'fileutils'
require 'vim/addon_manager/constants'
require 'vim/addon_manager/addon'
require 'vim/addon_manager/logger'
require 'vim/addon_manager/upgrade_from_legacy'
module Vim
class AddonManager
def initialize(target_dir)
@target_dir = target_dir
end
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|
installed_files.concat(addon.install(@target_dir))
end
rebuild_tags(installed_files)
end
def remove(addons)
removed_files = []
addons.each do |addon|
removed_files.concat(addon.remove(@target_dir))
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
logger.warn \
"#{addon} can't be disabled (since it has no 'disabledby' field)"
next
end
if lines.any? {|line| addon.is_disabled_by? line}
logger.info "ignoring addon '#{addon}' which is already disabled"
else
logger.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
logger.warn \
"#{addon} can't be enabled (since it has no disabledby field)"
next
end
if lines.any? {|line| addon.is_disabled_by? line}
logger.info "enabling disabled addon '#{addon}'"
lines.reject! {|line| addon.is_disabled_by? line}
else
logger.info "ignoring addon '#{addon}' which is enabled"
end
end
end
end
def amend(addons)
logger "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 "Files:\n#{addon.files.map { |f| " - #{f}\n"}.join}"
puts ""
end
end
private
def map_override_lines
override_lines = []
override_file = Vim::AddonManager.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
FileUtils.mkdir_p(File.dirname(override_file))
File.open(override_file, 'w') do |file|
override_lines.each do |line|
file.write line
end
end
end
end
def rebuild_tags(files)
needs_rebuilding = files.any? {|file| file =~ /^doc\//}
if needs_rebuilding
logger.info 'Rebuilding tags since documentation has been modified ...'
Vim::AddonManager.system "#{HELPZTAGS} #{File.join(@target_dir, 'doc/')}"
logger.info 'done.'
end
end
end
end
|