alexandria-book-collection-manager 0.6.9.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (293) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rubocop.yml +68 -0
  4. data/.rubocop_todo.yml +200 -0
  5. data/CHANGELOG.md +23 -0
  6. data/COPYING +339 -0
  7. data/ChangeLog.0 +3598 -0
  8. data/Gemfile +9 -0
  9. data/INSTALL.rdoc +156 -0
  10. data/PACKAGING +36 -0
  11. data/README.md +88 -0
  12. data/RELEASE_CHECKLIST +18 -0
  13. data/Rakefile +264 -0
  14. data/TODO +24 -0
  15. data/alexandria-book-collection-manager.gemspec +35 -0
  16. data/alexandria.desktop.in +10 -0
  17. data/bin/alexandria +82 -0
  18. data/doc/AUTHORS +60 -0
  19. data/doc/BUGS +31 -0
  20. data/doc/FAQ +369 -0
  21. data/doc/HACKING +19 -0
  22. data/doc/NEWS +341 -0
  23. data/doc/alexandria.1 +120 -0
  24. data/doc/cuecat_support.rdoc +67 -0
  25. data/lib/alexandria.rb +85 -0
  26. data/lib/alexandria/about.rb +82 -0
  27. data/lib/alexandria/book_providers.rb +411 -0
  28. data/lib/alexandria/book_providers/adlibris.rb +235 -0
  29. data/lib/alexandria/book_providers/amazon_aws.rb +261 -0
  30. data/lib/alexandria/book_providers/amazon_ecs_util.rb +405 -0
  31. data/lib/alexandria/book_providers/barnes_and_noble.rb +229 -0
  32. data/lib/alexandria/book_providers/bol_it.rb +162 -0
  33. data/lib/alexandria/book_providers/deastore.rb +277 -0
  34. data/lib/alexandria/book_providers/douban.rb +135 -0
  35. data/lib/alexandria/book_providers/ibs_it.rb +149 -0
  36. data/lib/alexandria/book_providers/mcu.rb +177 -0
  37. data/lib/alexandria/book_providers/proxis.rb +205 -0
  38. data/lib/alexandria/book_providers/pseudomarc.rb +185 -0
  39. data/lib/alexandria/book_providers/renaud.rb +142 -0
  40. data/lib/alexandria/book_providers/siciliano.rb +271 -0
  41. data/lib/alexandria/book_providers/thalia.rb +197 -0
  42. data/lib/alexandria/book_providers/web.rb +59 -0
  43. data/lib/alexandria/book_providers/webster_it.rb +173 -0
  44. data/lib/alexandria/book_providers/worldcat.rb +251 -0
  45. data/lib/alexandria/book_providers/z3950.rb +422 -0
  46. data/lib/alexandria/config.rb +8 -0
  47. data/lib/alexandria/console.rb +31 -0
  48. data/lib/alexandria/execution_queue.rb +96 -0
  49. data/lib/alexandria/export_library.rb +536 -0
  50. data/lib/alexandria/import_library.rb +316 -0
  51. data/lib/alexandria/import_library_csv.rb +270 -0
  52. data/lib/alexandria/logging.rb +159 -0
  53. data/lib/alexandria/models/book.rb +72 -0
  54. data/lib/alexandria/models/library.rb +714 -0
  55. data/lib/alexandria/net.rb +53 -0
  56. data/lib/alexandria/preferences.rb +324 -0
  57. data/lib/alexandria/scanners.rb +42 -0
  58. data/lib/alexandria/scanners/cuecat.rb +118 -0
  59. data/lib/alexandria/scanners/keyboard.rb +57 -0
  60. data/lib/alexandria/smart_library.rb +525 -0
  61. data/lib/alexandria/ui.rb +53 -0
  62. data/lib/alexandria/ui/builder_base.rb +43 -0
  63. data/lib/alexandria/ui/callbacks.rb +389 -0
  64. data/lib/alexandria/ui/completion_models.rb +228 -0
  65. data/lib/alexandria/ui/dialogs/about_dialog.rb +59 -0
  66. data/lib/alexandria/ui/dialogs/acquire_dialog.rb +640 -0
  67. data/lib/alexandria/ui/dialogs/alert_dialog.rb +68 -0
  68. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +43 -0
  69. data/lib/alexandria/ui/dialogs/barcode_animation.rb +159 -0
  70. data/lib/alexandria/ui/dialogs/book_properties_dialog.rb +210 -0
  71. data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +432 -0
  72. data/lib/alexandria/ui/dialogs/export_dialog.rb +172 -0
  73. data/lib/alexandria/ui/dialogs/import_dialog.rb +205 -0
  74. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +85 -0
  75. data/lib/alexandria/ui/dialogs/new_book_dialog.rb +639 -0
  76. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +153 -0
  77. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +67 -0
  78. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +587 -0
  79. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +56 -0
  80. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +432 -0
  81. data/lib/alexandria/ui/dndable.rb +81 -0
  82. data/lib/alexandria/ui/gtk_thread_help.rb +88 -0
  83. data/lib/alexandria/ui/icons.rb +100 -0
  84. data/lib/alexandria/ui/iconview.rb +91 -0
  85. data/lib/alexandria/ui/iconview_tooltips.rb +162 -0
  86. data/lib/alexandria/ui/init.rb +93 -0
  87. data/lib/alexandria/ui/libraries_combo.rb +75 -0
  88. data/lib/alexandria/ui/listview.rb +310 -0
  89. data/lib/alexandria/ui/main_app.rb +67 -0
  90. data/lib/alexandria/ui/multi_drag_treeview.rb +150 -0
  91. data/lib/alexandria/ui/sidepane.rb +194 -0
  92. data/lib/alexandria/ui/sound.rb +107 -0
  93. data/lib/alexandria/ui/ui_manager.rb +1308 -0
  94. data/lib/alexandria/undo_manager.rb +78 -0
  95. data/lib/alexandria/utils.rb +30 -0
  96. data/lib/alexandria/version.rb +24 -0
  97. data/lib/alexandria/web_themes.rb +75 -0
  98. data/misc/sounds/README +15 -0
  99. data/misc/sounds/bad_scan.csd +62 -0
  100. data/misc/sounds/good_scan.csd +61 -0
  101. data/misc/sounds/scanning.csd +46 -0
  102. data/po/ChangeLog +488 -0
  103. data/po/Makefile +44 -0
  104. data/po/README +29 -0
  105. data/po/commit-po +72 -0
  106. data/po/cs.po +1437 -0
  107. data/po/cy.po +1521 -0
  108. data/po/de.po +1400 -0
  109. data/po/el.po +1379 -0
  110. data/po/es.po +1376 -0
  111. data/po/fr.po +1420 -0
  112. data/po/ga.po +1359 -0
  113. data/po/gl.po +1397 -0
  114. data/po/it.po +1406 -0
  115. data/po/ja.po +1355 -0
  116. data/po/mk.po +1373 -0
  117. data/po/nb.po +1386 -0
  118. data/po/nl.po +1405 -0
  119. data/po/pl.po +1373 -0
  120. data/po/pt.po +1398 -0
  121. data/po/pt_BR.po +1409 -0
  122. data/po/ru.po +1372 -0
  123. data/po/sk.po +1380 -0
  124. data/po/sv.po +1402 -0
  125. data/po/uk.po +1423 -0
  126. data/po/zh_TW.po +1394 -0
  127. data/schemas/alexandria.schemas +300 -0
  128. data/share/alexandria/glade/acquire_dialog__builder.glade +201 -0
  129. data/share/alexandria/glade/book_properties_dialog__builder.glade +910 -0
  130. data/share/alexandria/glade/main_app__builder.glade +229 -0
  131. data/share/alexandria/glade/new_book_dialog__builder.glade +379 -0
  132. data/share/alexandria/glade/preferences_dialog__builder.glade +733 -0
  133. data/share/alexandria/icons/alexandria.png +0 -0
  134. data/share/alexandria/icons/alexandria_small.png +0 -0
  135. data/share/alexandria/icons/book.png +0 -0
  136. data/share/alexandria/icons/book_icon.png +0 -0
  137. data/share/alexandria/icons/book_small.png +0 -0
  138. data/share/alexandria/icons/cuecat.png +0 -0
  139. data/share/alexandria/icons/cuecat_inactive.png +0 -0
  140. data/share/alexandria/icons/favorite_tag.png +0 -0
  141. data/share/alexandria/icons/less.png +0 -0
  142. data/share/alexandria/icons/library.png +0 -0
  143. data/share/alexandria/icons/library_small.png +0 -0
  144. data/share/alexandria/icons/lookup.png +0 -0
  145. data/share/alexandria/icons/more.png +0 -0
  146. data/share/alexandria/icons/no_cover.png +0 -0
  147. data/share/alexandria/icons/smart_library.png +0 -0
  148. data/share/alexandria/icons/smart_library_small.png +0 -0
  149. data/share/alexandria/icons/star_set.png +0 -0
  150. data/share/alexandria/icons/star_unset.png +0 -0
  151. data/share/alexandria/icons/view_as_icons.png +0 -0
  152. data/share/alexandria/icons/view_as_list.png +0 -0
  153. data/share/alexandria/ui/menus.xml +91 -0
  154. data/share/alexandria/ui/popups.xml +91 -0
  155. data/share/alexandria/web-themes/clean/clean.css +85 -0
  156. data/share/alexandria/web-themes/clean/preview.jpg +0 -0
  157. data/share/alexandria/web-themes/list/list.css +105 -0
  158. data/share/alexandria/web-themes/list/preview.jpg +0 -0
  159. data/share/app-icon/16x16/alexandria.png +0 -0
  160. data/share/app-icon/16x16/alexandria.svg +263 -0
  161. data/share/app-icon/22x22/alexandria.png +0 -0
  162. data/share/app-icon/22x22/alexandria.svg +465 -0
  163. data/share/app-icon/24x24/alexandria.png +0 -0
  164. data/share/app-icon/32x32/alexandria.png +0 -0
  165. data/share/app-icon/32x32/alexandria.svg +813 -0
  166. data/share/app-icon/32x32/alexandria.xpm +241 -0
  167. data/share/app-icon/48x48/alexandria.png +0 -0
  168. data/share/app-icon/scalable/alexandria.svg +700 -0
  169. data/share/gnome/help/alexandria/C/about.xml +44 -0
  170. data/share/gnome/help/alexandria/C/adding-books.xml +339 -0
  171. data/share/gnome/help/alexandria/C/alexandria.xml +185 -0
  172. data/share/gnome/help/alexandria/C/bugs.xml +18 -0
  173. data/share/gnome/help/alexandria/C/editing-book-properties.xml +124 -0
  174. data/share/gnome/help/alexandria/C/exporting.xml +81 -0
  175. data/share/gnome/help/alexandria/C/figures/adding_books_acquire_from_scanner_process.png +0 -0
  176. data/share/gnome/help/alexandria/C/figures/adding_books_add_by_isbn.png +0 -0
  177. data/share/gnome/help/alexandria/C/figures/adding_books_isbn_import.png +0 -0
  178. data/share/gnome/help/alexandria/C/figures/adding_books_manual_details.png +0 -0
  179. data/share/gnome/help/alexandria/C/figures/adding_books_rename_library_after_import.png +0 -0
  180. data/share/gnome/help/alexandria/C/figures/adding_books_search_results.png +0 -0
  181. data/share/gnome/help/alexandria/C/figures/editing_book_properties_info.png +0 -0
  182. data/share/gnome/help/alexandria/C/figures/editing_book_properties_loaning.png +0 -0
  183. data/share/gnome/help/alexandria/C/figures/exporting_information_html.png +0 -0
  184. data/share/gnome/help/alexandria/C/figures/getting_started_first_launched.png +0 -0
  185. data/share/gnome/help/alexandria/C/figures/searching_filtering_views_list_view.png +0 -0
  186. data/share/gnome/help/alexandria/C/figures/searching_filtering_views_list_view_search.png +0 -0
  187. data/share/gnome/help/alexandria/C/figures/settings_providers_new_z3950.png +0 -0
  188. data/share/gnome/help/alexandria/C/figures/smart_libraries_new_smart_library.png +0 -0
  189. data/share/gnome/help/alexandria/C/figures/working_with_libraries_library_pane.png +0 -0
  190. data/share/gnome/help/alexandria/C/getting-started.xml +154 -0
  191. data/share/gnome/help/alexandria/C/gnu-fdl-1.2.xml +543 -0
  192. data/share/gnome/help/alexandria/C/introduction.xml +142 -0
  193. data/share/gnome/help/alexandria/C/searching.xml +90 -0
  194. data/share/gnome/help/alexandria/C/settings.xml +140 -0
  195. data/share/gnome/help/alexandria/C/smart-libraries.xml +160 -0
  196. data/share/gnome/help/alexandria/C/working-with-libraries.xml +76 -0
  197. data/share/gnome/help/alexandria/ChangeLog +99 -0
  198. data/share/gnome/help/alexandria/fr/alexandria.xml +2292 -0
  199. data/share/gnome/help/alexandria/fr/figures/alexandria_add_button.png +0 -0
  200. data/share/gnome/help/alexandria/fr/figures/alexandria_add_by_isbn_1.png +0 -0
  201. data/share/gnome/help/alexandria/fr/figures/alexandria_add_by_search_1.png +0 -0
  202. data/share/gnome/help/alexandria/fr/figures/alexandria_add_manually.png +0 -0
  203. data/share/gnome/help/alexandria/fr/figures/alexandria_add_z3950.png +0 -0
  204. data/share/gnome/help/alexandria/fr/figures/alexandria_close_button.png +0 -0
  205. data/share/gnome/help/alexandria/fr/figures/alexandria_edit_info.png +0 -0
  206. data/share/gnome/help/alexandria/fr/figures/alexandria_export_web_page.png +0 -0
  207. data/share/gnome/help/alexandria/fr/figures/alexandria_importing.png +0 -0
  208. data/share/gnome/help/alexandria/fr/figures/alexandria_library_pane.png +0 -0
  209. data/share/gnome/help/alexandria/fr/figures/alexandria_list_view.png +0 -0
  210. data/share/gnome/help/alexandria/fr/figures/alexandria_list_view_search.png +0 -0
  211. data/share/gnome/help/alexandria/fr/figures/alexandria_loaning.png +0 -0
  212. data/share/gnome/help/alexandria/fr/figures/alexandria_main_window.png +0 -0
  213. data/share/gnome/help/alexandria/fr/figures/alexandria_remove_button.png +0 -0
  214. data/share/gnome/help/alexandria/ja/about.xml +33 -0
  215. data/share/gnome/help/alexandria/ja/adding-books.xml +314 -0
  216. data/share/gnome/help/alexandria/ja/alexandria.xml +172 -0
  217. data/share/gnome/help/alexandria/ja/bugs.xml +11 -0
  218. data/share/gnome/help/alexandria/ja/editing-book-properties.xml +100 -0
  219. data/share/gnome/help/alexandria/ja/exporting.xml +98 -0
  220. data/share/gnome/help/alexandria/ja/figures/adding_books_acquire_from_scanner_process.png +0 -0
  221. data/share/gnome/help/alexandria/ja/figures/adding_books_add_by_isbn.png +0 -0
  222. data/share/gnome/help/alexandria/ja/figures/adding_books_isbn_import.png +0 -0
  223. data/share/gnome/help/alexandria/ja/figures/adding_books_manual_details.png +0 -0
  224. data/share/gnome/help/alexandria/ja/figures/adding_books_rename_library_after_import.png +0 -0
  225. data/share/gnome/help/alexandria/ja/figures/adding_books_search_results.png +0 -0
  226. data/share/gnome/help/alexandria/ja/figures/editing_book_properties_info.png +0 -0
  227. data/share/gnome/help/alexandria/ja/figures/editing_book_properties_loaning.png +0 -0
  228. data/share/gnome/help/alexandria/ja/figures/exporting_information_html.png +0 -0
  229. data/share/gnome/help/alexandria/ja/figures/getting_started_first_launched.png +0 -0
  230. data/share/gnome/help/alexandria/ja/figures/searching_filtering_views_list_view.png +0 -0
  231. data/share/gnome/help/alexandria/ja/figures/searching_filtering_views_list_view_search.png +0 -0
  232. data/share/gnome/help/alexandria/ja/figures/settings_providers_new_z3950.png +0 -0
  233. data/share/gnome/help/alexandria/ja/figures/smart_libraries_new_smart_library.png +0 -0
  234. data/share/gnome/help/alexandria/ja/figures/working_with_libraries_library_pane.png +0 -0
  235. data/share/gnome/help/alexandria/ja/getting-started.xml +144 -0
  236. data/share/gnome/help/alexandria/ja/gnu-fdl-1.2.xml +541 -0
  237. data/share/gnome/help/alexandria/ja/introduction.xml +134 -0
  238. data/share/gnome/help/alexandria/ja/searching.xml +104 -0
  239. data/share/gnome/help/alexandria/ja/settings.xml +129 -0
  240. data/share/gnome/help/alexandria/ja/smart-libraries.xml +140 -0
  241. data/share/gnome/help/alexandria/ja/working-with-libraries.xml +88 -0
  242. data/share/menu/alexandria +7 -0
  243. data/share/omf/alexandria/alexandria-C.omf.in +27 -0
  244. data/share/omf/alexandria/alexandria-fr.omf.in +30 -0
  245. data/share/sounds/alexandria/bad_scan.ogg +0 -0
  246. data/share/sounds/alexandria/bad_scan.wav +0 -0
  247. data/share/sounds/alexandria/good_scan.ogg +0 -0
  248. data/share/sounds/alexandria/good_scan.wav +0 -0
  249. data/share/sounds/alexandria/scanning.ogg +0 -0
  250. data/share/sounds/alexandria/scanning.wav +0 -0
  251. data/spec/alexandria/library_spec.rb +205 -0
  252. data/spec/alexandria/preferences_spec.rb +22 -0
  253. data/spec/alexandria/scanners/cuecat_spec.rb +68 -0
  254. data/spec/alexandria/smart_library_spec.rb +22 -0
  255. data/spec/alexandria/ui/dialogs_spec.rb +90 -0
  256. data/spec/alexandria/ui/iconview_spec.rb +27 -0
  257. data/spec/alexandria/ui/listview_spec.rb +28 -0
  258. data/spec/alexandria/ui/main_app_spec.rb +48 -0
  259. data/spec/alexandria/ui/sidepane_spec.rb +27 -0
  260. data/spec/alexandria/ui/ui_manager_spec.rb +26 -0
  261. data/spec/alexandria/ui/ui_utilities_spec.rb +60 -0
  262. data/spec/alexandria/utilities_spec.rb +50 -0
  263. data/spec/data/libraries/0.6.1-noisbn/My Library/0201398257.yaml +10 -0
  264. data/spec/data/libraries/0.6.1-noisbn/My Library/1565920007.yaml +10 -0
  265. data/spec/data/libraries/0.6.1/My Library/0192812173.yaml +9 -0
  266. data/spec/data/libraries/0.6.1/My Library/0201398257.cover +0 -0
  267. data/spec/data/libraries/0.6.1/My Library/0201398257.yaml +10 -0
  268. data/spec/data/libraries/0.6.1/My Library/1565920007.yaml +10 -0
  269. data/spec/data/libraries/0.6.2/My Library/9780140266146.cover +0 -0
  270. data/spec/data/libraries/0.6.2/My Library/9780140266146.yaml +16 -0
  271. data/spec/data/libraries/0.6.2/My Library/9780140278781.cover +0 -0
  272. data/spec/data/libraries/0.6.2/My Library/9780140278781.yaml +21 -0
  273. data/spec/data/libraries/0.6.2/My Library/9780571147168.cover +0 -0
  274. data/spec/data/libraries/0.6.2/My Library/9780571147168.yaml +20 -0
  275. data/spec/data/libraries/0.6.2/My Library/9780575079038.cover +0 -0
  276. data/spec/data/libraries/0.6.2/My Library/9780575079038.yaml +20 -0
  277. data/spec/data/libraries/0.6.2/My Library/9780755322800.cover +0 -0
  278. data/spec/data/libraries/0.6.2/My Library/9780755322800.yaml +20 -0
  279. data/spec/spec_helper.rb +46 -0
  280. data/tasks/rdoc.rake +6 -0
  281. data/tasks/setup.rb +30 -0
  282. data/tasks/spec.rake +29 -0
  283. data/tasks/test.rake +38 -0
  284. data/test/application_test.rb +39 -0
  285. data/test/book_test.rb +34 -0
  286. data/test/data/isbns.txt +3 -0
  287. data/test/isbn_test.rb +68 -0
  288. data/test/providers_test.rb +254 -0
  289. data/test/test_helper.rb +42 -0
  290. data/util/rake/fileinstall.rb +313 -0
  291. data/util/rake/gettextgenerate.rb +158 -0
  292. data/util/rake/omfgenerate.rb +79 -0
  293. metadata +452 -0
