Showing posts with label development. Show all posts
Showing posts with label development. Show all posts

Wednesday, March 23, 2011

hornetseye install continued

stuck on opencv gem

recap: trying to install opencv gem, it's not installing.
kudi-guetta% gem install opencv
Building native extensions.  This could take a while...
ERROR:  Error installing opencv:
        ERROR: Failed to build gem native extension.

        /home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/bin/ruby extconf.rb
>> check require libraries...
checking for main() in -lcxcore... yes
checking for main() in -lcv... yes
checking for main() in -lhighgui... yes
checking for main() in -lstdc++... yes
>> check require headers...
checking for cxcore.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/bin/ruby
        --with-opencv-dir
        --without-opencv-dir
        --with-opencv-include
        --without-opencv-include=${opencv-dir}/include
        --with-opencv-lib
        --without-opencv-lib=${opencv-dir}/lib
        --with-ffcall-dir
        --without-ffcall-dir
        --with-ffcall-include
        --without-ffcall-include=${ffcall-dir}/include
        --with-ffcall-lib
        --without-ffcall-lib=${ffcall-dir}/lib
        --with-cxcorelib
        --without-cxcorelib
        --with-cvlib
        --without-cvlib
        --with-highguilib
        --without-highguilib
        --with-stdc++lib
        --without-stdc++lib
extconf.rb:41: cxcore.h not found. (RuntimeError)
        from extconf.rb:40:in `each'
        from extconf.rb:40


Gem files will remain installed in /home/ozzloy/.rvm/gems/ruby-1.8.7-p330@hornetseye/gems/opencv-0.0.7 for inspection.
Results logged to /home/ozzloy/.rvm/gems/ruby-1.8.7-p330@hornetseye/gems/opencv-0.0.7/ext/gem_make.out
annoying.
jim v on rubyforge seems to have solved the problem. except where do i run ruby extconf.rb? i went to the directory containing gem_make.out to read it. turns out it just has the same thing as was printed to terminal above. but in the same directory was extconf.rb.

extconf.rb

i planned on running ruby extconf.rb with some extra flags, like jim v. for the values to the flag:
kudi-guetta% find / -name cxcore.h 2> /dev/null
/usr/include/opencv/cxcore.h
that's the header file location. i also needed the lib file location.
kudi-guetta% ls /usr/lib|grep opencv              
kudi-guetta% find / -name "*opencv*" 2> /dev/null
...
/usr/lib/pkgconfig/opencv.pc
...
i vaguely remember *.pc files from some other project. they are used by pkg-config to get the location of libs and header files. so i checked in there for the locations.
popped open extconf.rb just to see what was in it.
made these changes to it:

then in that directory:
rvm 1.8.7@hornetseye
ruby extconf.rb
make
still a fail, but in a different place:
kudi-guetta% ruby extconf.rb
>> check require libraries...
checking for main() in -lcxcore... yes
checking for main() in -lcv... yes
checking for main() in -lhighgui... yes
checking for main() in -lstdc++... yes
>> check require headers...
checking for cxcore.h... yes
checking for cv.h... yes
checking for highgui.h... yes
checking for stdarg.h... yes
>> ----- optional -----
>> check ffcall...
checking for main() in -lcallback... yes
checking for callback.h... yes
>> support OpenCV::GUI
creating Makefile
kudi-guetta% make
g++ -I. -I. -I/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/x86_64-linux -I. -DHAVE_CXCORE_H -DHAVE_CV_H -DHAVE_HIGHGUI_H -DHAVE_STDARG_H -DHAVE_CALLBACK_H -I/usr/include -I/usr/include/opencv    -fPIC -g -O2  -fPIC    -c cvchaincode.cpp
In file included from opencv.h:106,
                 from cvchaincode.h:13,
                 from cvchaincode.cpp:10:
cvcondensation.h:39: error: expected initializer before ‘*’ token
cvchaincode.cpp:49: error: expected ‘}’ at end of input
make: *** [cvchaincode.o] Error 1
aaaRRRGGG

wedekind's opencv ruby gem

ugh.
going back to the install site, i see this:
If you are unable to use RubyGems to install opencv, you may have to install hornetseye-opencv from source:

git clone git://github.com/wedesoft/hornetseye-opencv.git
cd hornetseye-opencv
rake
sudo rake install
cd ..
which isn't working for me. or ... it doesn't seem to be. here's what i get:
kudi-guetta% pwd
/home/ozzloy/src/hornetseye/hornetseye-opencv
kudi-guetta% rake 
(in /home/ozzloy/src/hornetseye/hornetseye-opencv)
kudi-guetta% rake install
(in /home/ozzloy/src/hornetseye/hornetseye-opencv)
kudi-guetta% rake test
(in /home/ozzloy/src/hornetseye/hornetseye-opencv)
ext/hornetseye_opencv.so: no such file to load -- opencv (LoadError)
        from ./test/tc_hornetseye_opencv.rb:22
        from /home/ozzloy/.rvm/gems/ruby-1.8.7-p330@global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `load'
        from /home/ozzloy/.rvm/gems/ruby-1.8.7-p330@global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
        from /home/ozzloy/.rvm/gems/ruby-1.8.7-p330@global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each'
        from /home/ozzloy/.rvm/gems/ruby-1.8.7-p330@global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
