zcc 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/History.txt +13 -0
  2. data/Manifest.txt +36 -1
  3. data/Rakefile +6 -1
  4. data/bin/zcc +98 -132
  5. data/{bin → examples}/linter.pl +0 -0
  6. data/examples/zcc.yaml +22 -10
  7. data/examples/zebra/README +2 -0
  8. data/examples/zebra/key/empty +1 -0
  9. data/examples/zebra/lock/empty +1 -0
  10. data/examples/zebra/records/examples/0.xml +1 -0
  11. data/examples/zebra/records/examples/1.xml +1 -0
  12. data/examples/zebra/records/examples/2.xml +1 -0
  13. data/examples/zebra/records/examples/3.xml +1 -0
  14. data/examples/zebra/records/examples/4.xml +1 -0
  15. data/examples/zebra/records/examples/5.xml +1 -0
  16. data/examples/zebra/records/examples/6.xml +1 -0
  17. data/examples/zebra/records/examples/7.xml +1 -0
  18. data/examples/zebra/records/examples/8.xml +1 -0
  19. data/examples/zebra/records/examples/9.xml +1 -0
  20. data/examples/zebra/register/empty +1 -0
  21. data/examples/zebra/shadow/empty +1 -0
  22. data/examples/zebra/tab/bib1.abs +151 -0
  23. data/examples/zebra/tab/bib1.att +151 -0
  24. data/examples/zebra/tab/default.idx +57 -0
  25. data/examples/zebra/tab/explain.abs +224 -0
  26. data/examples/zebra/tab/explain.att +27 -0
  27. data/examples/zebra/tab/explain.tag +175 -0
  28. data/examples/zebra/tab/gils.att +79 -0
  29. data/examples/zebra/tab/kohalis +1 -0
  30. data/examples/zebra/tab/numeric.chr +13 -0
  31. data/examples/zebra/tab/record.abs +66 -0
  32. data/examples/zebra/tab/sort-string-utf.chr +48 -0
  33. data/examples/zebra/tab/tagsetm.tag +35 -0
  34. data/examples/zebra/tab/usmarc.mar +3 -0
  35. data/examples/zebra/tab/word-phrase-utf.chr +41 -0
  36. data/examples/zebra/tmp/empty +1 -0
  37. data/examples/zebra/zebra.cfg +39 -0
  38. data/lib/zcc/marcadditions.rb +32 -10
  39. data/lib/zcc/pickers.rb +105 -29
  40. data/lib/zcc/subfieldeditor.rb +70 -0
  41. data/lib/zcc/version.rb +1 -1
  42. data/lib/zcc/zoomer.rb +72 -0
  43. data/website/index.html +1 -1
  44. data/website/koha.html +2 -2
  45. data/website/koha.txt +7 -5
  46. data/website/zcc.html +59 -31
  47. data/website/zcc.txt +52 -23
  48. data/website/zebra.html +80 -0
  49. data/website/zebra.txt +36 -0
  50. metadata +76 -6
data/History.txt CHANGED
@@ -1,3 +1,16 @@
1
+ == 0.0.3
2
+ * major changes:
3
+ * added dependencies to Rakefile
4
+ * added dependency to gem highline
5
+ * added subfield editing of existing fields. very basic but seems to work.
6
+ * Character encoding conversion from MARC-8 to UTF-8. ruby-zoom takes care of conversion through YAZ
7
+ * Added experimental localhost ztarget through zebra. See http://zcc.rubyforge.org/zebra.html This feature is turned ON by default.
8
+ * minor changes:
9
+ * general code cleaning and refactoring. paid more attention to
10
+ namespace issues
11
+ * added information on website on how to locally deploy gem from svn
12
+ * added some colorizing to MARC records in display using Highline
13
+
1
14
  == 0.0.2 2007-06-24
2
15
  * 2 major changes:
3
16
  * moved all config to yaml file
data/Manifest.txt CHANGED
@@ -3,14 +3,47 @@ LICENSE
3
3
  Manifest.txt
4
4
  README.txt
5
5
  Rakefile
6
- bin/linter.pl
7
6
  bin/zcc
7
+ examples/linter.pl
8
8
  examples/zcc.yaml
