alexandria-book-collection-manager 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.hound.yml +2 -0
- data/.rubocop.yml +4 -4
- data/.rubocop_todo.yml +55 -82
- data/CHANGELOG.md +17 -0
- data/INSTALL.md +3 -3
- data/README.md +1 -2
- data/Rakefile +14 -33
- data/TODO.md +9 -1
- data/alexandria-book-collection-manager.gemspec +4 -3
- data/bin/alexandria +21 -34
- data/doc/FAQ +2 -5
- data/lib/alexandria.rb +4 -16
- data/lib/alexandria/book_providers.rb +5 -7
- data/lib/alexandria/book_providers/adlibris.rb +5 -3
- data/lib/alexandria/book_providers/amazon_aws.rb +3 -1
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +8 -0
- data/lib/alexandria/book_providers/barnes_and_noble.rb +7 -4
- data/lib/alexandria/book_providers/douban.rb +1 -1
- data/lib/alexandria/book_providers/proxis.rb +11 -27
- data/lib/alexandria/book_providers/renaud.rb +9 -3
- data/lib/alexandria/book_providers/siciliano.rb +7 -4
- data/lib/alexandria/book_providers/thalia.rb +5 -3
- data/lib/alexandria/book_providers/web.rb +11 -29
- data/lib/alexandria/book_providers/worldcat.rb +7 -5
- data/lib/alexandria/book_providers/z3950.rb +10 -7
- data/lib/alexandria/console.rb +5 -18
- data/lib/alexandria/execution_queue.rb +2 -1
- data/lib/alexandria/export_format.rb +47 -0
- data/lib/alexandria/export_library.rb +72 -180
- data/lib/alexandria/import_library.rb +14 -23
- data/lib/alexandria/import_library_csv.rb +3 -6
- data/lib/alexandria/library_collection.rb +78 -0
- data/lib/alexandria/library_sort_order.rb +43 -0
- data/lib/alexandria/library_store.rb +222 -0
- data/lib/alexandria/logging.rb +2 -0
- data/lib/alexandria/models/book.rb +8 -16
- data/lib/alexandria/models/library.rb +26 -308
- data/lib/alexandria/preferences.rb +7 -24
- data/lib/alexandria/scanners/cuecat.rb +3 -1
- data/lib/alexandria/smart_library.rb +32 -67
- data/lib/alexandria/ui/builder_base.rb +6 -26
- data/lib/alexandria/ui/callbacks.rb +8 -34
- data/lib/alexandria/ui/completion_models.rb +2 -1
- data/lib/alexandria/ui/dialogs/about_dialog.rb +35 -47
- data/lib/alexandria/ui/dialogs/acquire_dialog.rb +14 -30
- data/lib/alexandria/ui/dialogs/alert_dialog.rb +8 -17
- data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +10 -24
- data/lib/alexandria/ui/dialogs/book_properties_dialog.rb +17 -18
- data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +25 -41
- data/lib/alexandria/ui/dialogs/export_dialog.rb +48 -56
- data/lib/alexandria/ui/dialogs/import_dialog.rb +31 -51
- data/lib/alexandria/ui/dialogs/keep_bad_isbn_dialog.rb +33 -0
- data/lib/alexandria/ui/dialogs/misc_dialogs.rb +12 -25
- data/lib/alexandria/ui/dialogs/new_book_dialog.rb +57 -94
- data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +24 -42
- data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +9 -21
- data/lib/alexandria/ui/dialogs/preferences_dialog.rb +27 -32
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +5 -3
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +15 -12
- data/lib/alexandria/ui/icons.rb +11 -22
- data/lib/alexandria/ui/init.rb +3 -3
- data/lib/alexandria/ui/libraries_combo.rb +1 -0
- data/lib/alexandria/ui/listview.rb +5 -21
- data/lib/alexandria/ui/multi_drag_treeview.rb +20 -32
- data/lib/alexandria/ui/sidepane.rb +9 -24
- data/lib/alexandria/ui/ui_manager.rb +36 -60
- data/lib/alexandria/undo_manager.rb +1 -0
- data/lib/alexandria/version.rb +2 -2
- data/lib/alexandria/web_themes.rb +1 -0
- data/po/cs.po +0 -4
- data/po/cy.po +0 -4
- data/po/de.po +0 -4
- data/po/el.po +0 -4
- data/po/es.po +0 -4
- data/po/fr.po +0 -4
- data/po/ga.po +0 -4
- data/po/gl.po +0 -4
- data/po/it.po +0 -4
- data/po/ja.po +0 -4
- data/po/mk.po +0 -4
- data/po/nb.po +0 -4
- data/po/nl.po +0 -4
- data/po/pl.po +0 -4
- data/po/pt.po +0 -4
- data/po/pt_BR.po +0 -4
- data/po/ru.po +0 -4
- data/po/sk.po +0 -4
- data/po/sv.po +0 -4
- data/po/uk.po +0 -4
- data/po/zh_TW.po +0 -4
- data/schemas/alexandria.schemas +1 -1
- data/share/alexandria/glade/acquire_dialog__builder.glade +14 -11
- data/share/alexandria/glade/book_properties_dialog__builder.glade +170 -298
- data/share/alexandria/glade/main_app__builder.glade +22 -16
- data/share/alexandria/glade/new_book_dialog__builder.glade +26 -58
- data/share/alexandria/glade/preferences_dialog__builder.glade +249 -289
- data/share/gnome/help/alexandria/C/introduction.xml +0 -4
- data/share/gnome/help/alexandria/ja/introduction.xml +0 -4
- data/spec/alexandria/book_providers_spec.rb +1 -20
- data/spec/alexandria/console_spec.rb +32 -0
- data/spec/alexandria/export_library_spec.rb +141 -0
- data/spec/alexandria/library_spec.rb +24 -80
- data/spec/alexandria/library_store_spec.rb +37 -0
- data/spec/alexandria/smart_library_spec.rb +27 -22
- data/spec/alexandria/ui/dialogs/new_book_dialog_spec.rb +22 -0
- data/spec/alexandria/ui/dialogs_spec.rb +104 -38
- data/spec/end_to_end/basic_run_spec.rb +69 -0
- data/spec/spec_helper.rb +13 -25
- data/tasks/spec.rake +15 -2
- data/util/rake/fileinstall.rb +1 -0
- metadata +38 -16
- data/lib/alexandria/book_providers/deastore.rb +0 -265
- data/lib/alexandria/book_providers/mcu.rb +0 -182
@@ -1,24 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
# Copyright (C) 2010 Cathal Mc Ginley
|
5
|
-
# Copyright (C) 2014,2015 Matijs van Zuijlen
|
3
|
+
# This file is part of Alexandria.
|
6
4
|
#
|
7
|
-
#
|
8
|
-
|
9
|
-
# published by the Free Software Foundation; either version 2 of the
|
10
|
-
# License, or (at your option) any later version.
|
11
|
-
#
|
12
|
-
# Alexandria is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
-
# General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public
|
18
|
-
# License along with Alexandria; see the file COPYING. If not,
|
19
|
-
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
20
|
-
# Fifth Floor, Boston, MA 02110-1301 USA.
|
5
|
+
# See the file README.md for authorship and licensing information.
|
6
|
+
|
21
7
|
require 'gettext'
|
8
|
+
require 'tmpdir'
|
22
9
|
|
23
10
|
module Alexandria
|
24
11
|
class ImportFilter
|
@@ -72,7 +59,7 @@ module Alexandria
|
|
72
59
|
elsif ['.tc', '.bc'].include? filename[-3..-1]
|
73
60
|
begin
|
74
61
|
import_as_tellico_xml_archive(*args)
|
75
|
-
rescue => e
|
62
|
+
rescue StandardError => e
|
76
63
|
puts e.message
|
77
64
|
puts e.backtrace.join("\n>> ")
|
78
65
|
end
|
@@ -88,6 +75,7 @@ module Alexandria
|
|
88
75
|
on_iterate_cb, _on_error_cb)
|
89
76
|
puts 'Starting import_as_tellico_xml_archive... '
|
90
77
|
return nil unless system("unzip -qqt \"#{filename}\"")
|
78
|
+
|
91
79
|
tmpdir = File.join(Dir.tmpdir, 'tellico_export')
|
92
80
|
FileUtils.rm_rf(tmpdir) if File.exist?(tmpdir)
|
93
81
|
Dir.mkdir(tmpdir)
|
@@ -99,8 +87,10 @@ module Alexandria
|
|
99
87
|
raise unless ['bookcase', 'tellico'].include? xml.root.name
|
100
88
|
# FIXME: handle multiple collections
|
101
89
|
raise unless xml.root.elements.size == 1
|
90
|
+
|
102
91
|
collection = xml.root.elements[1]
|
103
92
|
raise unless collection.name == 'collection'
|
93
|
+
|
104
94
|
type = collection.attribute('type').value.to_i
|
105
95
|
raise unless (type == 2) || (type == 5)
|
106
96
|
|
@@ -129,7 +119,7 @@ module Alexandria
|
|
129
119
|
begin
|
130
120
|
book_elements[2] = book_elements[2].strip
|
131
121
|
book_elements[2] = Library.canonicalise_ean(book_elements[2])
|
132
|
-
rescue => ex
|
122
|
+
rescue StandardError => ex
|
133
123
|
puts book_elements[2]
|
134
124
|
puts ex.message
|
135
125
|
puts ex.backtrace.join("\n> ")
|
@@ -160,7 +150,7 @@ module Alexandria
|
|
160
150
|
library.save(book)
|
161
151
|
end
|
162
152
|
return [library, []]
|
163
|
-
rescue => e
|
153
|
+
rescue StandardError => e
|
164
154
|
puts e.message
|
165
155
|
return nil
|
166
156
|
end
|
@@ -196,7 +186,7 @@ module Alexandria
|
|
196
186
|
end
|
197
187
|
book.edition = dl_book.edition unless book.edition
|
198
188
|
cover = dl_cover
|
199
|
-
rescue
|
189
|
+
rescue StandardError
|
200
190
|
puts "failed to get cover for #{book.title} #{book.isbn}" if $DEBUG
|
201
191
|
# note failure
|
202
192
|
end
|
@@ -246,7 +236,7 @@ module Alexandria
|
|
246
236
|
# Let's preserve the failing isbns so we can report them later.
|
247
237
|
begin
|
248
238
|
[line.chomp, canonicalise_isbn(line.chomp)] unless line == "\n"
|
249
|
-
rescue => e
|
239
|
+
rescue StandardError => e
|
250
240
|
puts e.message
|
251
241
|
[line.chomp, nil]
|
252
242
|
end
|
@@ -254,6 +244,7 @@ module Alexandria
|
|
254
244
|
puts "Isbn list: #{isbn_list.inspect}"
|
255
245
|
isbn_list.compact!
|
256
246
|
return nil if isbn_list.empty?
|
247
|
+
|
257
248
|
max_iterations = isbn_list.length * 2
|
258
249
|
current_iteration = 1
|
259
250
|
books = []
|
@@ -266,7 +257,7 @@ module Alexandria
|
|
266
257
|
else
|
267
258
|
bad_isbns << isbn[0]
|
268
259
|
end
|
269
|
-
rescue => e
|
260
|
+
rescue StandardError => e
|
270
261
|
puts e.message
|
271
262
|
failed_lookup_isbns << isbn[1]
|
272
263
|
puts "NOTE : ignoring on_error_cb #{on_error_cb}"
|
@@ -90,12 +90,9 @@ module Alexandria
|
|
90
90
|
book.redd = true if count > 0
|
91
91
|
end
|
92
92
|
if row[@date_read]
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
book.redd = true
|
97
|
-
rescue
|
98
|
-
end
|
93
|
+
date = Date.strptime(str, '%d/%m/%y') # e.g. "14/01/10" => 2010-01-14
|
94
|
+
book.redd_when = date
|
95
|
+
book.redd = true
|
99
96
|
end
|
100
97
|
if row[@mainshelf]
|
101
98
|
if row[@mainshelf] == 'read'
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file is part of Alexandria.
|
4
|
+
#
|
5
|
+
# See the file README.md for authorship and licensing information.
|
6
|
+
|
7
|
+
require 'observer'
|
8
|
+
require 'singleton'
|
9
|
+
|
10
|
+
module Alexandria
|
11
|
+
class LibraryCollection
|
12
|
+
attr_reader :all_libraries, :ruined_books, :deleted_books
|
13
|
+
attr_accessor :library_store
|
14
|
+
|
15
|
+
include Observable
|
16
|
+
include Singleton
|
17
|
+
|
18
|
+
def reload
|
19
|
+
@all_libraries.clear
|
20
|
+
@all_libraries.concat(library_store.load_all_libraries)
|
21
|
+
@all_libraries.concat(library_store.load_all_smart_libraries)
|
22
|
+
|
23
|
+
ruined = []
|
24
|
+
deleted = []
|
25
|
+
all_regular_libraries.each { |library|
|
26
|
+
ruined += library.ruined_books
|
27
|
+
# make deleted books from each library accessible so we don't crash on smart libraries
|
28
|
+
deleted += library.deleted_books
|
29
|
+
}
|
30
|
+
@ruined_books = ruined
|
31
|
+
@deleted_books = deleted
|
32
|
+
end
|
33
|
+
|
34
|
+
def all_regular_libraries
|
35
|
+
@all_libraries.select { |x| x.is_a?(Library) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def all_smart_libraries
|
39
|
+
@all_libraries.select { |x| x.is_a?(SmartLibrary) }
|
40
|
+
end
|
41
|
+
|
42
|
+
LIBRARY_ADDED = 1
|
43
|
+
LIBRARY_REMOVED = 2
|
44
|
+
|
45
|
+
def add_library(library)
|
46
|
+
@all_libraries << library
|
47
|
+
notify(LIBRARY_ADDED, library)
|
48
|
+
end
|
49
|
+
|
50
|
+
def remove_library(library)
|
51
|
+
@all_libraries.delete(library)
|
52
|
+
notify(LIBRARY_REMOVED, library)
|
53
|
+
end
|
54
|
+
|
55
|
+
def really_delete_deleted_libraries
|
56
|
+
Library.really_delete_deleted_libraries
|
57
|
+
SmartLibrary.really_delete_deleted_libraries
|
58
|
+
end
|
59
|
+
|
60
|
+
def really_save_all_books
|
61
|
+
all_regular_libraries.each do |library|
|
62
|
+
library.each { |book| library.save(book, true) }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def initialize
|
69
|
+
@all_libraries = []
|
70
|
+
@deleted_books = []
|
71
|
+
end
|
72
|
+
|
73
|
+
def notify(action, library)
|
74
|
+
changed
|
75
|
+
notify_observers(self, action, library)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file is part of Alexandria.
|
4
|
+
#
|
5
|
+
# See the file README.md for authorship and licensing information.
|
6
|
+
|
7
|
+
module Alexandria
|
8
|
+
class LibrarySortOrder
|
9
|
+
include Logging
|
10
|
+
|
11
|
+
def initialize(book_attribute, ascending = true)
|
12
|
+
@book_attribute = book_attribute
|
13
|
+
@ascending = ascending
|
14
|
+
end
|
15
|
+
|
16
|
+
def sort(library)
|
17
|
+
sorted = library.sort_by do |book|
|
18
|
+
book.send(@book_attribute)
|
19
|
+
end
|
20
|
+
sorted.reverse! unless @ascending
|
21
|
+
sorted
|
22
|
+
rescue StandardError => ex
|
23
|
+
log.warn { "Could not sort library by #{@book_attribute.inspect}: #{ex.message}" }
|
24
|
+
library
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
"#{@book_attribute} #{@ascending ? '(ascending)' : '(descending)'}"
|
29
|
+
end
|
30
|
+
|
31
|
+
class Unsorted < LibrarySortOrder
|
32
|
+
def initialize; end
|
33
|
+
|
34
|
+
def sort(library)
|
35
|
+
library
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
'default order'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file is part of Alexandria.
|
4
|
+
#
|
5
|
+
# See the file README.md for authorship and licensing information.
|
6
|
+
|
7
|
+
module Alexandria
|
8
|
+
class LibraryStore
|
9
|
+
include Logging
|
10
|
+
|
11
|
+
FIX_BIGNUM_REGEX =
|
12
|
+
/loaned_since:\s*(\!ruby\/object\:Bignum\s*)?(\d+)\n/.freeze
|
13
|
+
|
14
|
+
include GetText
|
15
|
+
bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
|
16
|
+
|
17
|
+
def initialize(dir)
|
18
|
+
@dir = dir
|
19
|
+
end
|
20
|
+
|
21
|
+
def load_all_libraries
|
22
|
+
a = []
|
23
|
+
begin
|
24
|
+
Dir.entries(library_dir).each do |file|
|
25
|
+
# Skip hidden files.
|
26
|
+
next if file =~ /^\./
|
27
|
+
# Skip non-directory files.
|
28
|
+
next unless File.stat(File.join(library_dir, file)).directory?
|
29
|
+
|
30
|
+
a << load_library(file)
|
31
|
+
end
|
32
|
+
rescue Errno::ENOENT
|
33
|
+
FileUtils.mkdir_p(library_dir)
|
34
|
+
end
|
35
|
+
# Create the default library if there is no library yet.
|
36
|
+
|
37
|
+
a << load_library(_('My Library')) if a.empty?
|
38
|
+
|
39
|
+
a
|
40
|
+
end
|
41
|
+
|
42
|
+
def load_library(name)
|
43
|
+
test = [0, nil]
|
44
|
+
ruined_books = []
|
45
|
+
library = Library.new(name, self)
|
46
|
+
FileUtils.mkdir_p(library.path) unless File.exist?(library.path)
|
47
|
+
Dir.chdir(library.path) do
|
48
|
+
Dir['*' + Library::EXT[:book]].each do |filename|
|
49
|
+
test[1] = filename if (test[0]).zero?
|
50
|
+
|
51
|
+
unless File.size? test[1]
|
52
|
+
log.warn { "Book file #{test[1]} was empty" }
|
53
|
+
md = /([\dxX]{10,13})#{Library::EXT[:book]}/.match(filename)
|
54
|
+
if md
|
55
|
+
file_isbn = md[1]
|
56
|
+
ruined_books << [nil, file_isbn, library]
|
57
|
+
else
|
58
|
+
log.warn { "Filename #{filename} does not contain an ISBN" }
|
59
|
+
# TODO: delete this file...
|
60
|
+
end
|
61
|
+
next
|
62
|
+
end
|
63
|
+
book = regularize_book_from_yaml(test[1])
|
64
|
+
old_isbn = book.isbn
|
65
|
+
old_pub_year = book.publishing_year
|
66
|
+
begin
|
67
|
+
raise "Not a book: #{book.inspect}" unless book.is_a?(Book)
|
68
|
+
|
69
|
+
ean = Library.canonicalise_ean(book.isbn)
|
70
|
+
book.isbn = ean if ean
|
71
|
+
|
72
|
+
book.publishing_year = book.publishing_year.to_i unless book.publishing_year.nil?
|
73
|
+
|
74
|
+
# Or if isbn has changed
|
75
|
+
raise "#{test[1]} isbn is not okay" unless book.isbn == old_isbn
|
76
|
+
|
77
|
+
# Re-save book if Alexandria::DATA_VERSION changes
|
78
|
+
raise "#{test[1]} version is not okay" unless book.version == Alexandria::DATA_VERSION
|
79
|
+
|
80
|
+
# Or if publishing year has changed
|
81
|
+
raise "#{test[1]} pub year is not okay" unless book.publishing_year == old_pub_year
|
82
|
+
|
83
|
+
# ruined_books << [book, book.isbn, library]
|
84
|
+
book.library = library.name
|
85
|
+
|
86
|
+
## TODO copy cover image file, if necessary
|
87
|
+
# due to #26909 cover files for books without ISBN are re-saved as "g#{ident}.cover"
|
88
|
+
if book.isbn.nil? || book.isbn.empty?
|
89
|
+
if File.exist? library.old_cover(book)
|
90
|
+
log.debug { "#{library.name}; book #{book.title} has no ISBN, fixing cover image" }
|
91
|
+
FileUtils::Verbose.mv(library.old_cover(book), library.cover(book))
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
library << book
|
96
|
+
rescue StandardError
|
97
|
+
book.version = Alexandria::DATA_VERSION
|
98
|
+
savedfilename = library.simple_save(book)
|
99
|
+
test[0] = test[0] + 1
|
100
|
+
test[1] = savedfilename
|
101
|
+
|
102
|
+
# retries the Dir.each block...
|
103
|
+
# but gives up after three tries
|
104
|
+
redo unless test[0] > 2
|
105
|
+
else
|
106
|
+
test = [0, nil]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Since 0.4.0 the cover files '_small.jpg' and
|
111
|
+
# '_medium.jpg' have been deprecated for a single medium
|
112
|
+
# cover file named '.cover'.
|
113
|
+
|
114
|
+
Dir['*' + '_medium.jpg'].each do |medium_cover|
|
115
|
+
FileUtils.mv(medium_cover,
|
116
|
+
medium_cover.sub(/_medium\.jpg$/,
|
117
|
+
Library::EXT[:cover]))
|
118
|
+
end
|
119
|
+
|
120
|
+
Dir['*' + Library::EXT[:cover]].each do |cover|
|
121
|
+
next if cover[0] == 'g'
|
122
|
+
|
123
|
+
md = /(.+)\.cover/.match(cover)
|
124
|
+
ean = Library.canonicalise_ean(md[1]) || md[1]
|
125
|
+
FileUtils.mv(cover, ean + Library::EXT[:cover]) unless cover == ean + Library::EXT[:cover]
|
126
|
+
end
|
127
|
+
|
128
|
+
FileUtils.rm_f(Dir['*_small.jpg'])
|
129
|
+
end
|
130
|
+
library.ruined_books = ruined_books
|
131
|
+
|
132
|
+
library
|
133
|
+
end
|
134
|
+
|
135
|
+
def load_all_smart_libraries
|
136
|
+
a = []
|
137
|
+
begin
|
138
|
+
# Deserialize smart libraries.
|
139
|
+
Dir.chdir(smart_library_dir) do
|
140
|
+
Dir['*' + SmartLibrary::EXT].each do |filename|
|
141
|
+
# Skip non-regular files.
|
142
|
+
next unless File.stat(filename).file?
|
143
|
+
|
144
|
+
text = IO.read(filename)
|
145
|
+
hash = YAML.safe_load(text, permitted_classes: [Symbol])
|
146
|
+
smart_library = SmartLibrary.from_hash(hash, self)
|
147
|
+
a << smart_library
|
148
|
+
end
|
149
|
+
end
|
150
|
+
rescue Errno::ENOENT
|
151
|
+
# First run and no smart libraries yet? Provide some default
|
152
|
+
# ones.
|
153
|
+
SmartLibrary.sample_smart_libraries(self).each do |smart_library|
|
154
|
+
smart_library.save
|
155
|
+
a << smart_library
|
156
|
+
end
|
157
|
+
end
|
158
|
+
a.each(&:refilter)
|
159
|
+
a
|
160
|
+
end
|
161
|
+
|
162
|
+
def library_dir
|
163
|
+
@dir
|
164
|
+
end
|
165
|
+
|
166
|
+
def smart_library_dir
|
167
|
+
File.join(@dir, '.smart_libraries')
|
168
|
+
end
|
169
|
+
|
170
|
+
private
|
171
|
+
|
172
|
+
def regularize_book_from_yaml(name)
|
173
|
+
text = IO.read(name)
|
174
|
+
|
175
|
+
# Code to remove the mystery string in books imported from Amazon
|
176
|
+
# (In the past, still?) To allow ruby-amazon to be removed.
|
177
|
+
|
178
|
+
# The string is removed on load, but can't make it stick, maybe has to do with cache
|
179
|
+
|
180
|
+
if text =~ /!str:Amazon::Search::Response/
|
181
|
+
log.debug { "Removing Ruby/Amazon strings from #{name}" }
|
182
|
+
text.gsub!('!str:Amazon::Search::Response', '')
|
183
|
+
end
|
184
|
+
|
185
|
+
# Backward compatibility with versions <= 0.6.0, where the
|
186
|
+
# loaned_since field was a numeric.
|
187
|
+
if (md = FIX_BIGNUM_REGEX.match(text))
|
188
|
+
new_yaml = Time.at(md[2].to_i).to_yaml
|
189
|
+
# Remove the "---" prefix.
|
190
|
+
new_yaml.sub!(/^\s*\-+\s*/, '')
|
191
|
+
text.sub!(md[0], "loaned_since: #{new_yaml}\n")
|
192
|
+
end
|
193
|
+
|
194
|
+
# TODO: Ensure book loading passes through Book#initialize
|
195
|
+
book = YAML.safe_load(text, permitted_classes: [Book, Time])
|
196
|
+
|
197
|
+
unless book.isbn.class == String
|
198
|
+
# HACK
|
199
|
+
md = /isbn: (.+)/.match(text)
|
200
|
+
if md
|
201
|
+
string_isbn = md[1].strip
|
202
|
+
book.isbn = string_isbn
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# another HACK of the same type as above
|
207
|
+
unless book.saved_ident.class == String
|
208
|
+
|
209
|
+
md2 = /saved_ident: (.+)/.match(text)
|
210
|
+
if md2
|
211
|
+
string_saved_ident = md2[1].strip
|
212
|
+
log.debug { "fixing saved_ident #{book.saved_ident} -> #{string_saved_ident}" }
|
213
|
+
book.saved_ident = string_saved_ident
|
214
|
+
end
|
215
|
+
end
|
216
|
+
if (book.isbn.class == String) && book.isbn.empty?
|
217
|
+
book.isbn = nil # save trouble later
|
218
|
+
end
|
219
|
+
book
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|