Skip to content

Commit

Permalink
fixing registration functions up
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-srnsw committed Apr 29, 2011
1 parent f49cf12 commit 3bb73ba
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions lib/srnsw_custom.rb
Expand Up @@ -224,22 +224,32 @@ module AuthorityRegister
module_function
def register(control)
cmd = REGISTER_PATH + " -n #{control}"
response = IO.popen(cmd) {|out| out.gets}
end

def unregister(control, id)
cmd = REGISTER_PATH + " -r #{control + id}"
response = IO.popen(cmd) {|out| out.gets}
end

def increment(control, id)
cmd = REGISTER_PATH + " -v #{control + id}"
response = IO.popen(cmd) {|out| out.gets}
end

def decrement(control, id)
cmd = REGISTER_PATH + " -d #{control + id}"
response = IO.popen(cmd) {|out| out.gets}
end

def execute_cmd(cmd)
begin
output = IO.popen(cmd) {|out| out.gets}
rescue
output = nil
end
return nil unless output
if output.strip.empty?
nil
else
output =~ /\D/ ? nil : output
end
end
end

Expand All @@ -254,11 +264,8 @@ def multi_delete(list, context, name, pos)
number = node.content
unless number.empty?
if Utils::confirm_dialog("Would you like to deregister ID #{control} #{number}?", list.toplevel)
begin
AuthorityRegister::unregister(control, number)
rescue
Utils::error_dialog("Error: can't connect to register", list.toplevel)
end
old_id = AuthorityRegister::execute_cmd(AuthorityRegister::unregister(control, number))
Utils::error_dialog("Error: failed to deregister ID #{control} #{number}", list.toplevel) unless old_id
end
end
end
Expand Down Expand Up @@ -301,15 +308,13 @@ def register_id
else
if control
if ['FA', 'GA', 'AR'].index(control)
begin
new_id = AuthorityRegister::register(control)
rescue
Utils::error_dialog("Error: can't connect to register", @parent)
end
if new_id
@content.text = new_id
response(0)
end
new_id = AuthorityRegister::execute_cmd(AuthorityRegister::register(control))
if new_id
@content.text = new_id
response(0)
else
Utils::error_dialog("Error: failure connecting to register", @parent)
end
else
Utils::error_dialog("ID must be of type FA/GA/AR", @parent)
end
Expand Down

0 comments on commit 3bb73ba

Please sign in to comment.