9
+ examples/zebra/key/empty
10
+ examples/zebra/lock/empty
11
+ examples/zebra/README
12
+ examples/zebra/register/empty
13
+ examples/zebra/records/examples/0.xml
14
+ examples/zebra/records/examples/1.xml
15
+ examples/zebra/records/examples/2.xml
16
+ examples/zebra/records/examples/3.xml
17
+ examples/zebra/records/examples/4.xml
18
+ examples/zebra/records/examples/5.xml
19
+ examples/zebra/records/examples/6.xml
20
+ examples/zebra/records/examples/7.xml
21
+ examples/zebra/records/examples/8.xml
22
+ examples/zebra/records/examples/9.xml
23
+ examples/zebra/shadow/empty
24
+ examples/zebra/tab/bib1.abs
25
+ examples/zebra/tab/bib1.att
26
+ examples/zebra/tab/default.idx
27
+ examples/zebra/tab/explain.abs
28
+ examples/zebra/tab/explain.att
29
+ examples/zebra/tab/explain.tag
30
+ examples/zebra/tab/gils.att
31
+ examples/zebra/tab/kohalis
32
+ examples/zebra/tab/numeric.chr
33
+ examples/zebra/tab/record.abs
34
+ examples/zebra/tab/sort-string-utf.chr
35
+ examples/zebra/tab/tagsetm.tag
36
+ examples/zebra/tab/usmarc.mar
37
+ examples/zebra/tab/word-phrase-utf.chr
38
+ examples/zebra/tmp/empty
39
+ examples/zebra/zebra.cfg
9
40
  examples/zoomer-iterator.txt
10
41
  lib/zcc.rb
11
42
  lib/zcc/marcadditions.rb
12
43
  lib/zcc/pickers.rb
44
+ lib/zcc/subfieldeditor.rb
13
45
  lib/zcc/version.rb
46
+ lib/zcc/zoomer.rb
14
47
  scripts/txt2html
15
48
  setup.rb
16
49
  test/test_helper.rb
@@ -24,3 +57,5 @@ website/stylesheets/screen.css
24
57
  website/template.rhtml
25
58
  website/zcc.html
26
59
  website/zcc.txt
60
+ website/zebra.html
61
+ website/zebra.txt
data/Rakefile CHANGED
@@ -71,7 +71,12 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
71
71
 
72
72
  # == Optional
73
73
  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
74
- #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
74
+ p.extra_deps = [
75
+ ['marc','>=0.1.6'],
76
+ ['zoom', '>=0.3.0'],
77
+ ['unicode','>=0.1'],
78
+ ['highline', '>=1.2.9']
79
+ ] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
75
80
  #p.spec_extras = {} # A hash of extra values to set in the gemspec.
76
81
  end
77
82
 
data/bin/zcc CHANGED
@@ -15,31 +15,32 @@ require 'unicode'
15
15
  #--my modules
16
16
  require 'zcc/marcadditions'
17
17
  require 'zcc/pickers'
18
-
19
- class Array
20
- include Pickers
21
- end
22
-
23
- class Object #MARC::Record
24
- include MARCAdditions
25
- end
26
-
27
-
28
-
29
-
30
- class String
31
- def usubstr(a, b)
32
- i = 0
33
- buff = ''
34
- each_char do
35
- | c |
36
- i += 1
37
- if i >= a: buff += c end
38
- if i == b: return buff end
18
+ require 'zcc/subfieldeditor'
19
+ require 'zcc/zoomer'
20
+ #require 'wcid'
21
+ require 'highline/import'
22
+ #require 'curses'
23
+
24
+ termsize = HighLine::SystemExtensions.terminal_size
25
+ $term_width = termsize[0]
26
+ $term_height = termsize[1]
27
+ $clear_code = %x{clear}
28
+
29
+
30
+ ft = HighLine::ColorScheme.new do |cs|
31
+ cs[:headline] = [ :bold, :white, :on_black ]
32
+ cs[:horizontal_line] = [ :bold, :white, :on_blue]
33
+ cs[:even_row] = [ :green ]
34
+ cs[:odd_row] = [ :magenta ]
35
+ cs[:marc_tag] = [:bold]
36
+ cs[:bolder] = [:bold]
37
+ cs[:field_hilite] = [:bold, :blue]
38
+ cs[:index] = [:bold, :red]
39
39
  end
40
- end
41
- end
40
+ HighLine.color_scheme = ft
41
+
42
42
 
43
+ ##Setting up testing parameter
43
44
  $testing = ARGV[0]
44
45
  $testing = nil unless $testing == 'v' or $testing == 't'
45
46
  puts "We're testing " if $testing
@@ -56,110 +57,37 @@ TO_SHOW = yamlfile['to_show']
56
57
  HOW_TO_SAVE = yamlfile['save_filename']
57
58
  TIMESTAMP = Time.now.strftime("%Y%m%d%H%M%S")
58
59
  SCRIPTING = yamlfile['scripting_on']