rake aborted!
Command failed with status (1): [/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/b...]

(See full trace by running task with --trace)
just under the instructions for installing hornetseye-opencv, the page links to wedekind's fork of the opencv gem which i tried installing next.

installing wedekind's opencv gem fork

here's the tail end of the install process from wedekind's opencv gem install instructions.
kudi-guetta% rake gem
(in /home/ozzloy/src/hornetseye/ruby-opencv)
mkdir -p pkg
Gemspec generated
WARNING:  description and summary are identical
  Successfully built RubyGem
  Name: opencv
  Version: 0.0.7
  File: opencv-0.0.7.gem
mv opencv-0.0.7.gem pkg/opencv-0.0.7.gem
kudi-guetta% gem install pkg/opencv-0.0.7.gem 
Building native extensions.  This could take a while...
ERROR:  Error installing pkg/opencv-0.0.7.gem:
        ERROR: Failed to build gem native extension.

        /home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/bin/ruby extconf.rb
>> check require libraries...
checking for main() in -lcxcore... yes
checking for main() in -lcv... yes
checking for main() in -lhighgui... yes
checking for main() in -lcvaux... yes
checking for main() in -lstdc++... yes
>> check require headers...
checking for cxcore.h... yes
checking for cv.h... yes
checking for highgui.h... yes
checking for cvaux.h... yes
checking for stdarg.h... yes
>> ----- optional -----
>> check ffcall...
checking for main() in -lcallback... yes
checking for callback.h... yes
>> support OpenCV::GUI
creating Makefile

make
g++ -I. -I. -I/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/x86_64-linux -I. -DHAVE_CXCORE_H -DHAVE_CV_H -DHAVE_HIGHGUI_H -DHAVE_CVAUX_H -DHAVE_STDARG_H -DHAVE_CALLBACK_H -I/usr/include -I/usr/include/opencv    -fPIC -g -O2  -fPIC    -c cvchaincode.cpp
In file included from opencv.h:101,
                 from cvchaincode.h:13,
                 from cvchaincode.cpp:10:
cvcondensation.h:39: error: expected initializer before ‘*’ token
cvchaincode.cpp:49: error: expected ‘}’ at end of input
make: *** [cvchaincode.o] Error 1


Gem files will remain installed in /home/ozzloy/.rvm/gems/ruby-1.8.7-p330@hornetseye/gems/opencv-0.0.7 for inspection.
Results logged to /home/ozzloy/.rvm/gems/ruby-1.8.7-p330@hornetseye/gems/opencv-0.0.7/ext/gem_make.out
and this is the same problem i was having installing the gem via gem install opencv, after modifying the extconf.rb file to point to the right places. what do i do now? i'll see if i can figure out the problem with cvcondensation.h. nope, the file looks fine at line 39.

moving on to openexr

this installed just fine with:
sudo aptitude install -y libopenexr-dev
gem install hornetseye-openexr #i'm using rvm

on to qt4

