Project

General

Profile

« Previous | Next » 

Revision a9b44a39

Added by Marc Dequènes over 15 years ago

  • ID a9b44a390fbf6ddb89fd0cf0cce9f5a4f0cb4dbe

[evol] code cleanup

View differences:

bin/shadowwalker
cmdparser.add_command(CmdParse::HelpCommand.new)
cmdparser.add_command(CmdParse::VersionCommand.new)
I18n.load_path += Dir[File.join(LdapShadows::Config::DATA_DIR, "*.yml")]
I18n.default_locale = :en
ldapctl = Controller.new
ldapctl.set_global_config(config[:presentation])
config[:aspects].each_pair do |aspect_name, aspect_data|
......
end
ldapctl.load_relations
def translate_object_name(obj_hdl)
I18n.t(obj_hdl, :scope => 'objects', :default => "Object '#{obj_hdl}'")
end
cmd = CmdParse::Command.new('list', false)
cmd.short_desc = "list objects"
cmd.set_execution_block do |args|
......
exit 2
end
obj_human_name = translate_object_name(obj_hdl)
puts "=== List of #{obj_human_name.pluralize} ==="
obj_klass.find(:all).each do |obj|
str = obj.human_name
str += " [#{obj.name}]" if $program_options[:handles]
str += ": #{obj.description}" unless obj.description.empty?
puts str
end
obj_human_name = Translator.translate_object_name(obj_hdl)
Display.display_item_list("List of " + obj_human_name.pluralize, obj_klass.find(:all))
end
cmdparser.add_command(cmd)
def 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 translate_aspect_name(aspect_name)
I18n.t(aspect_name, :scope => 'aspects', :default => "Aspect '#{aspect_name}'")
end
cmd = CmdParse::Command.new('show', false)
cmd.short_desc = "show object information"
cmd.set_execution_block do |args|
lib/ldap_shadows/display_utils.rb
#--
# 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'
module LdapShadows
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
module Display
def self.display_fields(attr_data, options = {})
attr_data.each_pair do |key, val|
field_name = translate_field_name(key)
field_name = Translator.translate_field_name(key)
field_name += " [#{key}]" if options[:handles]
puts field_name + ": " + (val.is_a?(Array) ? val.sort.collect{|v| v.to_s }.join(", ") : val.to_s)
end
end
def self.display_item(item, options = {})
obj_human_name = translate_object_name(item.handle)
obj_human_name = Translator.translate_object_name(item.handle)
name = item.human_name
name += " [#{item.name}]" if options[:handles]
puts "=== #{obj_human_name}: #{name} ==="
......
display_fields(obj_info, options)
obj_aspects.each_pair do |aspect_name, aspect_data|
puts "--- #{translate_aspect_name(aspect_name)} ---"
puts "--- #{Translator.translate_aspect_name(aspect_name)} ---"
display_fields(aspect_data, options)
end
end
end
def self.display_item_list(title, obj_list)
puts "=== #{title} ==="
obj_list.each do |obj|
str = obj.human_name
str += " [#{obj.name}]" if $program_options[:handles]
str += ": #{obj.description}" unless obj.description.empty?
puts str
end
end
def self.display_hash_tree(tree, level)
tree.keys.sort.each do |key|
str = ""
......
end
end
end

Also available in: Unified diff