alexandria-book-collection-manager 0.7.1 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +9 -0
- data/.gitignore +5 -2
- data/.hound.yml +2 -0
- data/.rubocop.yml +113 -45
- data/.rubocop_todo.yml +82 -170
- data/.simplecov +5 -1
- data/.travis.yml +45 -0
- data/.yardopts +1 -1
- data/CHANGELOG.md +60 -0
- data/ChangeLog.0 +33 -35
- data/Gemfile +6 -5
- data/INSTALL.md +164 -0
- data/README.md +52 -42
- data/Rakefile +95 -109
- data/TODO.md +9 -1
- data/alexandria-book-collection-manager.gemspec +52 -45
- data/bin/alexandria +31 -53
- data/doc/AUTHORS +61 -0
- data/doc/BUGS +31 -0
- data/doc/FAQ +365 -0
- data/doc/HACKING +19 -0
- data/doc/NEWS +341 -0
- data/doc/alexandria.1 +120 -0
- data/doc/cuecat_support.rdoc +67 -0
- data/doc/dependency_decisions.yml +80 -0
- data/lib/alexandria.rb +29 -37
- data/lib/alexandria/about.rb +52 -51
- data/lib/alexandria/book_providers.rb +94 -101
- data/lib/alexandria/book_providers/adlibris.rb +45 -85
- data/lib/alexandria/book_providers/amazon_aws.rb +105 -113
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +293 -324
- data/lib/alexandria/book_providers/barnes_and_noble.rb +54 -53
- data/lib/alexandria/book_providers/douban.rb +29 -51
- data/lib/alexandria/book_providers/proxis.rb +42 -59
- data/lib/alexandria/book_providers/pseudomarc.rb +79 -99
- data/lib/alexandria/book_providers/siciliano.rb +68 -70
- data/lib/alexandria/book_providers/thalia.rb +46 -45
- data/lib/alexandria/book_providers/web.rb +17 -33
- data/lib/alexandria/book_providers/worldcat.rb +74 -102
- data/lib/alexandria/book_providers/z3950.rb +170 -174
- data/lib/alexandria/config.rb +5 -3
- data/lib/alexandria/console.rb +10 -21
- data/lib/alexandria/default_preferences.rb +37 -0
- data/lib/alexandria/execution_queue.rb +17 -15
- data/lib/alexandria/export_format.rb +47 -0
- data/lib/alexandria/export_library.rb +188 -302
- data/lib/alexandria/import_library.rb +114 -155
- data/lib/alexandria/import_library_csv.rb +46 -96
- data/lib/alexandria/library_collection.rb +79 -0
- data/lib/alexandria/library_sort_order.rb +45 -0
- data/lib/alexandria/library_store.rb +233 -0
- data/lib/alexandria/logging.rb +15 -19
- data/lib/alexandria/models/book.rb +15 -20
- data/lib/alexandria/models/library.rb +81 -363
- data/lib/alexandria/net.rb +7 -6
- data/lib/alexandria/preferences.rb +73 -91
- data/lib/alexandria/scanners.rb +4 -2
- data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +24 -20
- data/lib/alexandria/scanners/keyboard.rb +10 -8
- data/lib/alexandria/smart_library.rb +135 -171
- data/lib/alexandria/ui.rb +17 -15
- data/lib/alexandria/ui/about_dialog.rb +49 -0
- data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +129 -152
- data/lib/alexandria/ui/alert_dialog.rb +64 -0
- data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
- data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +18 -15
- data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +44 -61
- data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +84 -89
- data/lib/alexandria/ui/builder_base.rb +9 -27
- data/lib/alexandria/ui/callbacks.rb +188 -186
- data/lib/alexandria/ui/columns.rb +2 -0
- data/lib/alexandria/ui/completion_models.rb +12 -23
- data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
- data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
- data/lib/alexandria/ui/dndable.rb +10 -8
- data/lib/alexandria/ui/error_dialog.rb +25 -0
- data/lib/alexandria/ui/export_dialog.rb +139 -0
- data/lib/alexandria/ui/icons.rb +49 -65
- data/lib/alexandria/ui/iconview.rb +15 -13
- data/lib/alexandria/ui/iconview_tooltips.rb +43 -58
- data/lib/alexandria/ui/import_dialog.rb +157 -0
- data/lib/alexandria/ui/init.rb +23 -33
- data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
- data/lib/alexandria/ui/libraries_combo.rb +18 -14
- data/lib/alexandria/ui/listview.rb +77 -88
- data/lib/alexandria/ui/main_app.rb +26 -26
- data/lib/alexandria/ui/misc_dialogs.rb +10 -0
- data/lib/alexandria/ui/multi_drag_treeview.rb +30 -41
- data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +168 -215
- data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
- data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
- data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
- data/lib/alexandria/ui/preferences_dialog.rb +313 -0
- data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
- data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
- data/lib/alexandria/ui/really_delete_dialog.rb +53 -0
- data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +62 -72
- data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
- data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
- data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog_base.rb → smart_library_properties_dialog_base.rb} +96 -172
- data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
- data/lib/alexandria/ui/sound.rb +13 -13
- data/lib/alexandria/ui/ui_manager.rb +262 -283
- data/lib/alexandria/undo_manager.rb +3 -0
- data/lib/alexandria/version.rb +6 -19
- data/lib/alexandria/web_themes.rb +24 -21
- data/po/Makefile +2 -2
- data/po/cs.po +993 -880
- data/po/cy.po +957 -874
- data/po/de.po +990 -869
- data/po/el.po +989 -869
- data/po/es.po +985 -865
- data/po/fr.po +986 -870
- data/po/ga.po +907 -823
- data/po/gl.po +981 -865
- data/po/it.po +986 -868
- data/po/ja.po +969 -853
- data/po/mk.po +983 -863
- data/po/nb.po +979 -863
- data/po/nl.po +983 -864
- data/po/pl.po +1020 -969
- data/po/pt.po +988 -861
- data/po/pt_BR.po +984 -868
- data/po/ru.po +992 -873
- data/po/sk.po +987 -869
- data/po/sv.po +977 -861
- data/po/uk.po +975 -865
- data/po/zh_TW.po +976 -860
- data/schemas/alexandria.schemas +25 -3
- data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
- data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
- data/share/alexandria/glade/main_app__builder.glade +24 -33
- data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
- data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
- data/share/gnome/help/alexandria/C/introduction.xml +0 -8
- data/share/gnome/help/alexandria/C/searching.xml +1 -1
- data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
- data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
- data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
- data/share/gnome/help/alexandria/ja/introduction.xml +0 -8
- data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
- data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
- data/spec/alexandria/book_providers_spec.rb +77 -210
- data/spec/alexandria/book_spec.rb +16 -12
- data/spec/alexandria/console_spec.rb +27 -0
- data/spec/alexandria/export_library_spec.rb +130 -0
- data/spec/alexandria/library_spec.rb +130 -172
- data/spec/alexandria/library_store_spec.rb +37 -0
- data/spec/alexandria/preferences_spec.rb +46 -17
- data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
- data/spec/alexandria/smart_library_spec.rb +32 -25
- data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
- data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/export_dialog_spec.rb +15 -0
- data/spec/alexandria/ui/icons_spec.rb +26 -0
- data/spec/alexandria/ui/iconview_spec.rb +9 -21
- data/spec/alexandria/ui/import_dialog_spec.rb +41 -0
- data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
- data/spec/alexandria/ui/main_app_spec.rb +8 -33
- data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
- data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
- data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
- data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
- data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
- data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
- data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +32 -0
- data/spec/alexandria/ui/sound_spec.rb +4 -2
- data/spec/alexandria/ui/ui_manager_spec.rb +45 -20
- data/spec/end_to_end/basic_run_spec.rb +57 -0
- data/spec/spec_helper.rb +66 -33
- data/tasks/setup.rb +5 -3
- data/tasks/spec.rake +18 -3
- data/util/rake/fileinstall.rb +38 -40
- data/util/rake/gettextgenerate.rb +15 -70
- data/util/rake/omfgenerate.rb +10 -10
- metadata +176 -60
- data/INSTALL.rdoc +0 -148
- data/dogtail/basic_run_test.py +0 -9
- data/lib/alexandria/book_providers/bol_it.rb +0 -160
- data/lib/alexandria/book_providers/deastore.rb +0 -273
- data/lib/alexandria/book_providers/ibs_it.rb +0 -147
- data/lib/alexandria/book_providers/mcu.rb +0 -169
- data/lib/alexandria/book_providers/renaud.rb +0 -140
- data/lib/alexandria/book_providers/webster_it.rb +0 -167
- data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -59
- data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -70
- data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -43
- data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
- data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
- data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -85
- data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
- data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
- data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -578
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -57
- data/spec/alexandria/scanners/cuecat_spec.rb +0 -65
- data/spec/alexandria/ui/dialogs_spec.rb +0 -94
- data/spec/alexandria/ui/sidepane_spec.rb +0 -27
- data/spec/alexandria/ui/ui_utilities_spec.rb +0 -60
- data/spec/alexandria/utilities_spec.rb +0 -50
- data/tasks/dogtail.rake +0 -4
@@ -1,66 +1,51 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# Alexandria is free software; you can redistribute it and/or
|
6
|
-
# modify it under the terms of the GNU General Public License as
|
7
|
-
# published by the Free Software Foundation; either version 2 of the
|
8
|
-
# License, or (at your option) any later version.
|
9
|
-
#
|
10
|
-
# Alexandria is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
# General Public License for more details.
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file is part of Alexandria.
|
14
4
|
#
|
15
|
-
#
|
16
|
-
# License along with Alexandria; see the file COPYING. If not,
|
17
|
-
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
18
|
-
# Fifth Floor, Boston, MA 02110-1301 USA.
|
5
|
+
# See the file README.md for authorship and licensing information.
|
19
6
|
|
20
7
|
## $Z3950_DEBUG = $DEBUG
|
21
8
|
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
9
|
+
require "zoom"
|
10
|
+
require "alexandria/book_providers/pseudomarc"
|
11
|
+
require "marc"
|
25
12
|
|
26
13
|
module Alexandria
|
27
14
|
class BookProviders
|
28
15
|
class Z3950Provider < AbstractProvider
|
29
16
|
include Logging
|
30
17
|
include GetText
|
31
|
-
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset:
|
18
|
+
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
|
32
19
|
|
33
|
-
def initialize(name =
|
20
|
+
def initialize(name = "Z3950", fullname = "Z39.50")
|
34
21
|
super
|
35
|
-
prefs.add(
|
36
|
-
prefs.add(
|
37
|
-
prefs.add(
|
38
|
-
prefs.add(
|
39
|
-
|
40
|
-
prefs.add(
|
41
|
-
prefs.add(
|
22
|
+
prefs.add("hostname", _("Hostname"), "")
|
23
|
+
prefs.add("port", _("Port"), 7090)
|
24
|
+
prefs.add("database", _("Database"), "")
|
25
|
+
prefs.add("record_syntax", _("Record syntax"), "USMARC",
|
26
|
+
["USMARC", "UNIMARC", "SUTRS"])
|
27
|
+
prefs.add("username", _("Username"), "", nil, false)
|
28
|
+
prefs.add("password", _("Password"), "", nil, false)
|
29
|
+
prefs.add("charset", _("Charset encoding"), "ISO-8859-1")
|
42
30
|
|
43
31
|
# HACK : piggybacking support
|
44
|
-
prefs.add(
|
32
|
+
prefs.add("piggyback", "Piggyback", true, [true, false])
|
45
33
|
prefs.read
|
46
34
|
end
|
47
35
|
|
48
36
|
def search(criterion, type)
|
49
37
|
prefs.read
|
50
|
-
criterion = criterion.encode(prefs[
|
51
|
-
|
52
|
-
# We only decode MARC at the moment.
|
53
|
-
# SUTRS needs to be decoded separately, because each Z39.50 server has a
|
54
|
-
# different one.
|
55
|
-
raise NoResultsError unless marc?
|
38
|
+
criterion = criterion.encode(prefs["charset"])
|
56
39
|
|
57
40
|
isbn = type == SEARCH_BY_ISBN ? criterion : nil
|
58
|
-
criterion =
|
59
|
-
conn_count = type
|
41
|
+
criterion = canonicalise_criterion(criterion, type)
|
42
|
+
conn_count = request_count(type)
|
60
43
|
resultset = search_records(criterion, type, conn_count)
|
61
44
|
log.debug { "total #{resultset.length}" }
|
62
|
-
|
63
|
-
results =
|
45
|
+
|
46
|
+
results = books_from_resultset(resultset, isbn)
|
47
|
+
raise NoResultsError if results.empty?
|
48
|
+
|
64
49
|
type == SEARCH_BY_ISBN ? results.first : results
|
65
50
|
end
|
66
51
|
|
@@ -68,25 +53,51 @@ module Alexandria
|
|
68
53
|
nil
|
69
54
|
end
|
70
55
|
|
56
|
+
def books_from_resultset(resultset, isbn)
|
57
|
+
case prefs["record_syntax"]
|
58
|
+
when /MARC$/
|
59
|
+
books_from_marc(resultset, isbn)
|
60
|
+
when "SUTRS"
|
61
|
+
books_from_sutrs(resultset)
|
62
|
+
else
|
63
|
+
raise NoResultsError
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
71
67
|
private
|
72
68
|
|
73
|
-
def
|
69
|
+
def request_count(type)
|
70
|
+
type == SEARCH_BY_ISBN ? 1 : 10 # results to retrieve
|
71
|
+
end
|
72
|
+
|
73
|
+
def canonicalise_criterion(criterion, type)
|
74
|
+
criterion = Library.canonicalise_isbn(criterion) if type == SEARCH_BY_ISBN
|
75
|
+
criterion
|
76
|
+
end
|
77
|
+
|
78
|
+
def books_from_sutrs(_resultset)
|
79
|
+
# SUTRS needs to be decoded separately, because each Z39.50 server has a
|
80
|
+
# different one.
|
81
|
+
raise NoResultsError
|
82
|
+
end
|
83
|
+
|
84
|
+
def marc_to_book(marc_txt, isbn)
|
74
85
|
begin
|
75
86
|
marc = MARC::Record.new_from_marc(marc_txt, forgiving: true)
|
76
|
-
rescue => ex
|
87
|
+
rescue StandardError => ex
|
77
88
|
log.error { ex.message }
|
78
89
|
log.error { ex.backtrace.join("> \n") }
|
79
90
|
begin
|
80
91
|
marc = MARC::Record.new(marc_txt)
|
81
|
-
rescue =>
|
82
|
-
log.error {
|
83
|
-
log.error {
|
84
|
-
raise
|
92
|
+
rescue StandardError => ex
|
93
|
+
log.error { ex.message }
|
94
|
+
log.error { ex.backtrace.join("> \n") }
|
95
|
+
raise ex
|
85
96
|
end
|
86
97
|
end
|
87
98
|
|
88
|
-
log.debug
|
89
|
-
msg =
|
99
|
+
log.debug do
|
100
|
+
msg = "Parsing MARC"
|
90
101
|
msg += "\n title: #{marc.title}"
|
91
102
|
msg += "\n authors: #{marc.authors.join(', ')}"
|
92
103
|
msg += "\n isbn: #{marc.isbn}, #{isbn}"
|
@@ -94,35 +105,34 @@ module Alexandria
|
|
94
105
|
msg += "\n publish year: #{marc.publish_year}" if marc.respond_to?(:publish_year)
|
95
106
|
msg += "\n edition: #{marc.edition}"
|
96
107
|
msg
|
97
|
-
|
108
|
+
end
|
98
109
|
|
99
110
|
return if marc.title.nil? # or marc.authors.empty?
|
100
111
|
|
101
|
-
|
112
|
+
isbn ||= marc.isbn
|
102
113
|
isbn = Library.canonicalise_ean(isbn)
|
103
114
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
book
|
115
|
+
Book.new(marc.title, marc.authors,
|
116
|
+
isbn,
|
117
|
+
(marc.publisher || ""),
|
118
|
+
marc.respond_to?(:publish_year) ? marc.publish_year.to_i : nil,
|
119
|
+
(marc.edition || ""))
|
110
120
|
end
|
111
121
|
|
112
|
-
def books_from_marc(resultset,
|
122
|
+
def books_from_marc(resultset, isbn)
|
113
123
|
results = []
|
114
124
|
resultset[0..9].each do |record|
|
115
|
-
marc_txt = record.render(prefs[
|
125
|
+
marc_txt = record.render(prefs["charset"], "UTF-8")
|
116
126
|
log.debug { marc_txt }
|
117
127
|
if $DEBUG
|
118
|
-
File.open(
|
128
|
+
File.open(",marc.txt", "wb") do |f| # DEBUG
|
119
129
|
f.write(marc_txt)
|
120
130
|
end
|
121
131
|
end
|
122
132
|
book = nil
|
123
133
|
begin
|
124
134
|
mappings = Alexandria::PseudoMarcParser::USMARC_MAPPINGS
|
125
|
-
if prefs[
|
135
|
+
if prefs["hostname"] == "z3950.bnf.fr"
|
126
136
|
mappings = Alexandria::PseudoMarcParser::BNF_FR_MAPPINGS
|
127
137
|
end
|
128
138
|
# try pseudo-marc parser first (it seems to have more luck)
|
@@ -130,9 +140,9 @@ module Alexandria
|
|
130
140
|
mappings)
|
131
141
|
if book.nil?
|
132
142
|
# failing that, try the genuine MARC parser
|
133
|
-
book = marc_to_book(marc_txt)
|
143
|
+
book = marc_to_book(marc_txt, isbn)
|
134
144
|
end
|
135
|
-
rescue => ex
|
145
|
+
rescue StandardError => ex
|
136
146
|
log.warn { ex }
|
137
147
|
log.warn { ex.backtrace }
|
138
148
|
end
|
@@ -143,26 +153,23 @@ module Alexandria
|
|
143
153
|
end
|
144
154
|
|
145
155
|
def marc?
|
146
|
-
|
156
|
+
prefs["record_syntax"].end_with?("MARC")
|
147
157
|
end
|
148
158
|
|
149
159
|
def search_records(criterion, type, conn_count)
|
150
160
|
options = {}
|
151
|
-
unless prefs[
|
152
|
-
options[
|
153
|
-
options[
|
161
|
+
unless prefs["username"].empty? || prefs["password"].empty?
|
162
|
+
options["user"] = prefs["username"]
|
163
|
+
options["password"] = prefs["password"]
|
154
164
|
end
|
155
|
-
hostname = prefs[
|
156
|
-
port = prefs[
|
165
|
+
hostname = prefs["hostname"]
|
166
|
+
port = prefs["port"].to_i
|
157
167
|
log.debug { "hostname #{hostname} port #{port} options #{options}" }
|
158
168
|
conn = ZOOM::Connection.new(options).connect(hostname, port)
|
159
|
-
conn.database_name = prefs[
|
169
|
+
conn.database_name = prefs["database"]
|
160
170
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
conn.preferred_record_syntax = prefs['record_syntax']
|
165
|
-
conn.element_set_name = 'F'
|
171
|
+
conn.preferred_record_syntax = prefs["record_syntax"]
|
172
|
+
conn.element_set_name = "F"
|
166
173
|
conn.count = conn_count
|
167
174
|
attr = case type
|
168
175
|
when SEARCH_BY_ISBN then [7]
|
@@ -170,33 +177,27 @@ module Alexandria
|
|
170
177
|
when SEARCH_BY_AUTHORS then [1, 1003]
|
171
178
|
when SEARCH_BY_KEYWORD then [1016]
|
172
179
|
end
|
173
|
-
pqf =
|
180
|
+
pqf = ""
|
174
181
|
attr.each { |att| pqf += "@attr 1=#{att} " }
|
175
182
|
pqf += '"' + criterion.upcase + '"'
|
176
183
|
log.debug { "pqf is #{pqf}, syntax #{prefs['record_syntax']}" }
|
177
184
|
|
178
185
|
begin
|
179
|
-
if prefs.variable_named(
|
180
|
-
|
181
|
-
|
182
|
-
conn.piggyback = false
|
183
|
-
end
|
186
|
+
if prefs.variable_named("piggyback") && !prefs["piggyback"]
|
187
|
+
log.debug { "setting conn.piggyback to false" }
|
188
|
+
conn.piggyback = false
|
184
189
|
end
|
185
190
|
conn.search(pqf)
|
186
|
-
rescue => ex
|
187
|
-
if /1005
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
# hopefully these precautions will prevent infinite loops here
|
194
|
-
else
|
195
|
-
raise ex
|
196
|
-
end
|
197
|
-
else
|
198
|
-
raise ex
|
191
|
+
rescue StandardError => ex
|
192
|
+
if /1005/.match?(ex.message) &&
|
193
|
+
prefs.variable_named("piggyback") && prefs["piggyback"]
|
194
|
+
log.error { "Z39.50 search failed:: #{ex.message}" }
|
195
|
+
log.info { "Turning off piggybacking for this provider" }
|
196
|
+
prefs.variable_named("piggyback").new_value = false
|
197
|
+
retry
|
199
198
|
end
|
199
|
+
|
200
|
+
raise ex
|
200
201
|
end
|
201
202
|
end
|
202
203
|
end
|
@@ -206,21 +207,23 @@ module Alexandria
|
|
206
207
|
unabstract
|
207
208
|
|
208
209
|
include GetText
|
209
|
-
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset:
|
210
|
+
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
|
210
211
|
|
211
212
|
def initialize
|
212
|
-
super(
|
213
|
-
prefs.variable_named(
|
214
|
-
prefs.variable_named(
|
215
|
-
prefs.variable_named(
|
216
|
-
prefs.variable_named(
|
217
|
-
prefs.variable_named(
|
213
|
+
super("LOC", _("Library of Congress (Usa)"))
|
214
|
+
prefs.variable_named("hostname").default_value = "z3950.loc.gov"
|
215
|
+
prefs.variable_named("port").default_value = 7090
|
216
|
+
prefs.variable_named("database").default_value = "Voyager"
|
217
|
+
prefs.variable_named("record_syntax").default_value = "USMARC"
|
218
|
+
prefs.variable_named("charset").default_value = "ISO-8859-1"
|
218
219
|
prefs.read
|
219
220
|
end
|
220
221
|
|
221
222
|
def url(book)
|
222
|
-
|
223
|
-
|
223
|
+
isbn = Library.canonicalise_isbn(book.isbn)
|
224
|
+
"http://catalog.loc.gov/cgi-bin/Pwebrecon.cgi?" \
|
225
|
+
"DB=local&CNT=25+records+per+page&CMD=isbn+#{isbn}"
|
226
|
+
rescue StandardError => ex
|
224
227
|
log.warn { "Cannot create url for book #{book}; #{ex.message}" }
|
225
228
|
nil
|
226
229
|
end
|
@@ -231,40 +234,30 @@ module Alexandria
|
|
231
234
|
# http://en.wikipedia.org/wiki/British_Library
|
232
235
|
# http://www.bl.uk/catalogues/z3950fullaccess.html
|
233
236
|
# http://www.bl.uk/catalogues/z3950copacaccess.html
|
234
|
-
#
|
237
|
+
#
|
238
|
+
# FIXME: switch from BL to Copac, which incudes the BL itself and many more
|
239
|
+
# libraries: http://copac.ac.uk/libraries/
|
240
|
+
#
|
235
241
|
# Details: http://copac.ac.uk/interfaces/z39.50/
|
236
242
|
# The SUTRS format used by Copac is different from the one used by BL
|
237
243
|
unabstract
|
238
244
|
|
239
245
|
include GetText
|
240
|
-
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset:
|
246
|
+
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
|
241
247
|
|
242
248
|
def initialize
|
243
|
-
super(
|
244
|
-
prefs.variable_named(
|
245
|
-
prefs.variable_named(
|
246
|
-
prefs.variable_named(
|
247
|
-
prefs.variable_named(
|
248
|
-
prefs.variable_named(
|
249
|
-
prefs.read
|
250
|
-
end
|
251
|
-
|
252
|
-
def search(criterion, type)
|
253
|
-
return super unless prefs['record_syntax'] == 'SUTRS'
|
254
|
-
|
249
|
+
super("BL", _("British Library"))
|
250
|
+
prefs.variable_named("hostname").default_value = "z3950cat.bl.uk"
|
251
|
+
prefs.variable_named("port").default_value = 9909
|
252
|
+
prefs.variable_named("database").default_value = "BLAC"
|
253
|
+
prefs.variable_named("record_syntax").default_value = "SUTRS"
|
254
|
+
prefs.variable_named("charset").default_value = "ISO-8859-1"
|
255
255
|
prefs.read
|
256
|
-
criterion = Library.canonicalise_isbn(criterion) if type == SEARCH_BY_ISBN
|
257
|
-
conn_count = type == SEARCH_BY_ISBN ? 1 : 10 # results to retrieve
|
258
|
-
resultset = search_records(criterion, type, conn_count)
|
259
|
-
log.debug { "total #{resultset.length}" }
|
260
|
-
raise NoResultsError if resultset.length == 0
|
261
|
-
results = books_from_sutrs(resultset)
|
262
|
-
type == SEARCH_BY_ISBN ? results.first : results
|
263
256
|
end
|
264
257
|
|
265
258
|
def url(book)
|
266
|
-
|
267
|
-
rescue => ex
|
259
|
+
"http://copac.ac.uk/openurl?isbn=" + Library.canonicalise_isbn(book.isbn)
|
260
|
+
rescue StandardError => ex
|
268
261
|
log.warn { "Cannot create url for book #{book}; #{ex.message}" }
|
269
262
|
nil
|
270
263
|
end
|
@@ -274,7 +267,7 @@ module Alexandria
|
|
274
267
|
def books_from_sutrs(resultset)
|
275
268
|
results = []
|
276
269
|
resultset[0..9].each do |record|
|
277
|
-
text = record.render(prefs[
|
270
|
+
text = record.render(prefs["charset"], "UTF-8")
|
278
271
|
# File.open(',bl.marc', 'wb') {|f| f.write(text) }
|
279
272
|
log.debug { text }
|
280
273
|
|
@@ -283,30 +276,31 @@ module Alexandria
|
|
283
276
|
|
284
277
|
text.split(/\n/).each do |line|
|
285
278
|
if (md = /^Title:\s+(.*)$/.match(line))
|
286
|
-
title = md[1].sub(/\.$/,
|
279
|
+
title = md[1].sub(/\.$/, "").squeeze(" ")
|
287
280
|
elsif (md = /^Added Person Name:\s+(.*),[^,]+$/.match(line))
|
288
281
|
authors << md[1]
|
289
282
|
elsif (md = /^ME-Personal Name:\s+(.*),[^,]+$/.match(line))
|
290
283
|
authors << md[1]
|
291
284
|
elsif (md = /^ISBN:\s+([\dXx]+)/.match(line))
|
292
285
|
isbn = Library.canonicalise_ean(md[1])
|
293
|
-
elsif (md = /^Imprint
|
286
|
+
elsif (md = /^Imprint:.+:\s*(.+),/.match(line))
|
294
287
|
publisher = md[1]
|
295
288
|
end
|
296
289
|
end
|
297
290
|
|
298
|
-
log.debug
|
299
|
-
msg =
|
291
|
+
log.debug do
|
292
|
+
msg = "Parsing SUTRS"
|
300
293
|
msg += "\n title: #{title}"
|
301
294
|
msg += "\n authors: #{authors.join(' and ')}"
|
302
295
|
msg += "\n isbn: #{isbn}"
|
303
296
|
msg += "\n publisher: #{publisher}"
|
304
297
|
msg += "\n edition: #{edition}"
|
305
298
|
msg
|
306
|
-
|
299
|
+
end
|
307
300
|
|
308
301
|
if title # and !authors.empty?
|
309
|
-
book = Book.new(title, authors, isbn, (publisher || nil),
|
302
|
+
book = Book.new(title, authors, isbn, (publisher || nil),
|
303
|
+
(publish_year || nil), (edition || nil))
|
310
304
|
results << [book]
|
311
305
|
end
|
312
306
|
end
|
@@ -320,83 +314,85 @@ module Alexandria
|
|
320
314
|
unabstract
|
321
315
|
|
322
316
|
include GetText
|
323
|
-
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset:
|
317
|
+
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
|
324
318
|
|
325
319
|
def initialize
|
326
|
-
super(
|
327
|
-
prefs.variable_named(
|
328
|
-
prefs.variable_named(
|
329
|
-
prefs.variable_named(
|
320
|
+
super("SBN", "Servizio Bibliotecario Nazionale (Italy)")
|
321
|
+
prefs.variable_named("hostname").default_value = "opac.sbn.it"
|
322
|
+
prefs.variable_named("port").default_value = 3950
|
323
|
+
prefs.variable_named("database").default_value = "nopac"
|
330
324
|
# supported 'USMARC', 'UNIMARC' , 'SUTRS'
|
331
|
-
prefs.variable_named(
|
332
|
-
prefs.variable_named(
|
325
|
+
prefs.variable_named("record_syntax").default_value = "USMARC"
|
326
|
+
prefs.variable_named("charset").default_value = "ISO-8859-1"
|
333
327
|
prefs.read
|
334
328
|
end
|
335
329
|
|
336
|
-
def search(criterion, type)
|
337
|
-
prefs.read
|
338
|
-
|
339
|
-
isbn = type == SEARCH_BY_ISBN ? criterion : nil
|
340
|
-
criterion = canonicalise_isbn_with_dashes(criterion)
|
341
|
-
resultset = search_records(criterion, type, 0)
|
342
|
-
log.debug { "total #{resultset.length}" }
|
343
|
-
raise NoResultsError if resultset.length == 0
|
344
|
-
results = books_from_marc(resultset, isbn)
|
345
|
-
type == SEARCH_BY_ISBN ? results.first : results
|
346
|
-
end
|
347
|
-
|
348
330
|
def url(book)
|
349
|
-
|
350
|
-
|
331
|
+
"http://sbnonline.sbn.it/cgi-bin/zgw/BRIEF.pl?displayquery=" \
|
332
|
+
"%253CB%253E%253Cfont%2520color%253D%2523000064%253E" \
|
333
|
+
"Codice%2520ISBN%253C%2FB%253E%253C%2Ffont%253E%2520" \
|
334
|
+
"contiene%2520%2522%2520%253CFONT%2520COLOR%253Dred%253E" +
|
351
335
|
canonicalise_isbn_with_dashes(book.isbn) +
|
352
|
-
|
336
|
+
"%253C%2FFONT%253E%2522&session=&zurl=opac" \
|
337
|
+
"&zquery=%281%3D7+4%3D2+2%3D3+5%3D100+6%3D1+3%3D3+%22" +
|
353
338
|
canonicalise_isbn_with_dashes(book.isbn) +
|
354
|
-
|
355
|
-
rescue => ex
|
339
|
+
"%22%29&language=it&maxentries=10&target=0&position=1"
|
340
|
+
rescue StandardError => ex
|
356
341
|
log.warn { "Cannot create url for book #{book}; #{ex.message}" }
|
357
342
|
nil
|
358
343
|
end
|
359
344
|
|
360
345
|
private
|
361
346
|
|
347
|
+
def canonicalise_criterion(criterion, _type)
|
348
|
+
canonicalise_isbn_with_dashes(criterion)
|
349
|
+
end
|
350
|
+
|
351
|
+
def request_count(_type)
|
352
|
+
0
|
353
|
+
end
|
354
|
+
|
362
355
|
def canonicalise_isbn_with_dashes(isbn)
|
363
356
|
# The reference for the position of the dashes is
|
364
357
|
# http://www.isbn-international.org/converter/ranges.htm
|
365
358
|
|
366
359
|
isbn = Alexandria::Library.canonicalise_isbn(isbn)
|
367
360
|
|
368
|
-
if isbn[0..1] ==
|
361
|
+
if isbn[0..1] == "88"
|
369
362
|
# Italian speaking area
|
370
|
-
if isbn >
|
371
|
-
|
372
|
-
elsif isbn >
|
373
|
-
|
374
|
-
elsif isbn >
|
375
|
-
|
376
|
-
elsif isbn >
|
377
|
-
|
378
|
-
elsif isbn >
|
379
|
-
|
380
|
-
elsif isbn >
|
381
|
-
|
363
|
+
if isbn > "8895000" && (isbn <= "8899999996")
|
364
|
+
isbn[0..1] + "-" + isbn[2..6] + "-" + isbn[7..8] + "-" + isbn[9..9]
|
365
|
+
elsif isbn > "88900000"
|
366
|
+
isbn[0..1] + "-" + isbn[2..7] + "-" + isbn[8..8] + "-" + isbn[9..9]
|
367
|
+
elsif isbn > "8885000"
|
368
|
+
isbn[0..1] + "-" + isbn[2..6] + "-" + isbn[7..8] + "-" + isbn[9..9]
|
369
|
+
elsif isbn > "886000"
|
370
|
+
isbn[0..1] + "-" + isbn[2..5] + "-" + isbn[6..8] + "-" + isbn[9..9]
|
371
|
+
elsif isbn > "88200"
|
372
|
+
isbn[0..1] + "-" + isbn[2..4] + "-" + isbn[5..8] + "-" + isbn[9..9]
|
373
|
+
elsif isbn > "8800"
|
374
|
+
isbn[0..1] + "-" + isbn[2..3] + "-" + isbn[4..8] + "-" + isbn[9..9]
|
382
375
|
else
|
383
|
-
raise
|
376
|
+
raise _("Invalid ISBN")
|
384
377
|
end
|
385
378
|
|
386
379
|
else
|
387
|
-
|
380
|
+
isbn
|
388
381
|
end
|
389
382
|
end
|
390
383
|
#
|
391
384
|
# Remarks about SBN
|
392
385
|
#
|
393
|
-
# This provider requires that value of conn.count is 0.
|
394
|
-
#
|
386
|
+
# This provider requires that value of conn.count is 0.
|
387
|
+
# It's a Yaz option "Number of records to be retrieved".
|
388
|
+
# This provider requires to specify the value of conn.element_set_name = 'F'.
|
389
|
+
# It's a Yaz option "Element-Set name of records".
|
395
390
|
# See http://www.indexdata.dk/yaz/doc/zoom.resultsets.tkl
|
396
391
|
#
|
397
392
|
# Dashes:
|
398
393
|
# this database requires that Italian books are searched with dashes :(
|
399
|
-
# However, they have also books with dashes in wrong positions, for
|
394
|
+
# However, they have also books with dashes in wrong positions, for
|
395
|
+
# instance 88-061-4934-2
|
400
396
|
#
|
401
397
|
# References:
|
402
398
|
# http://opac.internetculturale.it/cgi-bin/main.cgi?type=field
|