installing the qt libs and stuff went fine sudo aptitude install libqt4-ruby1.8 qt4-dev-tools libswscale-dev -y
but the next step didn't work:
kudi-guetta% cd hornetseye-qt4 
kudi-guetta% rake
(in /home/ozzloy/src/hornetseye/hornetseye-qt4)
g++ -MM ext/xvwidget.cc ext/frame.cc ext/init.cc | sed -e :a -e N -e 's/\n/\$/g' -e ta | sed -e 's/ *\\\$ */ /g' -e 's/\$/\n/g' | sed -e 's/^/ext\//' > .depends.mf
g++ -DNDEBUG -DHAVE_CONFIG_H -D__STDC_CONSTANT_MACROS    -g -O2  -fPIC   -I/usr/include/qt4 -I/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/x86_64-linux -c -o ext/xvwidget.o ext/xvwidget.cc
In file included from ext/xvwidget.cc:36:
ext/xvwidget.hh:22: fatal error: X11/extensions/Xv.h: No such file or directory
compilation terminated.
rake aborted!
Command failed with status (1): [g++ -DNDEBUG -DHAVE_CONFIG_H -D__STDC_CONS...]
/home/ozzloy/src/hornetseye/hornetseye-qt4/Rakefile:210
(See full trace by running task with --trace)
kudi-guetta%
i'll come back to this too.
so far i fail at ruby-opencv and hornetseye-qt4.

hornetseye-rmagick

of course the ubuntu stuff works fine: sudo aptitude install libmagickwand-dev -y.
woo! this seems to have worked as well: gem install hornetseye-rmagick (again, using rvm)

skipping v4l, straight to v4l2

sudo aptitude install linux-libc-dev -y was already installed.
gem install hornetseye-v4l2 went just fine too.

hornetseye-xorg

this might solve the problem with qt4 since it had something to do with a missing header file in some X11 path. let's hope so.
sudo aptitude install xserver-xorg-dev libgl1-mesa-dev libglu1-mesa-dev -y worked
gem install hornetseye-xorg failed like this:
kudi-guetta% gem install hornetseye-xorg
Fetching: hornetseye-xorg-0.5.2.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing hornetseye-xorg:
        ERROR: Failed to build gem native extension.

        "/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/bin/ruby" -rubygems /home/ozzloy/.rvm/gems/ruby-1.8.7-p330@global/gems/rake-0.8.7/bin/rake RUBYARCHDIR=/home/ozzloy/.rvm/gems/ruby-1.8.7-p330@hornetseye/gems/hornetseye-xorg-0.5.2/lib RUBYLIBDIR=/home/ozzloy/.rvm/gems/ruby-1.8.7-p330@hornetseye/gems/hornetseye-xorg-0.5.2/lib
g++ -MM ext/openglimagepainter.cc ext/x11window.cc ext/x11output.cc ext/xvideoimagepainter.cc ext/frame.cc ext/x11display.cc ext/init.cc ext/timer.cc ext/ximagepainter.cc | sed -e :a -e N -e 's/\n/\$/g' -e ta | sed -e 's/ *\\\$ */ /g' -e 's/\$/\n/g' | sed -e 's/^/ext\//' > .depends.mf
(in /home/ozzloy/.rvm/gems/ruby-1.8.7-p330@hornetseye/gems/hornetseye-xorg-0.5.2)
g++ -DNDEBUG -DHAVE_CONFIG_H -D__STDC_CONSTANT_MACROS    -g -O2  -fPIC   -I/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/x86_64-linux -c -o ext/openglimagepainter.o ext/openglimagepainter.cc
g++ -DNDEBUG -DHAVE_CONFIG_H -D__STDC_CONSTANT_MACROS    -g -O2  -fPIC   -I/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/x86_64-linux -c -o ext/x11window.o ext/x11window.cc
ext/x11window.cc:20: fatal error: X11/xpm.h: No such file or directory
compilation terminated.
rake aborted!
Command failed with status (1): [g++ -DNDEBUG -DHAVE_CONFIG_H -D__STDC_CONS...]
/home/ozzloy/.rvm/gems/ruby-1.8.7-p330@hornetseye/gems/hornetseye-xorg-0.5.2/Rakefile:209
(See full trace by running task with --trace)


Gem files will remain installed in /home/ozzloy/.rvm/gems/ruby-1.8.7-p330@hornetseye/gems/hornetseye-xorg-0.5.2 for inspection.
Results logged to /home/ozzloy/.rvm/gems/ruby-1.8.7-p330@hornetseye/gems/hornetseye-xorg-0.5.2/./gem_make.out
damn. since that's the last section of interest to me, i'll try to solve it.
google for "X11/xpm.h: No such file or directory" gives me yinglcs2's similar problem. solution: sudo aptitude install -y libxpm-dev.
now it fails with a different message:
kudi-guetta% gem install hornetseye-xorg     
Building native extensions.  This could take a while...
ERROR:  Error installing hornetseye-xorg:
        ERROR: Failed to build gem native extension.

        "/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/bin/ruby" -rubygems /home/ozzloy/.rvm/gems/ruby-1.8.7-p330@global/gems/rake-0.8.7/bin/rake RUBYARCHDIR=/home/ozzloy/.rvm/gems/ruby-1.8.7-p330@hornetseye/gems/hornetseye-xorg-0.5.2/lib RUBYLIBDIR=/home/ozzloy/.rvm/gems/ruby-1.8.7-p330@hornetseye/gems/hornetseye-xorg-0.5.2/lib
