9 require 'highline/import'
10 require 'term/ansicolor'
11 #include Term::ANSIColor
24 termsize
= HighLine
::SystemExtensions.terminal_size
25 $term_width = termsize
[0]
26 $term_height = termsize
[1]
27 $clear_code = %x{clear}
28 HighLine.track_eof = false
30 ##Setting up testing parameter
32 $testing = nil unless $testing == 'v' or $testing == 't'
33 file_mode = true if ARGV[0] == 'file'
34 puts "We're testing " if $testing
35 STDIN.gets if $testing
37 #reading in config from yaml file
38 yamlfile = YAML.load_file( "#{File.expand_path("~")}/.zcc/zcc.yaml" )
39 zservers = yamlfile['zservers']
42 #puts zservers[0][0].class
44 #puts zservers[0][0] =~ /Include/
46 if zservers[0][0] =~ /Include/
48 filename = zservers[0][0][8, 99]
49 contents = YAML.load_file("#{File.expand_path("~")}/.zcc/#{filename}")
52 contents.each{|c| zservers.push(c)}
55 #puts zservers.inspect
60 labels = yamlfile['labels']
61 scripting = yamlfile['scripting']
62 $procs = yamlfile['procs']
64 TO_SHOW = yamlfile['to_show']
65 HOW_TO_SAVE = yamlfile['save_filename']
66 TIMESTAMP = Time.now.strftime("%Y%m%d%H%M%S")
67 SCRIPTING = yamlfile['scripting_on']
68 EDITING = yamlfile['subfield_editing']
69 CSV = yamlfile['csv_on']
70 LINTER = yamlfile['linter_on']
71 FORMAT_TO_SAVE = yamlfile['save_record_syntax']
74 #printed once when starting the program.
75 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".bold)
76 say("Introductory help. For now see: http://zcc.rubyforge.org/zcc.html")
79 zservers.each do |server|
80 zserver_objects << Zserver.new(server[0], server[1], server[2], server[3])
83 server_h = Hash.new {|hash, key| hash[key] = [] }
84 zserver_objects.each {|z| server_h[z.group] << z}
87 server_h.each_key{|k| groups << k}
92 search_term = ask("\nEnter search. [ISBN, title, LCCN (with dash), or :q to quit]\nsearch> ".boldz, String){ |q| q.readline = true }
93 exit if search_term == ':q'
96 groups.each do |group|
99 servers = server_h[group] #zserver_objects.find_all{|server| server.group == group }
100 #puts "searching the following servers: #{servers.join("...\n")}"
102 query = Query.new(search_term, servers)
103 results = query.search(TO_SHOW)
104 #print "results.class" ; puts results.class
105 if results.records.empty?
106 puts "There are no results from group #{group} servers!\n\n\n"
107 another_group = ask("Do you want to continue searcing the next group of servers? [y], anything ".boldz)
108 if another_group == 'y' || another_group == ''
115 return_value = zcc_select_good_marc(results, 'multi')
117 break if return_value == 'done'
121 taken.remove_unselected!
125 say("\aThis is your combined result set.\nWe will winnow until you choose ".white.bold.on_black + "'done'".red.bold + "\nor you unselect all records.".white.bold.on_black)
128 return_value = zcc_select_good_marc(taken, 'multi')
129 #taken.remove_unselected!
130 #continue = false if taken.length == 0
131 continue = false if taken.selected_length == 0
132 continue = false if return_value == 'done'
134 taken.remove_unselected!
135 unless taken.length == 0
136 puts "Here are the records you've selected for processing:"
137 taken.each do |record|
143 taken.records.each do |final_taken|
145 #SCRIPTING and EDITING
149 say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}")
150 say("SCRIPTING...".bold.white.on_black)
151 final_taken.local_script(scripting)
157 say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}")
158 edit = ask("Would you like to " + "edit".headline + " this record [yes or ANYTHING]? ")
159 if edit == ('y' or 'yes')
161 say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}")
167 say("#{'-'*20}FINAL RECORD#{'-'*20}".headline)
168 say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}")
169 say("#{'-'*20}FINAL RECORD#{'-'*20}".headline)
170 to_save_or_not_to_save = ask("Would you like to keep this FINAL RECORD? (ANYTHING or n)")
172 if to_save_or_not_to_save == 'n'
173 next #if continue? == 'again'
179 say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}")
180 say("Label making time!".headline)
181 csv = final_taken.marc_to_csv(labels)
182 print "Final csv:\n#{csv}\n"
186 clear_code_do = false
189 #saves in the directory in which zcc was run
190 if HOW_TO_SAVE == 'search_term'
191 filename = search_term.gsub(' ','_')
192 elsif HOW_TO_SAVE == 'timestamp'
196 FORMAT_TO_SAVE.each do |format|
199 aFile = File.new("#{filename}\.mrc","a+")
200 aFile.write(final_taken.marc.to_marc)
201 puts "#{final_taken.marc['245']['a']} saved in #{filename}\.mrc"
204 elsif format == 'xml'
205 #puts final_taken.marc.to_xml
206 aFile = File.new("#{filename}\.xml","a+")
207 aFile.write(final_taken.marc.to_xml)
208 puts "#{final_taken.marc['245']['a']} saved in #{filename}\.xml"
210 elsif format == 'zebra'
211 #puts final_taken.to_xml
212 File.open("#{File.expand_path("~")}/.zcc/zebra/records/#{Time.now.strftime("%Y%m%d%H%M%S")}\.mrc", "w") do |f|
213 f.write final_taken.marc.to_marc
215 Dir.chdir("#{File.expand_path("~")}/.zcc/zebra") do
216 record_update = `zebraidx update records`
219 #saving to koha2 is untested. Please let me know if it doesn't work--or even if it does.
220 elsif format == 'koha2'
222 out = Tempfile.new("koha2-")
223 out << final_taken.marc.to_marc
225 koha_save = `perl /usr/local/koha/intranet/scripts/misc/migration_tools/bulkmarcimport.pl -v 6 -file #{out.path}`
233 csvFile = File.new("csv-#{filename}\.txt","a+")
235 puts "csv for #{final_taken.marc['245']['a']} saved in csv-#{filename}\.txt"