Top Level Namespace
Defined Under Namespace
Modules: BugFix, EVMime, Enumerable, IOExtras, Kernel, MARC, ParseTree, Rconftool, RwdtinkerTools, TextArray, Zip, Zlib Classes: Array, CloseTag, Comment, Dir, EVTable, EVURI, FakeThread, File, HTTPClient, HTTPServer, HTTPServerException, Hash, IE, Instruction, Integer, Module, Numeric, Object, OpenTag, RWDDone, RWDError, RWDLogin, RWDMessage, RWDProgressBar, RWDServer, RWDSession, RWDTimeOut, RWDTree, RWDWindow, RWDialog, Request, RequestGet, RequestPost, RequestRequest, Response, SGML, SGMLObject, SessionCleanup, Sessions, Special, String, TCPServer, Tag, Text, Thread, ThreadLimiter, Time, Tree, TreeObject, XML, ZipList
Constant Summary collapse
- RWDEmptyline =
"..."
- AL =
"align='left'"
- AC =
"align='center'"
- AR =
"align='right'"
- VA =
"valign='middle'"
- Format =
"\n<!-- %-10s %-10s -->\t"
- Tempfile =
BugFix::Tempfile
- RegExpStringWord =
"([#{tekens11}]+)"
- RegExpWord =
Regexp.new(RegExpStringWord)
- RegExpStringWord2 =
"([#{tekens21}]([#{tekens22}]*[#{tekens23}])?)"
- RegExpWord2 =
Regexp.new(RegExpStringWord2)
- RegExpStringText =
"([#{tekens31}]+)"
- RegExpText =
Regexp.new(RegExpStringText)
- RegExpStringFile =
'(\w[\w\.\-]*)'
- RegExpFile =
Regexp.new(RegExpStringFile)
- RegExpStringEmail =
'([\w\-\.]+@[\w\-\.]+)'
- RegExpEmail =
Regexp.new(RegExpStringEmail)
- RegExpStringURL =
'(\w+:\/\/[\w\.\-]+(:\d*)?\/[\w\.\-\/\#\?\=\%]*)'
- RegExpURL =
Regexp.new(RegExpStringURL)
- RegExpStringPrint =
'([\w \t\r\n\`\~\!\@\#\$\%\^\&\*\(\)\-\+\=\[\]\{\}\;\:\'\"\,\.\/\<\>\?\\\|]+)'
- RegExpPrint =
Regexp.new(RegExpStringPrint)
- RegExpStringDiff =
'(^[\-\+]([^\-\+].*)?)'
- RegExpDiff =
Regexp.new(RegExpStringDiff)
- RegExpStringHTHLink =
'(`[\w\,]*\ba\b[^`]*`)'
- RegExpHTHLink =
Regexp.new(RegExpStringHTHLink)
- RegExpStringHTHSpecial =
'(`[^`]*`)'
- RegExpHTHSpecial =
Regexp.new(RegExpStringHTHSpecial)
- Same =
0
- Down =
1
- Up =
2
- Dummy =
3
Instance Method Summary collapse
- #after(seconds, *args) ⇒ Object
- #ask(options, text = false) ⇒ Object
- #bm(label = "") ⇒ Object
- #cygwin? ⇒ Boolean
- #cygwinbrowser ⇒ Object
- #darwin? ⇒ Boolean
- #defaultbrowser ⇒ Object
- #every(seconds, *args) ⇒ Object
- #evtimeout(seconds) ⇒ Object
- #evtimeoutretry(seconds) ⇒ Object
- #home ⇒ Object
- #id2ref(id) ⇒ Object
- #lambda_cached(&block) ⇒ Object
- #linux? ⇒ Boolean
- #linuxbrowser ⇒ Object
-
#marcservers ⇒ Object
Two lists of open Z39.50 servers: targettest.indexdata.com/ staff.library.mun.ca/staff/toolbox/z3950hosts.htm.
- #nobm ⇒ Object
- #notrace ⇒ Object
- #showinbrowser(html, browser = defaultbrowser) ⇒ Object
- #showurlinbrowser(url, browser = defaultbrowser) ⇒ Object
- #stdtmp ⇒ Object
- #tab2html(tab) ⇒ Object
- #target_os ⇒ Object
- #temp ⇒ Object
- #trace ⇒ Object
- #trap(signal) ⇒ Object
- #uri2txt(s) ⇒ Object
- #url_unescape(string) ⇒ Object
- #user ⇒ Object
- #windows? ⇒ Boolean
- #windowsbrowser ⇒ Object
- #z3950query(isbn, host, port, db) ⇒ Object
Instance Method Details
#after(seconds, *args) ⇒ Object
688 689 690 691 692 693 694 695 |
# File 'lib/rwd/ruby.rb', line 688 def after(seconds, *args) if not seconds.nil? and not seconds.zero? Thread.new(*args) do |*args2| sleep seconds yield(*args2) end end end |
#ask(options, text = false) ⇒ Object
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 |
# File 'lib/rwd/ruby.rb', line 875 def ask(, text=false) i = 0 $stderr.puts "" .each do |s| $stderr.puts " %d %s" % [i+=1, s] end $stderr.puts "" $stderr.print "? " res = $stdin.gets unless res.nil? res = res.strip res = [res.to_i-1] if text and not res.empty? end res end |
#bm(label = "") ⇒ Object
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 |
# File 'lib/rwd/ruby.rb', line 781 def bm(label="") if $nobm if block_given? return yield else return nil end end label = label.inspect #unless label.kind_of?(String) res = nil $bm_mutex = ($bm_mutex or Mutex.new) $bm_mutex.synchronize do if $bm.nil? require "ev/bm" $bm = {} at_exit do l = $bm.keys.collect{|s| s.length}.max #format1 = "%10s %10s %10s %10s %10s %10s %s" #format2 = "%10.6f %10.6f %10.6f %10.6f %10.6f %10d %s" #$stderr.puts format1 % ["USERCPU", "SYSCPU", "CUSERCPU", "CSYSCPU", "ELAPSED", "COUNT", "LABEL"] #$bm.sort{|a, b| [b[1], b[0]] <=> [a[1], a[0]]}.each do |k, v| #$stderr.puts format2 % (v + [k]) #end format1 = "%10s %10s %10s %s" format2 = "%10.6f %10.6f %10d %s" $bm.each do |k, v| $bm[k] = [v[0]+v[1], v[4], v[5]] end $stderr.puts format1 % ["CPU", "ELAPSED", "COUNT", "LABEL"] $bm.sort{|a, b| [b[1], b[0]] <=> [a[1], a[0]]}.each do |k, v| $stderr.puts format2 % (v + [k]) end end end $bm[label] = [0.0]*5 + [0] unless $bm.include?(label) $bm[label][5] += 1 end if block_given? bm = Benchmark.measure{res = yield} bma = bm.to_a # [dummy label, user CPU time, system CPU time, childrens user CPU time, childrens system CPU time, elapsed real time] $bm_last = bma $bm_mutex.synchronize do e = $bm[label] 0.upto(4) do |n| e[n] += bma[n+1] end end end res end |
#cygwin? ⇒ Boolean
750 751 752 |
# File 'lib/rwd/ruby.rb', line 750 def cygwin? not (target_os.downcase =~ /cyg/).nil? end |
#cygwinbrowser ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rwd/browser.rb', line 33 def cygwinbrowser browser, *args = windowsbrowser.splitwords browser = browser.gsub(/\\/, "/") #browser = browser args.collect!{|a| a.gsub(/\\/, "/")} #args.collect!{|a| "\"%s\"" % [a.gsub(/\\/, "/")]} #args.collect!{|a| "\"%s\"" % [a]} res = "\"%s\" %s" % [browser, args.join(" ")] res end |
#darwin? ⇒ Boolean
742 743 744 |
# File 'lib/rwd/ruby.rb', line 742 def darwin? not (target_os.downcase =~ /darwin/).nil? end |
#defaultbrowser ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/rwd/browser.rb', line 60 def defaultbrowser res = nil res = windowsbrowser if windows? res = cygwinbrowser if cygwin? res = linuxbrowser if linux? res end |
#every(seconds, *args) ⇒ Object
697 698 699 700 701 702 703 704 705 706 |
# File 'lib/rwd/ruby.rb', line 697 def every(seconds, *args) if not seconds.nil? and not seconds.zero? Thread.new(*args) do |*args2| loop do sleep seconds yield(*args2) end end end end |
#evtimeout(seconds) ⇒ Object
708 709 710 711 712 713 714 715 |
# File 'lib/rwd/ruby.rb', line 708 def evtimeout(seconds) begin timeout(seconds) do yield end rescue TimeoutError end end |
#evtimeoutretry(seconds) ⇒ Object
717 718 719 720 721 722 723 724 725 726 |
# File 'lib/rwd/ruby.rb', line 717 def evtimeoutretry(seconds) ok = false while not ok evtimeout(seconds) do yield ok = true end end end |
#home ⇒ Object
762 763 764 |
# File 'lib/rwd/ruby.rb', line 762 def home (ENV["HOME"] or ENV["USERPROFILE"] or (File.directory?("h:/") ? "h:" : "c:")).gsub(/\\/, "/") end |
#id2ref(id) ⇒ Object
684 685 686 |
# File 'lib/rwd/ruby.rb', line 684 def id2ref(id) ObjectSpace._id2ref(id) end |
#lambda_cached(&block) ⇒ Object
863 864 865 866 867 868 869 870 871 872 873 |
# File 'lib/rwd/ruby.rb', line 863 def lambda_cached(&block) hash = {} lambda do |*args| res = hash[args] if res.nil? res = block.call(*args) hash[args] = res end res end end |
#linux? ⇒ Boolean
738 739 740 |
# File 'lib/rwd/ruby.rb', line 738 def linux? not (target_os.downcase =~ /linux/).nil? end |
#linuxbrowser ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rwd/browser.rb', line 46 def linuxbrowser application = "" application = `which galeon 2> /dev/null`.chomp if application.empty? application = `which mozilla 2> /dev/null`.chomp if application.empty? application = `which firefox 2> /dev/null`.chomp if application.empty? application = `which opera 2> /dev/null`.chomp if application.empty? application = `which konqueror 2> /dev/null`.chomp if application.empty? application = `which htmlview 2> /dev/null`.chomp if application.empty? application = nil if application.empty? application end |
#marcservers ⇒ Object
Two lists of open Z39.50 servers:
http://targettest.indexdata.com/
http://staff.library.mun.ca/staff/toolbox/z3950hosts.htm
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/zmarc.rb', line 23 def marcservers return [ # Reorder these so that your preferred servers are first # North America ['sirsi.library.utoronto.ca', 2200, 'unicorn' ], # U Toronto ['amicus.collectionscanada.ca', 210, 'NL' ], # Lib & Archives Canada ['aleph.mcgill.ca', 210, 'MUSE' ], # McGill # ['ualapp.library.ualberta.ca', 2200, 'unicorn', ], # U Alberta ['portage.library.ubc.ca', 7090, 'voyager' ], # UBC ['z3950.loc.gov', 7090, 'Voyager' ], # Library of Congress ['catnyp.nypl.org', 210, 'INNOPAC' ], # New York Pub Lib ['library.mit.edu', 9909, 'mit01pub' ], # MIT ['prodorbis.library.yale.edu', 7090, 'voyager' ], # Yale ['catalog.princeton.edu', 7090, 'voyager' ], # Princeton ['ipac.lib.uchicago.edu', 210, 'usmarc' ], # Chicago ['www.saclibrarycatalog.org', 210, 'INNOPAC' ], # Sacramento Pub Lib ['library.bu.edu', 210, 'INNOPAC' ], # Boston U ['voyager.wrlc.org', 7090, 'voyager' ], # Wash Res Lib Consor ['catalog.lib.jhu.edu', 210, 'horizon' ], # Johns Hopkins ['z3950.lib.umich.edu', 210, 'miu01_pub' ], # U Michigan ['catalog.library.cornell.edu',7090, 'voyager' ], # Cornell # UK and Ireland # ['library.ucc.ie', 210, 'INNOPAC' ], # U College Cork ['library.ox.ac.uk', 210, 'MAIN*BIBMAST'], # Oxford ['z3950.nls.uk', 7290, 'voyager' ], # Scottish Nat Lib ['lib-15.lse.ac.uk', 7090, 'voyager' ], # LSE ['libsys.lib.hull.ac.uk', 210, 'INNOPAC' ], # Hull # Europe (non-English) ['sigma.nkp.cz', 9909, 'NKC' ], # Nat Lib Czech R ['lib.mpib-berlin.mpg.de', 2020, 'opac' ], # Max Planck Inst ['ubsun02.biblio.etc.tu-bs.de',2020, 'bac' ], # Bibliotheken Berlins ['z3950.kb.dk', 2100, 'KGL01' ], # Kongelige Bibliothek ['www.bne.es', 2210, 'BIMO' ], # Nat Lib Spain ['roble.unizar.es', 210, 'INNOPAC' ], # U Zaragoza ['www.helmet.fi', 210, 'INNOPAC' ], # Helsinki Lib ['carmin.sudoc.abes.fr', 210, 'ABES-Z39-PUBLIC' ], # France # ['gofor.bibli.ens-cachan.fr', 21210, 'ADVANCE' ], # French school # ['gofor.bibli.ens-cachan.fr', 21210, 'MAIN*BIBMAST'], # French school # ['isis.cilea.it', 2100, 'usmarc' ], # U Brescia # ['aleph.library.tudelft.nl', 9909, 'tud01' ], # # Techn U Delft # ['z3950.bibsys.no', 2100, 'BIBSYS' ], # Nat Lib Norway # ['z3950.nb.no', 2100, 'norbok' ], # Nat Lib Norway #['alpha.bn.org.pl', 210, 'INNOPAC' ], # Nat Lib Poland #['z3950.btj.se', 210, 'BURK' ], # Sweden # ['lbsihol.unimaas.nl', 7190, 'lbs' ], # U Maastricht # Australia and New Zealand #['catalogue.nla.gov.au', 7090, 'voyager' ], # Nat Lib Australia #['nlnzcat.natlib.govt.nz', 7190, 'voyager' ], # Nat Lib New Zealand # Asia # ['library.cuhk.edu.hk', 210, 'INNOPAC' ], # Chinesse U HK # ['linc.nus.edu.sg', 210, 'INNOPAC' ], # Nat U Singapore # ['nbinet.ncl.edu.tw', 210, 'INNOPAC' ], # Nat Cent Lib Taiwan # ['wine.wul.waseda.ac.jp', 210, 'INNOPAC' ], # Waseda U # Africa # ['explore.up.ac.za', 210, 'INNOPAC' ], # U Pretoria # ['natlib1.unisa.ac.za', 210, 'INNOPAC' ], # Nat Lib South Africa ] # Given an ISBN and some Z39.50 information, return MARCXML. Why # MARCXML? Because (now) the ruby-zoom module can't return a # ruby-marc MARC object. It can, however, return MARCXML, which # ruby-marc can grok, so we translate it into XML and then back. end |
#nobm ⇒ Object
777 778 779 |
# File 'lib/rwd/ruby.rb', line 777 def nobm $nobm = true end |
#notrace ⇒ Object
859 860 861 |
# File 'lib/rwd/ruby.rb', line 859 def notrace set_trace_func nil end |
#showinbrowser(html, browser = defaultbrowser) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rwd/browser.rb', line 74 def showinbrowser(html, browser=defaultbrowser) port, io = TCPServer.freeport(7701, 7709) unless browser.nil? Thread.new do begin Thread.pass showurlinbrowser("http://localhost:#{port}/", browser) rescue end end end HTTPServer.serve([port, io]) do |req, resp| resp << html resp.stop end end |
#showurlinbrowser(url, browser = defaultbrowser) ⇒ Object
68 69 70 71 72 |
# File 'lib/rwd/browser.rb', line 68 def showurlinbrowser(url, browser=defaultbrowser) command = "#{browser} \"#{url}\"" system(command) or $stderr.puts "Starting of the browser failed, or the browser terminated abnormally.\nCommand => #{command}" end |
#stdtmp ⇒ Object
770 771 772 |
# File 'lib/rwd/ruby.rb', line 770 def stdtmp $stderr = $stdout = File.new("#{temp}/ruby.#{Process.pid}.log", "a") end |
#tab2html(tab) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/rwd/browser.rb', line 95 def tab2html(tab) res = "" tab = tab.to_html(false) res << "<html>\n" res << "<body>\n" res << "<table align='center' border='1' cellspacing='0' cellpadding='3'>\n" res << "<tbody>\n" tab.split(/\r*\n/).each do |line| res << "<tr>\n" line.split(/\t/, -1).each do |veld| veld = " " if veld.compress.empty? res << "<td>%s</td>\n" % veld end res << "</tr>\n" end res << "</tbody>\n" res << "</table>\n" res << "</body>\n" res << "</html>\n" res end |
#target_os ⇒ Object
754 755 756 |
# File 'lib/rwd/ruby.rb', line 754 def target_os Config::CONFIG["target_os"] or "" end |
#temp ⇒ Object
766 767 768 |
# File 'lib/rwd/ruby.rb', line 766 def temp (ENV["TMPDIR"] or ENV["TMP"] or ENV["TEMP"] or "/tmp").gsub(/\\/, "/") end |
#trace ⇒ Object
843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 |
# File 'lib/rwd/ruby.rb', line 843 def trace res =nil set_trace_func lambda { |event, file, line, id, binding, classname| $stderr.printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname } if block_given? res = yield notrace end res end |
#trap(signal) ⇒ Object
728 729 730 731 732 733 734 735 736 |
# File 'lib/rwd/ruby.rb', line 728 def trap(signal) Kernel::trap(signal) do yield end # Seems pointless, but it's for catching ^C under Windows... every(1) {} if windows? end |
#uri2txt(s) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/rwd/net.rb', line 20 def uri2txt(s) # ??? Werkt niet goed i = s.index(/%[[:digit:]]{2}/) while not i.nil? s = s[0..(i-1)] + s[(i+1)..(i+2)].unpack('H2').shift.to_i.chr + s[(i+3)..-1] i = s.index(/%[[:digit:]]{2}/) end s end |
#url_unescape(string) ⇒ Object
565 566 567 568 569 |
# File 'lib/rwd/net.rb', line 565 def url_unescape(string) string.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n) do [$1.delete('%')].pack('H*') end end |
#user ⇒ Object
758 759 760 |
# File 'lib/rwd/ruby.rb', line 758 def user ENV["USER"] or ENV["USERNAME"] end |
#windows? ⇒ Boolean
746 747 748 |
# File 'lib/rwd/ruby.rb', line 746 def windows? not (target_os.downcase =~ /32/).nil? end |
#windowsbrowser ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rwd/browser.rb', line 12 def windowsbrowser $stderr.puts "Looking for default browser..." filetype = "htmlfile" application = nil begin Win32::Registry::HKEY_CLASSES_ROOT.open(".html") do |reg| filetype = reg[""] end Win32::Registry::HKEY_CLASSES_ROOT.open(filetype + "\\shell\\open\\command") do |reg| application = reg[""] end rescue NameError $stderr.puts "Only available for Windows and Cygwin." end application end |
#z3950query(isbn, host, port, db) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/zmarc.rb', line 89 def z3950query(isbn, host, port, db) begin ZOOM::Connection.open(host, port) do |conn| conn.database_name = db conn.preferred_record_syntax = 'MARC21' rset = conn.search("@attr 1=7 #{isbn}") return rset[0].xml end rescue Exception => e # puts e # Uncomment to see any server erorrs return nil end end |