g++ -DNDEBUG -DHAVE_CONFIG_H -D__STDC_CONSTANT_MACROS    -g -O2  -fPIC   -I/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/x86_64-linux -c -o ext/openglimagepainter.o ext/openglimagepainter.cc
(in /home/ozzloy/.rvm/gems/ruby-1.8.7-p330@hornetseye/gems/hornetseye-xorg-0.5.2)
g++ -DNDEBUG -DHAVE_CONFIG_H -D__STDC_CONSTANT_MACROS    -g -O2  -fPIC   -I/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/x86_64-linux -c -o ext/x11window.o ext/x11window.cc
g++ -DNDEBUG -DHAVE_CONFIG_H -D__STDC_CONSTANT_MACROS    -g -O2  -fPIC   -I/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/x86_64-linux -c -o ext/x11output.o ext/x11output.cc
g++ -DNDEBUG -DHAVE_CONFIG_H -D__STDC_CONSTANT_MACROS    -g -O2  -fPIC   -I/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/x86_64-linux -c -o ext/xvideoimagepainter.o ext/xvideoimagepainter.cc
In file included from ext/xvideoimagepainter.cc:35:
ext/xvideoimagepainter.hh:20: fatal error: X11/extensions/Xvlib.h: No such file or directory
compilation terminated.
rake aborted!
Command failed with status (1): [g++ -DNDEBUG -DHAVE_CONFIG_H -D__STDC_CONS...]
/home/ozzloy/.rvm/gems/ruby-1.8.7-p330@hornetseye/gems/hornetseye-xorg-0.5.2/Rakefile:209
(See full trace by running task with --trace)


Gem files will remain installed in /home/ozzloy/.rvm/gems/ruby-1.8.7-p330@hornetseye/gems/hornetseye-xorg-0.5.2 for inspection.
Results logged to /home/ozzloy/.rvm/gems/ruby-1.8.7-p330@hornetseye/gems/hornetseye-xorg-0.5.2/./gem_make.out
so to google again, this time for "X11/extensions/Xvlib.h: No such file or directory".
found a solution from ubuntu forum's abhayashi:
sudo aptitude install -y libxv-dev
and now gem install hornetseye-xorg works!

back to hornetseye-qt4

since hornetseye-xorg involved a bunch of x stuff, and the qt4 error looked like a missing x header, i'll just try installing it again:
kudi-guetta% pwd                               
/home/ozzloy/src/hornetseye/hornetseye-qt4
kudi-guetta% rake             
(in /home/ozzloy/src/hornetseye/hornetseye-qt4)
g++ -DNDEBUG -DHAVE_CONFIG_H -D__STDC_CONSTANT_MACROS    -g -O2  -fPIC   -I/usr/include/qt4 -I/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/x86_64-linux -c -o ext/xvwidget.o ext/xvwidget.cc
g++ -DNDEBUG -DHAVE_CONFIG_H -D__STDC_CONSTANT_MACROS    -g -O2  -fPIC   -I/usr/include/qt4 -I/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/x86_64-linux -c -o ext/frame.o ext/frame.cc
g++ -DNDEBUG -DHAVE_CONFIG_H -D__STDC_CONSTANT_MACROS    -g -O2  -fPIC   -I/usr/include/qt4 -I/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/x86_64-linux -c -o ext/init.o ext/init.cc
g++ -shared -o ext/hornetseye_qt4.so ext/xvwidget.o ext/frame.o ext/init.o -lswscale -lX11 -lXv -lQtGui -lQtCore -L/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/lib -Wl,-R -Wl,/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/lib -L/home/ozzloy/.rvm/rubies/ruby-1.8.7-p330/lib -lruby -L.  -rdynamic -Wl,-export-dynamic -lrt -ldl -lcrypt -lm   -lc
kudi-guetta% rake install
(in /home/ozzloy/src/hornetseye/hornetseye-qt4)
kudi-guetta% rake test
(in /home/ozzloy/src/hornetseye/hornetseye-qt4)
hooray! that looks like it worked. now the only problem is with the opencv extension.