60
+ EDITING = yamlfile['subfield_editing']
59
61
  CSV = yamlfile['csv_on']
60
62
  LINTER = yamlfile['linter_on']
61
63
  FORMAT_TO_SAVE = yamlfile['save_record_syntax']
64
+ #ZEBRA_ON = yamlfile['zebra']
65
+ #ZEBRA_CONF = yamlfile['zebraconf']
62
66
 
63
-
64
- #class String
65
- # def to_proc
66
- # eval "Proc.new #{self} " # or "Proc.new #{self}" in my case
67
- # end
68
- #end
69
-
70
- def continue?
71
- loop {
72
- print "Enter to search again. q to quit: "
73
- enter_quit = STDIN.gets.chomp
74
- if enter_quit == ''
75
- puts "Again!\n"
76
- return "again"
77
- elsif enter_quit == 'q'
78
- puts "Please! No more!"
79
- exit
80
- end
81
- }
82
- end
83
-
84
- def zoomer (search_term, server, port, database )
85
- puts "\n-------------------------------------\n#{server} #{port} #{database} \n"
86
- conn = ZOOM::Connection.new
87
-
88
- conn.connect(server, port) #do |conn|
89
- conn.set_option('charset', 'UTF-8')
90
- conn.preferred_record_syntax = 'MARC21'
91
- #STDIN.gets
92
- conn.database_name = database
93
- #conn.preferred_record_syntax = 'MARC21'#'USMARC' #was 'XML'
94
- #conn.set_option('charset', 'UTF-8')
95
- full_search = ''
96
- if search_term =~ /\d+[X||\d]/ and !(search_term.match( /[a-wyz]/i ))
97
- puts "Searching for ISBN: #{search_term}"
98
- if server == 'z3950.loc.gov'
99
- full_search = "@attr 1=1007 #{search_term}"
100
- else
101
- full_search = "@attr 1=7 #{search_term}"
102
- end
103
- elsif ( search_term[/[a-z]/i] ) #-- This check for a string could be better!
104
- puts "searching for title:#{search_term}"
105
- search_term = "\'#{search_term}\'"
106
- full_search = "@attr 1=4 \"#{search_term}\""
107
- else
108
- puts "What is this search? Does not compute."
109
- exit
110
- end
111
-
112
- rset = conn.search(full_search)
113
- if ( rset.length == 0)
114
- return nil
115
- end
116
-
117
- rset_recs = rset[0,TO_SHOW]
118
-
119
- #puts rset_recs
120
- #STDIN.gets
121
-
122
- puts "rset.length #{rset.length}"
123
- #puts rset.get_option('charset')
124
- #STDIN.gets
125
- xmlsrecs = ''
126
- #--xmlsrecs = rset.records
127
- rset_recs.each do |rsetrec|
128
- #--puts "moving record into array"
129
- #puts rsetrec.syntax
130
- #puts rsetrec
131
- #STDIN.gets
132
- xmlsrecs += rsetrec.xml('MARC-8', 'UTF-8') #change this to detect character encoding before assuming marc8 to utf8
133
- #puts xmlsrecs
134
- end
135
- #puts xmlsrecs
136
- return records = MARC::XMLReader.new(StringIO.new(string=xmlsrecs))
137
- #end
138
- rescue Exception => except
139
- puts "Error! #{except}"
140
- return nil
141
-
142
-
143
- end
67
+ print $clear_code
68
+ #printed once when starting the program.
69
+ say("Zcc, Copyright (C) 2007 Jason Ronallo\nZcc comes with ABSOLUTELY NO WARRANTY.\nZcc is released under the terms of the GPL v.2 or later.\nSee LICENSE for full information.\n")
70
+ say("Introductory help. For now see: http://zcc.rubyforge.org/zcc.html")
144
71
 
145
72
  #++# All the main logic of the program is just one simple big loop.
