18 require 'zcc/marcadditions'
19 require 'zcc/cli_display'
20 require 'zcc/subfieldeditor'
23 require 'zcc/resultset'
28 require 'highline/import'
33 termsize
= HighLine
::SystemExtensions.terminal_size
34 $term_width = termsize
[0]
35 $term_height = termsize
[1]
36 $clear_code = %x{clear}
39 ft = HighLine::ColorScheme.new do |cs|
40 cs[:headline] = [ :bold, :white, :on_black ]
41 cs[:horizontal_line] = [ :bold, :white, :on_blue]
42 cs[:even_row] = [ :green ]
43 cs[:odd_row] = [ :magenta ]
44 cs[:marc_tag] = [:bold]
46 cs[:field_hilite] = [:bold, :blue]
47 cs[:index] = [:bold, :red]
49 HighLine.color_scheme = ft
52 ##Setting up testing parameter
54 $testing = nil unless $testing == 'v' or $testing == 't'
55 file_mode = true if ARGV[0] == 'file'
56 puts "We're testing " if $testing
57 STDIN.gets if $testing
59 #reading in config from yaml file
60 yamlfile = YAML.load_file( "#{File.expand_path("~")}/.zcc/zcc.yaml" )
61 zservers = yamlfile['zservers']
63 zservers.each do |server|
64 zserver_objects << Zserver.new(server[0], server[1], server[2])
66 puts zserver_objects.inspect
70 labels = yamlfile['labels']
71 scripting = yamlfile['scripting']
72 $procs = yamlfile['procs']
74 TO_SHOW = yamlfile['to_show']
75 HOW_TO_SAVE = yamlfile['save_filename']
76 TIMESTAMP = Time.now.strftime("%Y%m%d%H%M%S")
77 SCRIPTING = yamlfile['scripting_on']
78 EDITING = yamlfile['subfield_editing']
79 CSV = yamlfile['csv_on']
80 LINTER = yamlfile['linter_on']
81 FORMAT_TO_SAVE = yamlfile['save_record_syntax']
82 #ZEBRA_ON = yamlfile['zebra']
83 #ZEBRA_CONF = yamlfile['zebraconf']
86 #printed once when starting the program.
87 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")
88 say("Introductory help. For now see: http://zcc.rubyforge.org/zcc.html")
94 search_term = ask("\n<%= color('Enter search. [ISBN, title, LCCN (with dash), or :q to quit]', :bolder) %>\nsearch> ", String){ |q| q.readline = true }
95 exit if search_term == ':q'
98 query = Query.new(search_term, zserver_objects)
99 results = query.search(25)
101 #print "results.class: "
104 taken = zcc_select_good_marc(results, 'one')
107 final_taken = taken[0]
109 #SCRIPTING and EDITING
113 say("#{ZCC.zcc_marc_str_bold(final_taken.marc.to_s, 'record')}")
114 say("<%= color('SCRIPTING...', :headline) %>")
115 final_taken.marc.local_script(scripting)
120 say("#{ZCC.zcc_marc_str_bold(final_taken.marc.to_s, 'record')}")
121 say("Would you like to <%= color('edit', :headline) %> this record [yes or ANYTHING]? ")
122 edit = STDIN.gets.chomp
123 if edit == ('y' or 'yes')
125 say("#{ZCC.zcc_marc_str_bold(final_taken.marc.to_s, 'record')}")
126 final_taken.marc.edit
131 say("<%= color('#{'-'*20}FINAL RECORD#{'-'*20}', :headline) %>")
132 say("#{ZCC.zcc_marc_str_bold(final_taken.marc.to_s, 'record')}")
133 say("<%= color('#{'-'*20}FINAL RECORD#{'-'*20}\a', :headline) %>")
134 print "Would you like to keep this FINAL RECORD? (ANYTHING or n)"
136 to_save_or_not_to_save = STDIN.gets.chomp
138 if to_save_or_not_to_save == 'n'
139 next #if continue? == 'again'
145 say("#{ZCC.zcc_marc_str_bold(final_taken.marc.to_s, 'record')}")
146 say("<%= color('Label making time!', :headline) %>")
147 csv = final_taken.marc.marc_to_csv(labels)
148 print "Final csv:\n#{csv}\n"
152 clear_code_do = false
155 #saves in the directory in which zcc was run
156 if HOW_TO_SAVE == 'search_term'
157 filename = search_term.gsub(' ','_')
158 elsif HOW_TO_SAVE == 'timestamp'
162 if FORMAT_TO_SAVE == 'marc'
163 aFile = File.new("#{filename}\.mrc","a+")
164 aFile.write(final_taken.marc.to_marc)
165 puts "#{final_taken.marc['245']['a']} saved in #{filename}\.mrc"
167 elsif FORMAT_TO_SAVE == 'marcxml'
168 puts final_taken.marc.to_xml
169 aFile = File.new("#{filename}\.xml","a+")
170 aFile.write(final_taken.marc.to_xml)
171 puts "#{final_taken.marc['245']['a']} saved in #{filename}\.xml"
173 elsif FORMAT_TO_SAVE == 'zebra'
174 #puts final_taken.to_xml
175 File.open("#{File.expand_path("~")}/.zcc/zebra/records/#{Time.now.strftime("%Y%m%d%H%M%S")}\.mrc", "w") do |f|
176 f.write final_taken.marc.to_marc
178 Dir.chdir("#{File.expand_path("~")}/.zcc/zebra") do
179 record_update = `zebraidx update records`
182 aFile = File.new("#{filename}\.mrc","a+")
183 aFile.write(final_taken.marc.to_marc)
184 puts "#{final_taken.marc['245']['a']} saved in #{filename}\.mrc"
189 csvFile = File.new("csv-#{filename}\.txt","a+")
191 puts "csv for #{final_taken.marc['245']['a']} saved in csv-#{filename}\.txt"