Friday, February 5, 2010

slightly better kludge for suppressing ruby soap warnings

code i ended up with, followed by a description of the journey:

#monkeypatch kludge to get Parser to suppress "ignored element" warnings
#generated when mumboe-soap4r consumes wsdl that asp.net serves
#TODO: find a cleaner way to do this
class WSDL::Parser
old_initialize = instance_method(:initialize)
define_method(:initialize) do |*args, &block|
old_initialize.bind(self).call(*args, &block)

#set up QNames to ignore
names = ["binding", "operation", "body", "header", "address"]
namespace = "http://schemas.xmlsoap.org/wsdl/soap12/"
ignored = names.inject({}) do |ignored, name|
elename = XSD::QName.new(namespace, name)
ignored.update(elename => elename)
end

instance_variable_set(:@ignored, ignored)
end
end

how i got there


yesterday i implemented a kludge to suppress these warnings, but it was a bit broad. it would suppress everything printed to stderr during decode_tag. i refined that method to get to the code above. to make yesterday's kludge, i had to read some of the code in /var/lib/gems/1.9.0/gems/mumboe-soap4r-1.5.8.3/lib/wsdl/parser.rb. i noticed the use of @ignored to prevent duplicate warnings. i figured i could populate it with the things i don't care about before doing any wsdl consumption. turns out that worked.

what warnings to suppress


so i needed to print out the contents of @ignored. at first, i tried monkeypatching decode_tag to print out stuff as it was added to @ignored but that resulted in many duplicates. ironically, avoiding this duplication is exactly the reason for having @ignored. instead i went to the place where decode_tag was first called and monkeypatched that method (start_element).

deeper


i found that @ignored was populated with XSD::QNames. so i went to .../lib/xsd/qname.rb to find out how to create them and how they were compared. QName creation requires a namespace and a name. so i needed to have each key and value in @ignore print its namespace and name. fortunately these were readable attributes, so i just had to modify start_element in wsdl/parser.rb

back to wsdl/parser.rb


so i landed on this monkeypatch, which is the slickness:

class WSDL::Parser
def parse(string_or_readable)
@parsestack = []
@lastnode = nil
@textbuf = ''
@parser.do_parse(string_or_readable)
puts
puts "ignored = {"
@ignored.each do |key, value|
puts "XSD::QName.new(\"#{key.namespace}\", \"#{key.name}\") =>"
puts "XSD::QName.new(\"#{value.namespace}\", \"#{value.name}\"),"
end
puts "}"
@lastnode
end
end

that's right, it prints out the information i need formatted as ruby code so i just copy-pasta'd the output back into my code and massaged it a little.

kinda sorta almost


this result was almost what i wanted. here's the code:

class WSDL::Parser
old_initialize = instance_method(:initialize)
define_method(:initialize) do |*args, &block|
old_initialize.bind(self).call(*args, &block)
ignored = {
XSD::QName.new("http://schemas.xmlsoap.org/wsdl/soap12/", "binding") =>
XSD::QName.new("http://schemas.xmlsoap.org/wsdl/soap12/", "binding"),
XSD::QName.new("http://schemas.xmlsoap.org/wsdl/soap12/", "operation") =>
XSD::QName.new("http://schemas.xmlsoap.org/wsdl/soap12/", "operation"),
XSD::QName.new("http://schemas.xmlsoap.org/wsdl/soap12/", "body") =>
XSD::QName.new("http://schemas.xmlsoap.org/wsdl/soap12/", "body"),
XSD::QName.new("http://schemas.xmlsoap.org/wsdl/soap12/", "header") =>
XSD::QName.new("http://schemas.xmlsoap.org/wsdl/soap12/", "header"),
XSD::QName.new("http://schemas.xmlsoap.org/wsdl/soap12/", "address") =>
XSD::QName.new("http://schemas.xmlsoap.org/wsdl/soap12/", "address"),
}
instance_variable_set(:@ignored, ignored)
end
end

this was nearly good enough for me to stop. it suppressed exactly what i knew about. nothing more, nothing less. but that's a lot of text. and a lot of it is repepetetetivive. and every QName is created twice, so technically it wasn't populating @ignored in exactly the same way as decode_tag does. and what if the namespace needs changing, or i want to add another name? i felt this would be annoying to maintain.

another step


so i used a variable to store the namespace and used a variable to store each QName.
here's that code:

class WSDL::Parser
old_initialize = instance_method(:initialize)
define_method(:initialize) do |*args, &block|
old_initialize.bind(self).call(*args, &block)
namespace = "http://schemas.xmlsoap.org/wsdl/soap12/"
binding = XSD::QName.new(namespace, "binding")
operation = XSD::QName.new(namespace, "operation")
body = XSD::QName.new(namespace, "body")
header = XSD::QName.new(namespace, "header")
address = XSD::QName.new(namespace, "address")
ignored = {
binding => binding,
operation => operation,
body => body,
header => header,
address => address,
}
instance_variable_set(:@ignored, ignored)
end
end

all right. better. but ... augh, i can't let it be that way. i mean, come on! for every ignored thing, the name of the ignored thing shows up 4 times, on 2 different lines that aren't right next to each other. still not DRY enough. i figured i could create an array with symbols and do something with that. turns out that 3 of the 4 times a name showed up, it was just a temporary variable and the true essence could be summed up more generically so that any particular name was only given once! so i messed with Enumerable#each and finally landed on a workable solution using Enumberable#inject.

final code again (so you don't have to scroll up):



#monkeypatch kludge to get Parser to suppress "ignored element" warnings
#generated when mumboe-soap4r consumes wsdl that asp.net serves
#TODO: find a cleaner way to do this
class WSDL::Parser
old_initialize = instance_method(:initialize)
define_method(:initialize) do |*args, &block|
old_initialize.bind(self).call(*args, &block)

#set up QNames to ignore
names = ["binding", "operation", "body", "header", "address"]
namespace = "http://schemas.xmlsoap.org/wsdl/soap12/"
ignored = names.inject({}) do |ignored, name|
elename = XSD::QName.new(namespace, name)
ignored.update(elename => elename)
end

instance_variable_set(:@ignored, ignored)
end
end

now when someone wants to add a new ignored name, they just add it to the list of names that get ignored! one place! <comma> <space> <quotation mark> <name> <quotation mark>. the rest of the work is done generically, automatically. and i think reading this is easier than reading the intermediate steps. there's less to read. less dense. easier to update. a good kludge.
so i'm glad that's done. ... or is it?

it's still a kludge


ultimately, this is neat and all, but it's still a kludge. i need to figure out why these warnings are generated at all. i don't want to have to read a wsdl, or read more code involved in the process of parsing a wsdl. a brief look tells me it must be that parent.parse_element(elename) returns nil in some case. i don't know what type parent is and i don't feel like searching any further right now.

Wednesday, January 27, 2010

be careful with ruby include

turns out the problem i've been having over the last few days has been that i included some libs in the top level of a ruby file. so the module's definition of "read" overrode the kernel's version. as you might suspect, changing ruby's idea of "read" around leads to errors. in my case, the first code to hit this was inside a soap library, which called an http library. so i thought the problem might be in there. i spent yesterday and today tracking that error down. i did other things during that time, but still that was lots of time.

i tracked it down by creating a minimal test case for the soap portion, iprofiletools.rb, creating a class out of it and having a small driver at the end of the class definition file: if $0 == __FILE__ then driver_code end.
when that worked, but using the class in the project still yielded errors, i knew it wasn't the soap code that was bad. i suspected global variables or constants set in the module might be messing with some setting used somewhere down the line.
so i tried putting in all the includes from vue_monitor.rb to the top of iprofiletools.rb.
this reproduced the errors i saw when running vue_monitor.rb. since i didn't actually need any of those "require"s and "include"s, i started removing them and rerunning iprofiletools until i had a minimal set that created the error. that led me to SimpleCommons
i looked in SimpleCommons for globals and constants and found nothing obvious. so i started commenting out large portions and rerunning iprofiletools. eventually i narrowed it down to the read function.
that's when i realized that i was "include"ing SimpleCommons at the top level. all i needed to do was include it within the class, instead of at the top level, directly into Kernel.
that's a better model of what i want anyways. i want the stuff in SimpleCommons to be a part of the Vue_Monitor class, not a part of Kernel.

i'm not sure how this problem didn't come up earlier. git bisect would have been a better approach to this. i could have seen the diff that started this all. but the problem only appeared on one machine and not on my laptop. so i initially started with the suspicion that the installed library was the culprit. i'm still not sure why errors only produced on one machine and not the other.

anywho. i've fixed it. i understand part of what was wrong. i know now to be careful with includes.

Where am I?