@@ -0,0 +1,422 @@
1
+ # Copyright (C) 2005-2006 Laurent Sansonetti
2
+ # Copyright (C) 2007 Laurent Sansonetti and Marco Costantini
3
+ # Copyright (C) 2014 Matijs van Zuijlen
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.
14
+ #
15
+ # You should have received a copy of the GNU General Public
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.
19
+
20
+ ## $Z3950_DEBUG = $DEBUG
21
+
22
+ require 'zoom'
23
+ require 'alexandria/book_providers/pseudomarc'
24
+ require 'marc'
25
+
26
+ module Alexandria
27
+ class BookProviders
28
+ class Z3950Provider < AbstractProvider
29
+ include Logging
30
+ include GetText
31
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
32
+
33
+ def initialize(name = 'Z3950', fullname = 'Z39.50')
34
+ super
35
+ prefs.add('hostname', _('Hostname'), '')
36
+ prefs.add('port', _('Port'), 7090)
37
+ prefs.add('database', _('Database'), '')
38
+ prefs.add('record_syntax', _('Record syntax'), 'USMARC', ['USMARC', 'UNIMARC', 'SUTRS'])
39
+ prefs.add('username', _('Username'), '', nil, false)
40
+ prefs.add('password', _('Password'), '', nil, false)
41
+ prefs.add('charset', _('Charset encoding'), 'ISO-8859-1')
42
+
43
+ # HACK : piggybacking support
44
+ prefs.add('piggyback', 'Piggyback', true, [true, false])
45
+ prefs.read
46
+ end
47
+
48
+ def search(criterion, type)
49
+ prefs.read
50
+ criterion = criterion.convert(prefs['charset'], 'UTF-8')
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
+ unless marc?
56
+ raise NoResultsError
57
+ end
58
+
59
+ isbn = type == SEARCH_BY_ISBN ? criterion : nil
60
+ criterion = Library.canonicalise_isbn(criterion) if type == SEARCH_BY_ISBN
61
+ conn_count = type == SEARCH_BY_ISBN ? 1 : 10 # results to retrieve
62
+ resultset = search_records(criterion, type, conn_count)
63
+ log.debug { "total #{resultset.length}" }
64
+ raise NoResultsError if resultset.length == 0
65
+ results = books_from_marc(resultset, isbn)
66
+ type == SEARCH_BY_ISBN ? results.first : results
67
+ end
68
+
69
+ def url(_book)
70
+ nil
71
+ end
72
+
73
+ #######
74
+ private
75
+ #######
76
+
77
+ def marc_to_book(marc_txt)
78
+ begin
79
+ marc = MARC::Record.new_from_marc(marc_txt, forgiving: true)
80
+ rescue => ex
81
+ log.error { ex.message }
82
+ log.error { ex.backtrace.join("> \n") }
83
+ begin
84
+ marc = MARC::Record.new(marc_txt)
85
+ rescue => ex2
86
+ log.error { ex2.message }
87
+ log.error { ex2.backtrace.join("> \n") }
88
+ raise ex2
89
+ end
90
+ end
91
+
92
+ log.debug {
93
+ msg = 'Parsing MARC'
94
+ msg += "\n title: #{marc.title}"
95
+ msg += "\n authors: #{marc.authors.join(', ')}"
96
+ msg += "\n isbn: #{marc.isbn}, #{isbn}"
97
+ msg += "\n publisher: #{marc.publisher}"
98
+ msg += "\n publish year: #{marc.publish_year}" if marc.respond_to?(:publish_year)
99
+ msg += "\n edition: #{marc.edition}"
100
+ msg
101
+ }
102
+
103
+ return if marc.title.nil? # or marc.authors.empty?
104
+
105
+ isbn = isbn or marc.isbn
106
+ isbn = Library.canonicalise_ean(isbn)
107
+
108
+ book = Book.new(marc.title, marc.authors,
109
+ isbn,
110
+ (marc.publisher or ''),
111
+ marc.respond_to?(:publish_year) ? marc.publish_year.to_i : nil,
112
+ (marc.edition or ''))
113
+ book
114
+ end
115
+
116
+ def books_from_marc(resultset, _isbn)
117
+ results = []
118
+ resultset[0..9].each do |record|
119
+ marc_txt = record.render(prefs['charset'], 'UTF-8') # (prefs['record_syntax'], 'USMARC')
120
+ log.debug { marc_txt }
121
+ # marc_txt = marc_txt.convert("UTF-8", prefs['charset'])
122
+ if $DEBUG
123
+ File.open(',marc.txt', 'wb') do |f| # DEBUG
124
+ f.write(marc_txt)
125
+ end
126
+ end
127
+ book = nil
128
+ begin
129
+ mappings = Alexandria::PseudoMarcParser::USMARC_MAPPINGS
130
+ if prefs['hostname'] == 'z3950.bnf.fr'
131
+ mappings = Alexandria::PseudoMarcParser::BNF_FR_MAPPINGS
132
+ end
133
+ # try pseudo-marc parser first (it seems to have more luck)
134
+ book = Alexandria::PseudoMarcParser.marc_text_to_book(marc_txt,
135
+ mappings)
136
+ if book.nil?
137
+ # failing that, try the genuine MARC parser
138
+ book = marc_to_book(marc_txt)
139
+ end
140
+ rescue => ex
141
+ log.warn { ex }
142
+ log.warn { ex.backtrace }
143
+ end
144
+
145
+ results << [book] unless book.nil?
146
+ end
147
+ results
148
+ end
149
+
150
+ def marc?
151
+ /MARC$/.match(prefs['record_syntax'])
152
+ end
153
+
154
+ def search_records(criterion, type, conn_count)
155
+ options = {}
156
+ unless prefs['username'].empty? or prefs['password'].empty?
157
+ options['user'] = prefs['username']
158
+ options['password'] = prefs['password']
159
+ end
160
+ hostname, port = prefs['hostname'], prefs['port'].to_i
161
+ log.debug { "hostname #{hostname} port #{port} options #{options}" }
162
+ conn = ZOOM::Connection.new(options).connect(hostname, port)
163
+ conn.database_name = prefs['database']
164
+
165
+ # HACK turn off piggybacking, just to see CMcG
166
+ # #conn.piggyback = false
167
+
168
+ conn.preferred_record_syntax = prefs['record_syntax']
169
+ conn.element_set_name = 'F'
170
+ conn.count = conn_count
171
+ attr = case type
172
+ when SEARCH_BY_ISBN then [7]
173
+ when SEARCH_BY_TITLE then [4]
174
+ when SEARCH_BY_AUTHORS then [1, 1003]
175
+ when SEARCH_BY_KEYWORD then [1016]
176
+ end
177
+ pqf = ''
178
+ attr.each { |att| pqf += "@attr 1=#{att} " }
179
+ pqf += "\"" + criterion.upcase + "\""
180
+ log.debug { "pqf is #{pqf}, syntax #{prefs['record_syntax']}" }
181
+
182
+ begin
183
+ if prefs.variable_named('piggyback')
184
+ unless prefs['piggyback']
185
+ log.debug { 'setting conn.piggyback to false' }
186
+ conn.piggyback = false
187
+ end
188
+ end
189
+ conn.search(pqf)
190
+ rescue => ex
191
+ if /1005/ =~ ex.message
192
+ if prefs.variable_named('piggyback') and prefs['piggyback']
193
+ log.error { "Z39.50 search failed:: #{ex.message}" }
194
+ log.info { 'Turning off piggybacking for this provider' }
195
+ prefs.variable_named('piggyback').new_value = false
196
+ search_records(criterion, type, conn_count)
197
+ # hopefully these precautions will prevent infinite loops here
198
+ else
199
+ raise ex
200
+ end
201
+ else
202
+ raise ex
203
+ end
204
+ end
205
+ end
206
+ end
207
+
208
+ class LOCProvider < Z3950Provider
209
+ # http://en.wikipedia.org/wiki/Library_of_Congress
210
+ unabstract
211
+
212
+ include GetText
213
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
214
+
215
+ def initialize
216
+ super('LOC', _('Library of Congress (Usa)'))
217
+ prefs.variable_named('hostname').default_value = 'z3950.loc.gov'
218
+ prefs.variable_named('port').default_value = 7090
219
+ prefs.variable_named('database').default_value = 'Voyager'
220
+ prefs.variable_named('record_syntax').default_value = 'USMARC'
221
+ prefs.variable_named('charset').default_value = 'ISO_6937'
222
+ prefs.read
223
+ end
224
+
225
+ def url(book)
226
+ 'http://catalog.loc.gov/cgi-bin/Pwebrecon.cgi?DB=local&CNT=25+records+per+page&CMD=isbn+' + Library.canonicalise_isbn(book.isbn)
227
+ rescue => ex
228
+ log.warn { "Cannot create url for book #{book}; #{ex.message}" }
229
+ nil
230
+ end
231
+ end
232
+
233
+ class BLProvider < Z3950Provider
234
+ # http://en.wikipedia.org/wiki/Copac
235
+ # http://en.wikipedia.org/wiki/British_Library
236
+ # http://www.bl.uk/catalogues/z3950fullaccess.html
237
+ # http://www.bl.uk/catalogues/z3950copacaccess.html
238
+ # FIXME: switch from BL to Copac, which incudes the BL itself and many more libraries: http://copac.ac.uk/libraries/
239
+ # Details: http://copac.ac.uk/interfaces/z39.50/
240
+ # The SUTRS format used by Copac is different from the one used by BL
241
+ unabstract
242
+
243
+ include GetText
244
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
245
+
246
+ def initialize
247
+ super('BL', _('British Library'))
248
+ prefs.variable_named('hostname').default_value = 'z3950cat.bl.uk'
249
+ prefs.variable_named('port').default_value = 9909
250
+ prefs.variable_named('database').default_value = 'BLAC'
251
+ prefs.variable_named('record_syntax').default_value = 'SUTRS'
252
+ prefs.variable_named('charset').default_value = 'ISO-8859-1'
253
+ prefs.read
254
+ end
255
+
256
+ def search(criterion, type)
257
+ return super unless prefs['record_syntax'] == 'SUTRS'
258
+
259
+ prefs.read
260
+ criterion = Library.canonicalise_isbn(criterion) if type == SEARCH_BY_ISBN
261
+ conn_count = type == SEARCH_BY_ISBN ? 1 : 10 # results to retrieve
262
+ resultset = search_records(criterion, type, conn_count)
263
+ log.debug { "total #{resultset.length}" }
264
+ raise NoResultsError if resultset.length == 0
265
+ results = books_from_sutrs(resultset)
266
+ type == SEARCH_BY_ISBN ? results.first : results
267
+ end
268
+
269
+ def url(book)
270
+ 'http://copac.ac.uk/openurl?isbn=' + Library.canonicalise_isbn(book.isbn)
271
+ rescue => ex
272
+ log.warn { "Cannot create url for book #{book}; #{ex.message}" }
273
+ nil
274
+ end
275
+
276
+ #######
277
+ private
278
+ #######
279
+
280
+ def books_from_sutrs(resultset)
281
+ results = []
282
+ resultset[0..9].each do |record|
283
+ text = record.render(prefs['charset'], 'UTF-8')
284
+ # File.open(',bl.marc', 'wb') {|f| f.write(text) }
285
+ log.debug { text }
286
+ # text = text.convert("UTF-8", prefs['charset'])
287
+
288
+ title = isbn = publisher = publish_year = edition = nil
289
+ authors = []
290
+
291
+ text.split(/\n/).each do |line|
292
+ if (md = /^Title:\s+(.*)$/.match(line))
293
+ title = md[1].sub(/\.$/, '').squeeze(' ')
294
+ elsif (md = /^Added Person Name:\s+(.*),[^,]+$/.match(line))
295
+ authors << md[1]
296
+ elsif (md = /^ME-Personal Name:\s+(.*),[^,]+$/.match(line))
297
+ authors << md[1]
298
+ elsif (md = /^ISBN:\s+([\dXx]+)/.match(line))
299
+ isbn = Library.canonicalise_ean(md[1])
300
+ elsif (md = /^Imprint:.+\:\s*(.+)\,/.match(line))
301
+ publisher = md[1]
302
+ end
303
+ end
304
+
305
+ log.debug {
306
+ msg = 'Parsing SUTRS'
307
+ msg += "\n title: #{title}"
308
+ msg += "\n authors: #{authors.join(' and ')}"
309
+ msg += "\n isbn: #{isbn}"
310
+ msg += "\n publisher: #{publisher}"
311
+ msg += "\n edition: #{edition}"
312
+ msg
313
+ }
314
+
315
+ if title # and !authors.empty?
316
+ book = Book.new(title, authors, isbn, (publisher or nil), (publish_year or nil), (edition or nil))
317
+ results << [book]
318
+ end
319
+
320
+ end
321
+ results
322
+ end
323
+ end
324
+
325
+ class SBNProvider < Z3950Provider
326
+ # http://sbnonline.sbn.it/
327
+ # http://it.wikipedia.org/wiki/ICCU
328
+ unabstract
329
+
330
+ include GetText
331
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
332
+
333
+ def initialize
334
+ super('SBN', 'Servizio Bibliotecario Nazionale (Italy)')
335
+ prefs.variable_named('hostname').default_value = 'opac.sbn.it'
336
+ prefs.variable_named('port').default_value = 3950
337
+ prefs.variable_named('database').default_value = 'nopac'
338
+ # supported 'USMARC', 'UNIMARC' , 'SUTRS'
339
+ prefs.variable_named('record_syntax').default_value = 'USMARC'
340
+ prefs.variable_named('charset').default_value = 'ISO-8859-1'
341
+ prefs.read
342
+ end
343
+
344
+ def search(criterion, type)
345
+ prefs.read
346
+
347
+ isbn = type == SEARCH_BY_ISBN ? criterion : nil
348
+ criterion = canonicalise_isbn_with_dashes(criterion)
349
+ resultset = search_records(criterion, type, 0)
350
+ log.debug { "total #{resultset.length}" }
351
+ raise NoResultsError if resultset.length == 0
352
+ results = books_from_marc(resultset, isbn)
353
+ type == SEARCH_BY_ISBN ? results.first : results
354
+ end
355
+
356
+ def url(book)
357
+ 'http://sbnonline.sbn.it/cgi-bin/zgw/BRIEF.pl?displayquery=%253CB%253E%253Cfont%2520color%253D%2523000064%253E' \
358
+ 'Codice%2520ISBN%253C%2FB%253E%253C%2Ffont%253E%2520contiene%2520%2522%2520%253CFONT%2520COLOR%253Dred%253E' +
359
+ canonicalise_isbn_with_dashes(book.isbn) +
360
+ '%253C%2FFONT%253E%2522&session=&zurl=opac&zquery=%281%3D7+4%3D2+2%3D3+5%3D100+6%3D1+3%3D3+%22' +
361
+ canonicalise_isbn_with_dashes(book.isbn) +
362
+ '%22%29&language=it&maxentries=10&target=0&position=1'
363
+ rescue => ex
364
+ log.warn { "Cannot create url for book #{book}; #{ex.message}" }
365
+ nil
366
+ end
367
+
368
+ #######
369
+ private
370
+ #######
371
+
372
+ def canonicalise_isbn_with_dashes(isbn)
373
+ # The reference for the position of the dashes is
374
+ # http://www.isbn-international.org/converter/ranges.htm
375
+
376
+ isbn = Alexandria::Library.canonicalise_isbn(isbn)
377
+
378
+ if isbn[0..1] == '88'
379
+ # Italian speaking area
380
+ if isbn > '8895000' and isbn <= '8899999996'
381
+ return isbn[0..1] + '-' + isbn[2..6] + '-' + isbn[7..8] + '-' + isbn[9..9]
382
+ elsif isbn > '88900000'
383
+ return isbn[0..1] + '-' + isbn[2..7] + '-' + isbn[8..8] + '-' + isbn[9..9]
384
+ elsif isbn > '8885000'
385
+ return isbn[0..1] + '-' + isbn[2..6] + '-' + isbn[7..8] + '-' + isbn[9..9]
386
+ elsif isbn > '886000'
387
+ return isbn[0..1] + '-' + isbn[2..5] + '-' + isbn[6..8] + '-' + isbn[9..9]
388
+ elsif isbn > '88200'
389
+ return isbn[0..1] + '-' + isbn[2..4] + '-' + isbn[5..8] + '-' + isbn[9..9]
390
+ elsif isbn > '8800'
391
+ return isbn[0..1] + '-' + isbn[2..3] + '-' + isbn[4..8] + '-' + isbn[9..9]
392
+ else
393
+ raise 'Invalid ISBN'
394
+ end
395
+
396
+ else
397
+ return isbn
398
+ end
399
+ end
400
+ #
401
+ # Remarks about SBN
402
+ #
403
+ # This provider requires that value of conn.count is 0. It's a Yaz option "Number of records to be retrieved".
404
+ # This provider requires to specify the value of conn.element_set_name = 'F'. It's a Yaz option "Element-Set name of records".
405
+ # See http://www.indexdata.dk/yaz/doc/zoom.resultsets.tkl
406
+ #
407
+ # Dashes:
408
+ # this database requires that Italian books are searched with dashes :(
409
+ # However, they have also books with dashes in wrong positions, for instance 88-061-4934-2
410
+ #
411
+ # References:
412
+ # http://opac.internetculturale.it/cgi-bin/main.cgi?type=field
413
+ # http://www.internetculturale.it/
414
+ # http://sbnonline.sbn.it/zgw/homeit.html
415
+ # http://www.iccu.sbn.it/genera.jsp?id=124
416
+ # with link at http://www.iccu.sbn.it/upload/documenti/cartecsbn.pdf
417
+ # http://www.loc.gov/cgi-bin/zgstart?ACTION=INIT&FORM_HOST_PORT=/prod/www/data/z3950/iccu.html,opac.sbn.it,2100
418
+ # http://gwz.cilea.it/cgi-bin/reportOpac.cgi
419
+ #
420
+ end
421
+ end
422
+ end
@@ -0,0 +1,8 @@
1
+ module Alexandria
2
+ module Config
3
+ SHARE_DIR = File.expand_path('../../share', File.dirname(__FILE__))
4
+ SOUNDS_DIR = "#{SHARE_DIR}/sounds/alexandria"
5
+ DATA_DIR = "#{SHARE_DIR}/alexandria"
6
+ MAIN_DATA_DIR = DATA_DIR
7
+ end
8
+ end
@@ -0,0 +1,31 @@
1
+ # Copyright (C) 2008 Joseph Method
2
+ #
3
+ # Alexandria is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU General Public License as
5
+ # published by the Free Software Foundation; either version 2 of the
6
+ # License, or (at your option) any later version.
7
+ #
8
+ # Alexandria is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public
14
+ # License along with Alexandria; see the file COPYING. If not,
15
+ # write to the Free Software Foundation, Inc., 51 Franklin Street,
16
+ # Fifth Floor, Boston, MA 02110-1301 USA.
17
+
18
+ module Alexandria
19
+ def self.list_books_on_console(_title = true, authors = true)
20
+ libraries_simpleton = Alexandria::Libraries.instance
21
+ libraries_simpleton.reload
22
+ libraries = Alexandria::Library.loadall
23
+ output_string = ''
24
+ @books = libraries.flatten
25
+ @books.each do |book|
26
+ book_authors = book.authors.join(' & ') if authors
27
+ output_string += [book.title, book_authors].join(', ') + "\n"
28
+ end
29
+ output_string
30
+ end
31
+ end