alexandria-book-collection-manager 0.7.2 → 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +9 -0
- data/.github/workflows/ruby.yml +77 -0
- data/.gitignore +5 -1
- data/.hound.yml +2 -0
- data/.rubocop.yml +87 -37
- data/.rubocop_todo.yml +62 -191
- data/.simplecov +5 -2
- data/CHANGELOG.md +63 -0
- data/Gemfile +4 -3
- data/INSTALL.md +26 -14
- data/README.md +52 -42
- data/Rakefile +93 -109
- data/TODO.md +9 -1
- data/alexandria-book-collection-manager.gemspec +50 -43
- data/bin/alexandria +30 -53
- data/doc/FAQ +2 -6
- data/doc/dependency_decisions.yml +27 -8
- data/lib/alexandria.rb +27 -37
- data/lib/alexandria/about.rb +50 -50
- data/lib/alexandria/book_providers.rb +90 -97
- data/lib/alexandria/book_providers/adlibris.rb +41 -76
- data/lib/alexandria/book_providers/amazon_aws.rb +96 -100
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +295 -322
- data/lib/alexandria/book_providers/barnes_and_noble.rb +48 -45
- data/lib/alexandria/book_providers/douban.rb +26 -42
- data/lib/alexandria/book_providers/proxis.rb +44 -55
- data/lib/alexandria/book_providers/pseudomarc.rb +77 -85
- data/lib/alexandria/book_providers/siciliano.rb +64 -65
- data/lib/alexandria/book_providers/thalia.rb +42 -41
- data/lib/alexandria/book_providers/web.rb +15 -33
- data/lib/alexandria/book_providers/worldcat.rb +70 -97
- data/lib/alexandria/book_providers/z3950.rb +160 -173
- data/lib/alexandria/config.rb +1 -1
- data/lib/alexandria/console.rb +8 -21
- data/lib/alexandria/default_preferences.rb +37 -0
- data/lib/alexandria/execution_queue.rb +15 -13
- data/lib/alexandria/export_format.rb +47 -0
- data/lib/alexandria/export_library.rb +193 -300
- data/lib/alexandria/import_library.rb +108 -141
- data/lib/alexandria/import_library_csv.rb +43 -46
- 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 +11 -13
- data/lib/alexandria/models/book.rb +13 -20
- data/lib/alexandria/models/library.rb +81 -353
- data/lib/alexandria/net.rb +5 -6
- data/lib/alexandria/preferences.rb +73 -87
- data/lib/alexandria/scanners.rb +2 -2
- data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +20 -18
- data/lib/alexandria/scanners/keyboard.rb +8 -8
- data/lib/alexandria/smart_library.rb +133 -170
- data/lib/alexandria/ui.rb +15 -15
- data/lib/alexandria/ui/about_dialog.rb +49 -0
- data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +119 -136
- 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} +16 -15
- data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +39 -52
- data/lib/alexandria/ui/book_properties_dialog_base.rb +318 -0
- data/lib/alexandria/ui/builder_base.rb +7 -27
- data/lib/alexandria/ui/calendar_popup.rb +58 -0
- data/lib/alexandria/ui/callbacks.rb +189 -183
- data/lib/alexandria/ui/completion_models.rb +10 -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 +7 -7
- data/lib/alexandria/ui/error_dialog.rb +25 -0
- data/lib/alexandria/ui/export_dialog.rb +142 -0
- data/lib/alexandria/ui/icons.rb +47 -63
- data/lib/alexandria/ui/iconview.rb +12 -10
- data/lib/alexandria/ui/iconview_tooltips.rb +41 -54
- data/lib/alexandria/ui/import_dialog.rb +157 -0
- data/lib/alexandria/ui/init.rb +21 -33
- data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
- data/lib/alexandria/ui/libraries_combo.rb +16 -14
- data/lib/alexandria/ui/listview.rb +73 -87
- data/lib/alexandria/ui/main_app.rb +24 -26
- data/lib/alexandria/ui/misc_dialogs.rb +10 -0
- data/lib/alexandria/ui/multi_drag_treeview.rb +28 -41
- data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +156 -194
- 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} +56 -68
- 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/smart_library_properties_dialog_base.rb +242 -0
- data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
- data/lib/alexandria/ui/sound.rb +11 -13
- data/lib/alexandria/ui/ui_manager.rb +236 -251
- data/lib/alexandria/undo_manager.rb +1 -0
- data/lib/alexandria/version.rb +4 -19
- data/lib/alexandria/web_themes.rb +22 -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 +1017 -974
- 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 +75 -171
- data/spec/alexandria/book_spec.rb +12 -10
- data/spec/alexandria/console_spec.rb +27 -0
- data/spec/alexandria/export_library_spec.rb +130 -0
- data/spec/alexandria/library_spec.rb +128 -172
- data/spec/alexandria/library_store_spec.rb +37 -0
- data/spec/alexandria/preferences_spec.rb +44 -17
- data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
- data/spec/alexandria/smart_library_spec.rb +30 -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 +36 -0
- data/spec/alexandria/ui/icons_spec.rb +26 -0
- data/spec/alexandria/ui/iconview_spec.rb +7 -21
- data/spec/alexandria/ui/import_dialog_spec.rb +46 -0
- data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
- data/spec/alexandria/ui/main_app_spec.rb +7 -34
- 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 +49 -0
- data/spec/alexandria/ui/sound_spec.rb +2 -2
- data/spec/alexandria/ui/ui_manager_spec.rb +43 -20
- data/spec/end_to_end/basic_run_spec.rb +52 -0
- data/spec/spec_helper.rb +65 -33
- data/tasks/setup.rb +2 -2
- data/tasks/spec.rake +16 -3
- data/util/rake/fileinstall.rb +39 -35
- data/util/rake/gettextgenerate.rb +7 -7
- data/util/rake/omfgenerate.rb +7 -7
- metadata +178 -45
- data/dogtail/basic_run_test.py +0 -9
- data/lib/alexandria/book_providers/deastore.rb +0 -265
- data/lib/alexandria/book_providers/mcu.rb +0 -182
- data/lib/alexandria/book_providers/renaud.rb +0 -149
- data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -61
- data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -72
- data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -51
- data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +0 -426
- 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 -87
- 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 -568
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -59
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +0 -420
- data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
- data/spec/alexandria/ui/dialogs_spec.rb +0 -96
- data/spec/alexandria/ui/sidepane_spec.rb +0 -29
- data/spec/alexandria/ui/ui_utilities_spec.rb +0 -62
- data/spec/alexandria/utilities_spec.rb +0 -52
- data/tasks/dogtail.rake +0 -6
@@ -0,0 +1,79 @@
|
|
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 do |library|
|
26
|
+
ruined += library.ruined_books
|
27
|
+
# make deleted books from each library accessible so we don't crash on
|
28
|
+
# smart libraries
|
29
|
+
deleted += library.deleted_books
|
30
|
+
end
|
31
|
+
@ruined_books = ruined
|
32
|
+
@deleted_books = deleted
|
33
|
+
end
|
34
|
+
|
35
|
+
def all_regular_libraries
|
36
|
+
@all_libraries.select { |x| x.is_a?(Library) }
|
37
|
+
end
|
38
|
+
|
39
|
+
def all_smart_libraries
|
40
|
+
@all_libraries.select { |x| x.is_a?(SmartLibrary) }
|
41
|
+
end
|
42
|
+
|
43
|
+
LIBRARY_ADDED = 1
|
44
|
+
LIBRARY_REMOVED = 2
|
45
|
+
|
46
|
+
def add_library(library)
|
47
|
+
@all_libraries << library
|
48
|
+
notify(LIBRARY_ADDED, library)
|
49
|
+
end
|
50
|
+
|
51
|
+
def remove_library(library)
|
52
|
+
@all_libraries.delete(library)
|
53
|
+
notify(LIBRARY_REMOVED, library)
|
54
|
+
end
|
55
|
+
|
56
|
+
def really_delete_deleted_libraries
|
57
|
+
Library.really_delete_deleted_libraries
|
58
|
+
SmartLibrary.really_delete_deleted_libraries
|
59
|
+
end
|
60
|
+
|
61
|
+
def really_save_all_books
|
62
|
+
all_regular_libraries.each do |library|
|
63
|
+
library.each { |book| library.save(book, true) }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def initialize
|
70
|
+
@all_libraries = []
|
71
|
+
@deleted_books = []
|
72
|
+
end
|
73
|
+
|
74
|
+
def notify(action, library)
|
75
|
+
changed
|
76
|
+
notify_observers(self, action, library)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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
|
33
|
+
super(nil, nil)
|
34
|
+
end
|
35
|
+
|
36
|
+
def sort(library)
|
37
|
+
library
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
"default order"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,233 @@
|
|
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
|
+
%r{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.start_with?(".")
|
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]].sort.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 format(_("Not a book: %<book>s"), book.inspect) unless book.is_a?(Book)
|
68
|
+
|
69
|
+
ean = Library.canonicalise_ean(book.isbn)
|
70
|
+
book.isbn = ean if ean
|
71
|
+
|
72
|
+
unless book.publishing_year.nil?
|
73
|
+
book.publishing_year = book.publishing_year.to_i
|
74
|
+
end
|
75
|
+
|
76
|
+
# Or if isbn has changed
|
77
|
+
unless book.isbn == old_isbn
|
78
|
+
raise format(_("%<file>s isbn is not okay"), file: test[1])
|
79
|
+
end
|
80
|
+
|
81
|
+
# Re-save book if Alexandria::DATA_VERSION changes
|
82
|
+
unless book.version == Alexandria::DATA_VERSION
|
83
|
+
raise format(_("%<file>s version is not okay"), file: test[1])
|
84
|
+
end
|
85
|
+
|
86
|
+
# Or if publishing year has changed
|
87
|
+
unless book.publishing_year == old_pub_year
|
88
|
+
raise format(_("%<file>s pub year is not okay"), file: test[1])
|
89
|
+
end
|
90
|
+
|
91
|
+
# ruined_books << [book, book.isbn, library]
|
92
|
+
book.library = library.name
|
93
|
+
|
94
|
+
## TODO copy cover image file, if necessary
|
95
|
+
# due to #26909 cover files for books without ISBN are re-saved as
|
96
|
+
# "g#{ident}.cover"
|
97
|
+
if (book.isbn.nil? || book.isbn.empty?) && File.exist?(library.old_cover(book))
|
98
|
+
log.debug do
|
99
|
+
"#{library.name}; book #{book.title} has no ISBN, fixing cover image"
|
100
|
+
end
|
101
|
+
FileUtils::Verbose.mv(library.old_cover(book), library.cover(book))
|
102
|
+
end
|
103
|
+
|
104
|
+
library << book
|
105
|
+
rescue StandardError
|
106
|
+
book.version = Alexandria::DATA_VERSION
|
107
|
+
savedfilename = library.simple_save(book)
|
108
|
+
test[0] = test[0] + 1
|
109
|
+
test[1] = savedfilename
|
110
|
+
|
111
|
+
# retries the Dir.each block...
|
112
|
+
# but gives up after three tries
|
113
|
+
redo unless test[0] > 2
|
114
|
+
else
|
115
|
+
test = [0, nil]
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# Since 0.4.0 the cover files '_small.jpg' and
|
120
|
+
# '_medium.jpg' have been deprecated for a single medium
|
121
|
+
# cover file named '.cover'.
|
122
|
+
|
123
|
+
Dir["*" + "_medium.jpg"].each do |medium_cover|
|
124
|
+
FileUtils.mv(medium_cover,
|
125
|
+
medium_cover.sub(/_medium\.jpg$/,
|
126
|
+
Library::EXT[:cover]))
|
127
|
+
end
|
128
|
+
|
129
|
+
Dir["*" + Library::EXT[:cover]].each do |cover|
|
130
|
+
next if cover[0] == "g"
|
131
|
+
|
132
|
+
md = /(.+)\.cover/.match(cover)
|
133
|
+
ean = Library.canonicalise_ean(md[1]) || md[1]
|
134
|
+
unless cover == ean + Library::EXT[:cover]
|
135
|
+
FileUtils.mv(cover, ean + Library::EXT[:cover])
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
FileUtils.rm_f(Dir["*_small.jpg"])
|
140
|
+
end
|
141
|
+
library.ruined_books = ruined_books
|
142
|
+
|
143
|
+
library
|
144
|
+
end
|
145
|
+
|
146
|
+
def load_all_smart_libraries
|
147
|
+
a = []
|
148
|
+
begin
|
149
|
+
# Deserialize smart libraries.
|
150
|
+
Dir.chdir(smart_library_dir) do
|
151
|
+
Dir["*" + SmartLibrary::EXT].each do |filename|
|
152
|
+
# Skip non-regular files.
|
153
|
+
next unless File.stat(filename).file?
|
154
|
+
|
155
|
+
text = IO.read(filename)
|
156
|
+
hash = YAML.safe_load(text, permitted_classes: [Symbol])
|
157
|
+
smart_library = SmartLibrary.from_hash(hash, self)
|
158
|
+
a << smart_library
|
159
|
+
end
|
160
|
+
end
|
161
|
+
rescue Errno::ENOENT
|
162
|
+
# First run and no smart libraries yet? Provide some default
|
163
|
+
# ones.
|
164
|
+
SmartLibrary.sample_smart_libraries(self).each do |smart_library|
|
165
|
+
smart_library.save
|
166
|
+
a << smart_library
|
167
|
+
end
|
168
|
+
end
|
169
|
+
a.each(&:refilter)
|
170
|
+
a
|
171
|
+
end
|
172
|
+
|
173
|
+
def library_dir
|
174
|
+
@dir
|
175
|
+
end
|
176
|
+
|
177
|
+
def smart_library_dir
|
178
|
+
File.join(@dir, ".smart_libraries")
|
179
|
+
end
|
180
|
+
|
181
|
+
private
|
182
|
+
|
183
|
+
def regularize_book_from_yaml(name)
|
184
|
+
text = IO.read(name)
|
185
|
+
|
186
|
+
# Code to remove the mystery string in books imported from Amazon
|
187
|
+
# (In the past, still?) To allow ruby-amazon to be removed.
|
188
|
+
|
189
|
+
# The string is removed on load, but can't make it stick, maybe has to do with cache
|
190
|
+
|
191
|
+
if /!str:Amazon::Search::Response/.match?(text)
|
192
|
+
log.debug { "Removing Ruby/Amazon strings from #{name}" }
|
193
|
+
text.gsub!("!str:Amazon::Search::Response", "")
|
194
|
+
end
|
195
|
+
|
196
|
+
# Backward compatibility with versions <= 0.6.0, where the
|
197
|
+
# loaned_since field was a numeric.
|
198
|
+
if (md = FIX_BIGNUM_REGEX.match(text))
|
199
|
+
new_yaml = Time.at(md[2].to_i).to_yaml
|
200
|
+
# Remove the "---" prefix.
|
201
|
+
new_yaml.sub!(/^\s*-+\s*/, "")
|
202
|
+
text.sub!(md[0], "loaned_since: #{new_yaml}\n")
|
203
|
+
end
|
204
|
+
|
205
|
+
# TODO: Ensure book loading passes through Book#initialize
|
206
|
+
book = YAML.safe_load(text, permitted_classes: [Book, Time])
|
207
|
+
|
208
|
+
unless book.isbn.instance_of? String
|
209
|
+
# HACK
|
210
|
+
md = /isbn: (.+)/.match(text)
|
211
|
+
if md
|
212
|
+
string_isbn = md[1].strip
|
213
|
+
book.isbn = string_isbn
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
# another HACK of the same type as above
|
218
|
+
unless book.saved_ident.instance_of? String
|
219
|
+
|
220
|
+
md2 = /saved_ident: (.+)/.match(text)
|
221
|
+
if md2
|
222
|
+
string_saved_ident = md2[1].strip
|
223
|
+
log.debug { "fixing saved_ident #{book.saved_ident} -> #{string_saved_ident}" }
|
224
|
+
book.saved_ident = string_saved_ident
|
225
|
+
end
|
226
|
+
end
|
227
|
+
if (book.isbn.instance_of? String) && book.isbn.empty?
|
228
|
+
book.isbn = nil # save trouble later
|
229
|
+
end
|
230
|
+
book
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
data/lib/alexandria/logging.rb
CHANGED
@@ -18,19 +18,21 @@
|
|
18
18
|
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
19
19
|
# Fifth Floor, Boston, MA 02110-1301 USA.
|
20
20
|
|
21
|
-
require
|
22
|
-
require
|
21
|
+
require "logger"
|
22
|
+
require "forwardable"
|
23
23
|
|
24
24
|
module Alexandria
|
25
25
|
# A Logger subclass which accepts a source for log messages
|
26
26
|
# in order to improve legibility of the logs.
|
27
27
|
# The source should usually be +self+, whether that be a Class, Module
|
28
|
-
# or Object. A
|
28
|
+
# or Object. A LogWrapper can be used to simplify this procedure.
|
29
29
|
class Logger < ::Logger
|
30
30
|
def add(severity, message = nil, source = nil, progname = nil, &block)
|
31
31
|
return super(severity, message, progname, &block) if source.nil?
|
32
|
+
|
32
33
|
category = self.class.category(source)
|
33
34
|
return super(severity, progname, category) unless block_given?
|
35
|
+
|
34
36
|
category = "#{category} #{progname}" if progname
|
35
37
|
super(severity, message, category, &block)
|
36
38
|
end
|
@@ -80,9 +82,9 @@ module Alexandria
|
|
80
82
|
|
81
83
|
def <<(msg)
|
82
84
|
if msg.respond_to? :backtrace
|
83
|
-
msg.backtrace.each
|
85
|
+
msg.backtrace.each do |line|
|
84
86
|
@logger << " #{line} \n"
|
85
|
-
|
87
|
+
end
|
86
88
|
else
|
87
89
|
@logger << msg + "\n"
|
88
90
|
end
|
@@ -116,7 +118,7 @@ module Alexandria
|
|
116
118
|
module Logging
|
117
119
|
module ClassMethods
|
118
120
|
def log
|
119
|
-
@
|
121
|
+
@log ||= LogWrapper.new(Alexandria.log, self)
|
120
122
|
end
|
121
123
|
end
|
122
124
|
|
@@ -125,17 +127,15 @@ module Alexandria
|
|
125
127
|
end
|
126
128
|
|
127
129
|
def log
|
128
|
-
@
|
130
|
+
@log ||= LogWrapper.new(Alexandria.log, self)
|
129
131
|
end
|
130
132
|
end
|
131
133
|
|
132
|
-
private
|
133
|
-
|
134
134
|
# Creates the Logger for Alexandria
|
135
135
|
def self.create_logger
|
136
|
-
logger = Alexandria::Logger.new(
|
136
|
+
logger = Alexandria::Logger.new($stderr)
|
137
137
|
|
138
|
-
level = ENV[
|
138
|
+
level = ENV["LOGLEVEL"] ? ENV["LOGLEVEL"].intern : nil
|
139
139
|
if [:FATAL, :ERROR, :WARN, :INFO, :DEBUG].include? level
|
140
140
|
logger.level = Logger.const_get(level)
|
141
141
|
else
|
@@ -148,8 +148,6 @@ module Alexandria
|
|
148
148
|
|
149
149
|
@@logger = create_logger
|
150
150
|
|
151
|
-
public
|
152
|
-
|
153
151
|
# Returns the Logger for Alexandria
|
154
152
|
def self.log
|
155
153
|
@@logger
|
@@ -1,33 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
3
|
+
# This file is part of Alexandria.
|
4
4
|
#
|
5
|
-
#
|
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.
|
5
|
+
# See the file README.md for authorship and licensing information.
|
19
6
|
|
20
7
|
module Alexandria
|
21
8
|
class Book
|
22
9
|
attr_accessor :title, :authors, :isbn, :publisher, :publishing_year,
|
23
10
|
:edition, :notes, :loaned, :loaned_since,
|
24
|
-
:loaned_to, :saved_ident, :redd, :redd_when, :own, :want,
|
11
|
+
:loaned_to, :saved_ident, :redd, :redd_when, :own, :want,
|
12
|
+
:tags, :version, :library
|
25
13
|
|
26
14
|
attr_reader :rating
|
27
15
|
|
28
16
|
DEFAULT_RATING = 0
|
29
17
|
MAX_RATING_STARS = 5
|
30
|
-
VALID_RATINGS = (DEFAULT_RATING..MAX_RATING_STARS)
|
18
|
+
VALID_RATINGS = (DEFAULT_RATING..MAX_RATING_STARS).freeze
|
31
19
|
|
32
20
|
def initialize(title, authors, isbn, publisher, publishing_year,
|
33
21
|
edition)
|
@@ -37,7 +25,7 @@ module Alexandria
|
|
37
25
|
@isbn = isbn
|
38
26
|
@publisher = publisher
|
39
27
|
@edition = edition # actually used for binding! (i.e. paperback or hardback)
|
40
|
-
@notes =
|
28
|
+
@notes = ""
|
41
29
|
@saved_ident = ident
|
42
30
|
@publishing_year = publishing_year
|
43
31
|
@redd = false
|
@@ -56,6 +44,7 @@ module Alexandria
|
|
56
44
|
|
57
45
|
def rating=(rating)
|
58
46
|
raise ArgumentError unless VALID_RATINGS.include? rating
|
47
|
+
|
59
48
|
@rating = rating
|
60
49
|
end
|
61
50
|
|
@@ -75,8 +64,12 @@ module Alexandria
|
|
75
64
|
own || false
|
76
65
|
end
|
77
66
|
|
78
|
-
def ==(
|
79
|
-
|
67
|
+
def ==(other)
|
68
|
+
other.is_a?(self.class) && (ident == other.ident)
|
69
|
+
end
|
70
|
+
|
71
|
+
def inspect
|
72
|
+
"#<Alexandria::Book title: #{@title}>"
|
80
73
|
end
|
81
74
|
end
|
82
75
|
end
|