146
- puts "Zcc, Copyright (C) 2007 Jason Ronallo\nZcc comes with ABSOLUTELY NO WARRANTY.\nZcc is released under the terms of the GPL v.2 or later. See LICENSE for full information."
73
+ # Copy cataloging forever....
74
+ clear_code_do = false
147
75
  loop {
148
76
  taken = []
149
- print "Enter a title or ISBN to search for: "
150
- search_term = STDIN.gets.chomp
151
-
77
+ print $clear_code if clear_code_do
78
+ clear_code_do = true
79
+ search_term = ask("\n<%= color('Enter search. [ISBN, title, LCCN (with dash), or :q to quit]', :bolder) %>\nsearch> ", String){ |q| q.readline = true }
80
+ exit if search_term == ':q'
152
81
 
153
82
  zservers.each do |zserver|
154
- records = zoomer(search_term, zserver[0], zserver[1], zserver[2])
83
+ records = ZCC.zoomer(search_term, zserver[0], zserver[1], zserver[2])
155
84
  puts "\n"
156
85
 
157
86
  if records.nil?: print "nil records returned"; next; end
158
87
 
159
88
  recs_array = records.to_a
160
89
  taker = []
161
- taker = recs_array.select_good_marc('multi')
162
- #--puts taker.inspect
90
+ taker = recs_array.zcc_select_good_marc('multi')
163
91
  another_zserver = taker.pop if taker[-1] == 'done'
164
92
 
165
93
  next if taker == nil
@@ -174,43 +102,78 @@ loop {
174
102
  taken.compact!
175
103
  puts "taken.length #{taken.length}"
176
104
  if taken.length > 1
177
- puts "\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nWe only need one record per book, so make your choice now!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n"
178
- taken = taken.select_good_marc('one')
179
- next if taken == 'none'
105
+ say("\a<%= color('#{'!' * 10}We only need one record per book, so make your choice now!#{'!' * 10}', :headline) %>")
106
+ sleep 2
107
+ taken = taken.zcc_select_good_marc('one')
108
+ if taken == 'none'
109
+ next
110
+ print $clear_code
111
+ end
180
112
  puts "after selecting final record taken.length = #{taken.length}"
181
113
  puts taken[0]['245'] , "\n\n"
182
114
  elsif taken.length == 0
115
+ print $clear_code
183
116
  print "You didn't get any records!\n"
184
- next if continue? == 'again'
117
+ clear_code_do = false
118
+ next #if continue? == 'again'
185
119
  end
186
120
 
187
121
  final_taken = taken[0]
188
- puts final_taken
189
- final_taken.local_script(scripting) if SCRIPTING
190
-
191
- puts "--------------FINAL RECORD----------------------------"
192
- puts final_taken
193
- puts "--------------FINAL RECORD----------------------------\a"
194
- puts "Above is how your final record looks. Are you happy with it? (anything or n)"
122
+ #puts final_taken
123
+
124
+ #SCRIPTING and EDITING
125
+ if SCRIPTING
126
+ print $clear_code
127
+ print "\a"
128
+ say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}")
129
+ say("<%= color('SCRIPTING...', :headline) %>")
130
+ final_taken.local_script(scripting)
131
+ end
132
+ if EDITING
133
+ print $clear_code
134
+ print "\a"
135
+ say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}")
136
+ say("Would you like to <%= color('edit', :headline) %> this record [yes or ANYTHING]? ")
137
+ edit = STDIN.gets.chomp
138
+ if edit == ('y' or 'yes')
139
+ print $clear_code
140
+ say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}")
141
+ final_taken.edit
142
+ end
143
+ end
144
+
145
+ print $clear_code
146
+ say("<%= color('#{'-'*20}FINAL RECORD#{'-'*20}', :headline) %>")
147
+ say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}")
148
+ say("<%= color('#{'-'*20}FINAL RECORD#{'-'*20}\a', :headline) %>")
149
+ print "Would you like to keep this FINAL RECORD? (ANYTHING or n)"
195
150
 
196
151
  to_save_or_not_to_save = STDIN.gets.chomp
197
152
 
198
153
  if to_save_or_not_to_save == 'n'
199
- next if continue? == 'again'
154
+ next #if continue? == 'again'
200
155
  end
201
156
 
202
- csv = final_taken.marc_to_csv(labels) if CSV
203
-
204
- print "\n#{csv}\n"
157
+ if CSV
158
+ print $clear_code
159
+ print "\a"
160
+ say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}")
161
+ say("<%= color('Label making time!', :headline) %>")
162
+ csv = final_taken.marc_to_csv(labels)
163
+ print "Final csv:\n#{csv}\n"
164
+ end
165
+
166
+ print $clear_code
167
+ clear_code_do = false
205
168
 
169
+
170
+ #saves in the directory in which zcc was run
206
171
  if HOW_TO_SAVE == 'search_term'
207
172
  filename = search_term.gsub(' ','_')
208
173
  elsif HOW_TO_SAVE == 'timestamp'
209
174
  filename = TIMESTAMP
210
175
  end
211
- #puts Dir.getwd
212
- #STDIN.gets
213
- #Dir.chdir("./saved") do
176
+
214
177
  if FORMAT_TO_SAVE == 'marc'
215
178
  aFile = File.new("#{filename}\.mrc","a+")
