Project

General

Profile

Download (3.91 KB) Statistics
| Branch: | Tag: | Revision:
a9b44a39 Marc Dequènes (Duck)
#--
# LdapShadows, a Medium-level LDAP Access Library and Tool.
# Copyright (c) 2009 Marc Dequènes (Duck) <Duck@DuckCorp.org>
#
# 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++

require 'active_support'

bbb82941 Marc Dequènes (Duck)
module LdapShadows
a9b44a39 Marc Dequènes (Duck)
module Translator
I18n.load_path += Dir[File.join(Config::DATA_DIR, "*.yml")]
I18n.default_locale = :en

def self.translate_object_name(obj_hdl)
I18n.t(obj_hdl, :scope => 'objects', :default => "Object '#{obj_hdl}'")
end

def self.translate_field_name(field_name)
if field_name.index(":")
type, key = field_name.split(":")
case type
when 'rel'
I18n.t(key, :scope => 'relations', :default => field_name)
else
raise "Cannot translate unknown data key type"
end
else
att = ActiveLdap::Base.schema.attribute(field_name)
I18n.t(att.human_attribute_name, :scope => 'attribute_types', :default => att.human_attribute_description)
end
end

def self.translate_aspect_name(aspect_name)
I18n.t(aspect_name, :scope => 'aspects', :default => "Aspect '#{aspect_name}'")
end
end

bbb82941 Marc Dequènes (Duck)
module Display
def self.display_fields(attr_data, options = {})
attr_data.each_pair do |key, val|
f7217dcd Marc Dequènes (Duck)
next if attr_data[:expert] and options[:expert]

a9b44a39 Marc Dequènes (Duck)
field_name = Translator.translate_field_name(key)
f7217dcd Marc Dequènes (Duck)
str = field_name
str += " [#{key}]" if options[:handles]
if val[:binary] and options[:skip_binary]
str += " -> #{val[:value].size} file(s) available"
else
str += ": " + (val[:multiple] ? val[:value].sort.collect{|v| v.to_s }.join(", ") : val[:value].to_s)
end

puts str
bbb82941 Marc Dequènes (Duck)
end
end

def self.display_item(item, options = {})
a9b44a39 Marc Dequènes (Duck)
obj_human_name = Translator.translate_object_name(item.handle)
bbb82941 Marc Dequènes (Duck)
name = item.human_name
name += " [#{item.name}]" if options[:handles]
puts "=== #{obj_human_name}: #{name} ==="

if options[:debug]
puts item.to_s
puts "--- Detected Info ---"
puts "aspects: " + item.aspects.sort.join(", ")

puts "--- Family ---"
puts "parent: " + item.family_parent_dn.to_s
puts "siblings: " + item.family_siblings_dn.join(", ")
puts "children: " + item.family_children_dn.join(", ")

puts "--- Relations ---"
item.relations.each do |rel|
puts "#{rel}: " + item.send(rel).collect{|g| g.name }.join(", ")
end
else
f7217dcd Marc Dequènes (Duck)
obj_info, obj_aspects = item.organized_data
bbb82941 Marc Dequènes (Duck)
display_fields(obj_info, options)

obj_aspects.each_pair do |aspect_name, aspect_data|
a9b44a39 Marc Dequènes (Duck)
puts "--- #{Translator.translate_aspect_name(aspect_name)} ---"
bbb82941 Marc Dequènes (Duck)
display_fields(aspect_data, options)
end
end
end

a24bc5b1 Marc Dequènes (Duck)
def self.display_item_list(title, item_list)
puts "=== #{title} (#{item_list.size}) ==="
item_list.each do |item|
str = item.human_name
str += " [#{item.name}]" if $program_options[:handles]
str += ": #{item.description}" unless item.description.empty?
a9b44a39 Marc Dequènes (Duck)
puts str
end
end

bbb82941 Marc Dequènes (Duck)
def self.display_hash_tree(tree, level)
tree.keys.sort.each do |key|
str = ""
str += " " + "| " * (level -1) + "+-- " if level > 0
str += "<#{key}>"
puts str

display_hash_tree(tree[key], level + 1) if tree[key]
end
end
end
end