Project

General

Profile

« Previous | Next » 

Revision 016427dd

Added by Marc Dequènes over 13 years ago

  • ID 016427dd02ba652aba3281235e512f73f3650fb5

[evol] allow specifying a file content as value in the command line for search and modify commands (closes #149)

View differences:

lib/ldap_shadows/manipulation_helper.rb
module LdapShadows
module Manipulation
# hyphens are permitted by RFC2251, but disallowed for method named
# hyphens are permitted by RFC2251, but disallowed for method names
TEXTUI_KEY_PATTERN = "(?:[a-zA-Z]*:)?[a-zA-Z][a-zA-Z0-9]*"
def self.prepare_string_part(key, op_modifier, op, val)
case op_modifier
when '@'
unless File.exists?(val)
raise PreProcessingError, _("The file for key '%s' does not exist") % key
end
begin
val = File.read(val)
rescue
raise PreProcessingError, _("The file for key '%s' cannot be read: ") % [key, $!]
end
end
val
end
def self.item_modify_from_strings(item, str_list)
str_list = [str_list] unless str_list.is_a? Array
modification_done = false
str_list.each do |str|
unless str =~ /^(#{TEXTUI_KEY_PATTERN})(=|\+=|-=)(.*)$/
unless str =~ /^(#{TEXTUI_KEY_PATTERN})(@)?(=|\+=|-=)(.*)$/
raise SyntaxError, _("modification parameter '%s' is invalid") % str
end
key = $1
op = $2
val = $3
op_modifier = $2
op = $3
val = $4
val = prepare_string_part(key, op_modifier, op, val)
mod_done = item.modify(key, op, val)
modification_done ||= mod_done
......
ldap_search_exclude =Set.new
ldap_search_fields_post = Set.new
str_list.each do |str|
unless str =~ /^(#{TEXTUI_KEY_PATTERN})(=|~=)(.*)$/
unless str =~ /^(#{TEXTUI_KEY_PATTERN})(@)?(=|~=)(.*)$/
raise SyntaxError, _("search parameter '%s' is invalid") % str
end
key = $1
op = $2
val = $3
op_modifier = $2
op = $3
val = $4
val = prepare_string_part(key, op_modifier, op, val)
if key.index(":")
type, field = key.split(":")

Also available in: Unified diff