216
179
  aFile.write(final_taken.to_marc)
@@ -222,6 +185,11 @@ loop {
222
185
  aFile.write(final_taken.to_xml)
223
186
  puts "#{final_taken['245']['a']} saved in #{filename}\.xml"
224
187
  aFile.close
188
+ elsif FORMAT_TO_SAVE == 'zebra'
189
+ #puts final_taken.to_xml
190
+ File.open("#{File.expand_path("~")}/.zcc/zebra/records/#{Time.now.strftime("%Y%m%d%H%M%S")}\.xml", "w") do |f|
191
+ f.write final_taken.to_xml
192
+ end
225
193
  end
226
194
 
227
195
  if CSV
@@ -230,7 +198,5 @@ loop {
230
198
  puts "csv for #{taken[0]['245']['a']} saved in csv-#{filename}\.txt"
231
199
  csvFile.close
232
200
  end
233
- #end
234
-
235
- next if continue? == 'again'
201
+
236
202
  }
File without changes
data/examples/zcc.yaml CHANGED
@@ -17,14 +17,24 @@ save_filename: timestamp
17
17
  #Do you want scripting turned on?
18
18
  scripting_on: yes
19
19
 
20
+ #Do you want subfield editing turned on?
21
+ subfield_editing: yes
22
+
20
23
  #Do you want CSV file creation turned on?
21
24
  csv_on: yes
22
25
 
23
26
  #Do you want to use the optional MARC linter? Perl and the MARC::Lint module are necessary for the functionality to work.
24
27
  linter_on: yes
25
28
 
26
- #How do you want your records saved? Current choices are
27
- save_record_syntax: marc
29
+ #How do you want your records saved? Current choices are [marc, xml, zebra]
30
+ #'marc' means ISO2709, marc transmission format, not human readable
31
+ #'xml' means marcxml right now
32
+ #'zebra' means marcxml saved to the directory of the zebra database by timestamp.
33
+ #See for more information on setting up zebra: http://zcc.rubyforge.org/zebra.html
34
+ save_record_syntax: zebra
35
+
36
+
37
+
28
38
 
29
39
 
30
40
  ###########################
@@ -38,13 +48,16 @@ save_record_syntax: marc
38
48
  ##########################
39
49
  zservers:
40
50
  # server port service
51
+ - [localhost, 9999, zcc] #if you use the zcc zebra server setup
41
52
 
42
53
  # [128.148.19.6, 210, INNOPAC ] #bad server, for testing
43
54
  #-[81.144.245.7, 210, INNOPAC] #wellcome.ac.uk latin1 charset
44
55
  #- [142.51.8.7, 2200, unicorn]
45
56
  - [z3950.loc.gov, 7090, Voyager ] # Library of Congress
46
- # [bobcat.nyu.edu, 210, ADVANCE] #New York University Libraries | 98%
47
- # [128.197.130.200, 210, INNOPAC] #Boston U. | 100%
57
+ - [es33.uits.indiana.edu, 2200, Unicorn] #IU
58
+ #- [webcat.lib.okayama-u.ac.jp, 2210, limedio ] #utf8 records by default
59
+ - [bobcat.nyu.edu, 210, ADVANCE] #New York University Libraries | 98%
60
+ - [128.197.130.200, 210, INNOPAC] #Boston U. | 100%
48
61
 
49
62
 
50
63
  #######################################################
@@ -206,10 +219,9 @@ procs:
206
219
  cutter = STDIN.gets.chomp
207
220
  end
208
221
  cutter.upcase!
209
- puts "|#{cutter}|"
210
- puts cutter.jlength
211
-
212
- cutter
222
+ puts "The final cutter: |#{cutter}|"
223
+ #puts cutter.jlength
224
+ cutter
213
225
 
214
226
 
215
227
  get_cip_callnum: |
@@ -218,7 +230,7 @@ procs:
218
230
  cipcall = STDIN.gets.chomp
219
231
  cipcall
220
232
  else
221
- puts "value is nil"
233
+ puts "Skipping CIP call number."
222
234
  end
223
235
 
224
236
 
@@ -246,7 +258,7 @@ procs:
246
258
  iterator = File.new("#{File.expand_path("~")}/.zcc/zoomer-iterator.txt", "r").gets
247
259
  end
248
260
  #iterator = File.new("test-zoomer-iterator.txt").gets if $testing == 't'
249
- puts iterator
261
+ puts "iterator: #{iterator}"
250
262
  iterator = iterator.chomp
251
263
  barcode = "MRML-%05d" % iterator
252
264
  new_iterator = iterator.to_i + 1