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.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.hound.yml +2 -0
  4. data/.rubocop.yml +4 -4
  5. data/.rubocop_todo.yml +55 -82
  6. data/CHANGELOG.md +17 -0
  7. data/INSTALL.md +3 -3
  8. data/README.md +1 -2
  9. data/Rakefile +14 -33
  10. data/TODO.md +9 -1
  11. data/alexandria-book-collection-manager.gemspec +4 -3
  12. data/bin/alexandria +21 -34
  13. data/doc/FAQ +2 -5
  14. data/lib/alexandria.rb +4 -16
  15. data/lib/alexandria/book_providers.rb +5 -7
  16. data/lib/alexandria/book_providers/adlibris.rb +5 -3
  17. data/lib/alexandria/book_providers/amazon_aws.rb +3 -1
  18. data/lib/alexandria/book_providers/amazon_ecs_util.rb +8 -0
  19. data/lib/alexandria/book_providers/barnes_and_noble.rb +7 -4
  20. data/lib/alexandria/book_providers/douban.rb +1 -1
  21. data/lib/alexandria/book_providers/proxis.rb +11 -27
  22. data/lib/alexandria/book_providers/renaud.rb +9 -3
  23. data/lib/alexandria/book_providers/siciliano.rb +7 -4
  24. data/lib/alexandria/book_providers/thalia.rb +5 -3
  25. data/lib/alexandria/book_providers/web.rb +11 -29
  26. data/lib/alexandria/book_providers/worldcat.rb +7 -5
  27. data/lib/alexandria/book_providers/z3950.rb +10 -7
  28. data/lib/alexandria/console.rb +5 -18
  29. data/lib/alexandria/execution_queue.rb +2 -1
  30. data/lib/alexandria/export_format.rb +47 -0
  31. data/lib/alexandria/export_library.rb +72 -180
  32. data/lib/alexandria/import_library.rb +14 -23
  33. data/lib/alexandria/import_library_csv.rb +3 -6
  34. data/lib/alexandria/library_collection.rb +78 -0
  35. data/lib/alexandria/library_sort_order.rb +43 -0
  36. data/lib/alexandria/library_store.rb +222 -0
  37. data/lib/alexandria/logging.rb +2 -0
  38. data/lib/alexandria/models/book.rb +8 -16
  39. data/lib/alexandria/models/library.rb +26 -308
  40. data/lib/alexandria/preferences.rb +7 -24
  41. data/lib/alexandria/scanners/cuecat.rb +3 -1
  42. data/lib/alexandria/smart_library.rb +32 -67
  43. data/lib/alexandria/ui/builder_base.rb +6 -26
  44. data/lib/alexandria/ui/callbacks.rb +8 -34
  45. data/lib/alexandria/ui/completion_models.rb +2 -1
  46. data/lib/alexandria/ui/dialogs/about_dialog.rb +35 -47
  47. data/lib/alexandria/ui/dialogs/acquire_dialog.rb +14 -30
  48. data/lib/alexandria/ui/dialogs/alert_dialog.rb +8 -17
  49. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +10 -24
  50. data/lib/alexandria/ui/dialogs/book_properties_dialog.rb +17 -18
  51. data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +25 -41
  52. data/lib/alexandria/ui/dialogs/export_dialog.rb +48 -56
  53. data/lib/alexandria/ui/dialogs/import_dialog.rb +31 -51
  54. data/lib/alexandria/ui/dialogs/keep_bad_isbn_dialog.rb +33 -0
  55. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +12 -25
  56. data/lib/alexandria/ui/dialogs/new_book_dialog.rb +57 -94
  57. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +24 -42
  58. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +9 -21
  59. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +27 -32
  60. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +5 -3
  61. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +15 -12
  62. data/lib/alexandria/ui/icons.rb +11 -22
  63. data/lib/alexandria/ui/init.rb +3 -3
  64. data/lib/alexandria/ui/libraries_combo.rb +1 -0
  65. data/lib/alexandria/ui/listview.rb +5 -21
  66. data/lib/alexandria/ui/multi_drag_treeview.rb +20 -32
  67. data/lib/alexandria/ui/sidepane.rb +9 -24
  68. data/lib/alexandria/ui/ui_manager.rb +36 -60
  69. data/lib/alexandria/undo_manager.rb +1 -0
  70. data/lib/alexandria/version.rb +2 -2
  71. data/lib/alexandria/web_themes.rb +1 -0
  72. data/po/cs.po +0 -4
  73. data/po/cy.po +0 -4
  74. data/po/de.po +0 -4
  75. data/po/el.po +0 -4
  76. data/po/es.po +0 -4
  77. data/po/fr.po +0 -4
  78. data/po/ga.po +0 -4
  79. data/po/gl.po +0 -4
  80. data/po/it.po +0 -4
  81. data/po/ja.po +0 -4
  82. data/po/mk.po +0 -4
  83. data/po/nb.po +0 -4
  84. data/po/nl.po +0 -4
  85. data/po/pl.po +0 -4
  86. data/po/pt.po +0 -4
  87. data/po/pt_BR.po +0 -4
  88. data/po/ru.po +0 -4
  89. data/po/sk.po +0 -4
  90. data/po/sv.po +0 -4
  91. data/po/uk.po +0 -4
  92. data/po/zh_TW.po +0 -4
  93. data/schemas/alexandria.schemas +1 -1
  94. data/share/alexandria/glade/acquire_dialog__builder.glade +14 -11
  95. data/share/alexandria/glade/book_properties_dialog__builder.glade +170 -298
  96. data/share/alexandria/glade/main_app__builder.glade +22 -16
  97. data/share/alexandria/glade/new_book_dialog__builder.glade +26 -58
  98. data/share/alexandria/glade/preferences_dialog__builder.glade +249 -289
  99. data/share/gnome/help/alexandria/C/introduction.xml +0 -4
  100. data/share/gnome/help/alexandria/ja/introduction.xml +0 -4
  101. data/spec/alexandria/book_providers_spec.rb +1 -20
  102. data/spec/alexandria/console_spec.rb +32 -0
  103. data/spec/alexandria/export_library_spec.rb +141 -0
  104. data/spec/alexandria/library_spec.rb +24 -80
  105. data/spec/alexandria/library_store_spec.rb +37 -0
  106. data/spec/alexandria/smart_library_spec.rb +27 -22
  107. data/spec/alexandria/ui/dialogs/new_book_dialog_spec.rb +22 -0
  108. data/spec/alexandria/ui/dialogs_spec.rb +104 -38
  109. data/spec/end_to_end/basic_run_spec.rb +69 -0
  110. data/spec/spec_helper.rb +13 -25
  111. data/tasks/spec.rake +15 -2
  112. data/util/rake/fileinstall.rb +1 -0
  113. metadata +38 -16
  114. data/lib/alexandria/book_providers/deastore.rb +0 -265
  115. data/lib/alexandria/book_providers/mcu.rb +0 -182
@@ -29,8 +29,10 @@ module Alexandria
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
@@ -1,21 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2004-2006 Laurent Sansonetti
3
+ # This file is part of Alexandria.
4
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.
5
+ # See the file README.md for authorship and licensing information.
19
6
 
20
7
  module Alexandria
21
8
  class Book
@@ -27,7 +14,7 @@ module Alexandria
27
14
 
28
15
  DEFAULT_RATING = 0
29
16
  MAX_RATING_STARS = 5
30
- VALID_RATINGS = (DEFAULT_RATING..MAX_RATING_STARS)
17
+ VALID_RATINGS = (DEFAULT_RATING..MAX_RATING_STARS).freeze
31
18
 
32
19
  def initialize(title, authors, isbn, publisher, publishing_year,
33
20
  edition)
@@ -56,6 +43,7 @@ module Alexandria
56
43
 
57
44
  def rating=(rating)
58
45
  raise ArgumentError unless VALID_RATINGS.include? rating
46
+
59
47
  @rating = rating
60
48
  end
61
49
 
@@ -78,5 +66,9 @@ module Alexandria
78
66
  def ==(obj)
79
67
  obj.is_a?(self.class) && (ident == obj.ident)
80
68
  end
69
+
70
+ def inspect
71
+ "#<Alexandria::Book title: #{@title}>"
72
+ end
81
73
  end
82
74
  end
@@ -1,31 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2004-2006 Laurent Sansonetti
4
- # Copyright (C) 2014 Matijs van Zuijlen
3
+ # This file is part of Alexandria.
5
4
  #
6
- # Alexandria is free software; you can redistribute it and/or
7
- # modify it under the terms of the GNU General Public License as
8
- # published by the Free Software Foundation; either version 2 of the
9
- # License, or (at your option) any later version.
10
- #
11
- # Alexandria is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- # General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public
17
- # License along with Alexandria; see the file COPYING. If not,
18
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
19
- # Fifth Floor, Boston, MA 02110-1301 USA.
5
+ # See the file README.md for authorship and licensing information.
20
6
 
21
7
  require 'yaml'
22
8
  require 'fileutils'
23
9
  require 'rexml/document'
24
10
  require 'tempfile'
25
11
  require 'etc'
26
- require 'open-uri'
27
- require 'observer'
28
- require 'singleton'
12
+ require 'alexandria/library_store'
29
13
 
30
14
  module Alexandria
31
15
  class Library < Array
@@ -33,7 +17,7 @@ module Alexandria
33
17
 
34
18
  attr_reader :name
35
19
  attr_accessor :ruined_books, :updating, :deleted_books
36
- DIR = File.join(ENV['HOME'], '.alexandria')
20
+ DEFAULT_DIR = File.join(ENV['HOME'], '.alexandria')
37
21
  EXT = { book: '.yaml', cover: '.cover' }.freeze
38
22
 
39
23
  include GetText
@@ -44,7 +28,7 @@ module Alexandria
44
28
  include Observable
45
29
 
46
30
  def path
47
- File.join(DIR, @name)
31
+ File.join(@store.library_dir, @name)
48
32
  end
49
33
 
50
34
  def updating?
@@ -59,189 +43,12 @@ module Alexandria
59
43
  loop do
60
44
  name = i == 1 ? from_base : from_base + " #{i}"
61
45
  break unless all_libraries.find { |x| x.name == name }
46
+
62
47
  i += 1
63
48
  end
64
49
  name
65
50
  end
66
51
 
67
- FIX_BIGNUM_REGEX =
68
- /loaned_since:\s*(\!ruby\/object\:Bignum\s*)?(\d+)\n/
69
-
70
- def self.load(name)
71
- test = [0, nil]
72
- ruined_books = []
73
- library = Library.new(name)
74
- FileUtils.mkdir_p(library.path) unless File.exist?(library.path)
75
- Dir.chdir(library.path) do
76
- Dir['*' + EXT[:book]].each do |filename|
77
- test[1] = filename if (test[0]).zero?
78
-
79
- unless File.size? test[1]
80
- log.warn { "Book file #{test[1]} was empty" }
81
- md = /([\dxX]{10,13})#{EXT[:book]}/.match(filename)
82
- if md
83
- file_isbn = md[1]
84
- ruined_books << [nil, file_isbn, library]
85
- else
86
- log.warn { "Filename #{filename} does not contain an ISBN" }
87
- # TODO: delete this file...
88
- end
89
- next
90
- end
91
- book = regularize_book_from_yaml(test[1])
92
- old_isbn = book.isbn
93
- old_pub_year = book.publishing_year
94
- begin
95
- begin
96
- book.isbn = canonicalise_ean(book.isbn).to_s unless book.isbn.nil?
97
- raise "Not a book: #{book.inspect}" unless book.is_a?(Book)
98
- rescue InvalidISBNError
99
- book.isbn = old_isbn
100
- end
101
-
102
- book.publishing_year = book.publishing_year.to_i unless book.publishing_year.nil?
103
-
104
- # Or if isbn has changed
105
- raise "#{test[1]} isbn is not okay" unless book.isbn == old_isbn
106
-
107
- # Re-save book if Alexandria::DATA_VERSION changes
108
- raise "#{test[1]} version is not okay" unless book.version == Alexandria::DATA_VERSION
109
-
110
- # Or if publishing year has changed
111
- raise "#{test[1]} pub year is not okay" unless book.publishing_year == old_pub_year
112
-
113
- # ruined_books << [book, book.isbn, library]
114
- book.library = library.name
115
-
116
- ## TODO copy cover image file, if necessary
117
- # due to #26909 cover files for books without ISBN are re-saved as "g#{ident}.cover"
118
- if book.isbn.nil? || book.isbn.empty?
119
- if File.exist? library.old_cover(book)
120
- log.debug { "#{library.name}; book #{book.title} has no ISBN, fixing cover image" }
121
- FileUtils::Verbose.mv(library.old_cover(book), library.cover(book))
122
- end
123
- end
124
-
125
- library << book
126
- rescue
127
- book.version = Alexandria::DATA_VERSION
128
- savedfilename = library.simple_save(book)
129
- test[0] = test[0] + 1
130
- test[1] = savedfilename
131
-
132
- # retries the Dir.each block...
133
- # but gives up after three tries
134
- redo unless test[0] > 2
135
- else
136
- test = [0, nil]
137
- end
138
- end
139
-
140
- # Since 0.4.0 the cover files '_small.jpg' and
141
- # '_medium.jpg' have been deprecated for a single medium
142
- # cover file named '.cover'.
143
-
144
- Dir['*' + '_medium.jpg'].each do |medium_cover|
145
- begin
146
- FileUtils.mv(medium_cover,
147
- medium_cover.sub(/_medium\.jpg$/,
148
- EXT[:cover]))
149
- rescue
150
- end
151
- end
152
-
153
- Dir['*' + EXT[:cover]].each do |cover|
154
- next if cover[0] == 'g'
155
- md = /(.+)\.cover/.match(cover)
156
- begin
157
- ean = canonicalise_ean(md[1])
158
- rescue
159
- ean = md[1]
160
- end
161
- begin
162
- FileUtils.mv(cover, ean + EXT[:cover]) unless cover == ean + EXT[:cover]
163
- rescue
164
- end
165
- end
166
-
167
- FileUtils.rm_f(Dir['*_small.jpg'])
168
- end
169
- library.ruined_books = ruined_books
170
-
171
- library
172
- end
173
-
174
- def self.regularize_book_from_yaml(name)
175
- text = IO.read(name)
176
-
177
- # Code to remove the mystery string in books imported from Amazon
178
- # (In the past, still?) To allow ruby-amazon to be removed.
179
-
180
- # The string is removed on load, but can't make it stick, maybe has to do with cache
181
-
182
- if text =~ /!str:Amazon::Search::Response/
183
- log.debug { "Removing Ruby/Amazon strings from #{name}" }
184
- text.gsub!('!str:Amazon::Search::Response', '')
185
- end
186
-
187
- # Backward compatibility with versions <= 0.6.0, where the
188
- # loaned_since field was a numeric.
189
- if (md = FIX_BIGNUM_REGEX.match(text))
190
- new_yaml = Time.at(md[2].to_i).to_yaml
191
- # Remove the "---" prefix.
192
- new_yaml.sub!(/^\s*\-+\s*/, '')
193
- text.sub!(md[0], "loaned_since: #{new_yaml}\n")
194
- end
195
-
196
- # TODO: Ensure book loading passes through Book#initialize
197
- book = YAML.safe_load(text, whitelist_classes = [Book, Time])
198
-
199
- unless book.isbn.class == String
200
- # HACK
201
- md = /isbn: (.+)/.match(text)
202
- if md
203
- string_isbn = md[1].strip
204
- book.isbn = string_isbn
205
- end
206
- end
207
-
208
- # another HACK of the same type as above
209
- unless book.saved_ident.class == String
210
-
211
- md2 = /saved_ident: (.+)/.match(text)
212
- if md2
213
- string_saved_ident = md2[1].strip
214
- log.debug { "fixing saved_ident #{book.saved_ident} -> #{string_saved_ident}" }
215
- book.saved_ident = string_saved_ident
216
- end
217
- end
218
- if (book.isbn.class == String) && book.isbn.empty?
219
- book.isbn = nil # save trouble later
220
- end
221
- book
222
- end
223
-
224
- def self.loadall
225
- a = []
226
- begin
227
- Dir.entries(DIR).each do |file|
228
- # Skip hidden files.
229
- next if file =~ /^\./
230
- # Skip non-directory files.
231
- next unless File.stat(File.join(DIR, file)).directory?
232
-
233
- a << load(file)
234
- end
235
- rescue Errno::ENOENT
236
- FileUtils.mkdir_p(DIR)
237
- end
238
- # Create the default library if there is no library yet.
239
-
240
- a << load(_('My Library')) if a.empty?
241
-
242
- a
243
- end
244
-
245
52
  def self.move(source_library, dest_library, *books)
246
53
  dest = dest_library.path
247
54
  books.each do |book|
@@ -261,23 +68,14 @@ module Alexandria
261
68
  end
262
69
  end
263
70
 
264
- class NoISBNError < StandardError
265
- end
266
-
267
- class InvalidISBNError < StandardError
268
- attr_reader :isbn
269
- def initialize(isbn = nil)
270
- super()
271
- @isbn = isbn
272
- end
273
- end
71
+ def self.extract_numbers(entry)
72
+ return [] if entry.nil? || entry.empty?
274
73
 
275
- def self.extract_numbers(isbn)
276
- raise NoISBNError, 'Nil ISBN' if isbn.nil? || isbn.empty?
74
+ normalized = entry.delete('- ').upcase
75
+ return [] unless normalized =~ /\A[\dX]*\Z/
277
76
 
278
- isbn.delete('- ').upcase.split('').map do |x|
279
- raise InvalidISBNError, isbn unless x =~ /[\dX]/
280
- x == 'X' ? 10 : x.to_i
77
+ normalized.split('').map do |char|
78
+ char == 'X' ? 10 : char.to_i
281
79
  end
282
80
  end
283
81
 
@@ -292,8 +90,6 @@ module Alexandria
292
90
  def self.valid_isbn?(isbn)
293
91
  numbers = extract_numbers(isbn)
294
92
  (numbers.length == 10) && isbn_checksum(numbers).zero?
295
- rescue InvalidISBNError
296
- false
297
93
  end
298
94
 
299
95
  def self.ean_checksum(numbers)
@@ -307,8 +103,6 @@ module Alexandria
307
103
  (ean_checksum(numbers[0..11]) == numbers[12])) ||
308
104
  ((numbers.length == 18) &&
309
105
  (ean_checksum(numbers[0..11]) == numbers[12]))
310
- rescue InvalidISBNError
311
- false
312
106
  end
313
107
 
314
108
  def self.upc_checksum(numbers)
@@ -320,8 +114,6 @@ module Alexandria
320
114
  numbers = extract_numbers(upc)
321
115
  ((numbers.length == 17) &&
322
116
  (upc_checksum(numbers[0..10]) == numbers[11]))
323
- rescue InvalidISBNError
324
- false
325
117
  end
326
118
 
327
119
  AMERICAN_UPC_LOOKUP = {
@@ -347,23 +139,21 @@ module Alexandria
347
139
  def self.canonicalise_ean(code)
348
140
  code = code.to_s.delete('- ')
349
141
  if valid_ean?(code)
350
- return code
142
+ code
351
143
  elsif valid_isbn?(code)
352
144
  code = '978' + code[0..8]
353
- return code + String(ean_checksum(extract_numbers(code)))
145
+ code + String(ean_checksum(extract_numbers(code)))
354
146
  elsif valid_upc?(code)
355
147
  isbn10 = canonicalise_isbn
356
148
  code = '978' + isbn10[0..8]
357
- return code + String(ean_checksum(extract_numbers(code)))
358
- ## raise "fix function Alexandria::Library.canonicalise_ean"
359
- else
360
- raise InvalidISBNError, code
149
+ code + String(ean_checksum(extract_numbers(code)))
361
150
  end
362
151
  end
363
152
 
364
153
  def self.canonicalise_isbn(isbn)
365
154
  numbers = extract_numbers(isbn)
366
155
  return isbn if valid_ean?(isbn) && (numbers[0..2] != [9, 7, 8])
156
+
367
157
  canonical = if valid_ean?(isbn)
368
158
  # Looks like an EAN number -- extract the intersting part and
369
159
  # calculate a checksum. It would be nice if we could validate
@@ -377,10 +167,10 @@ module Alexandria
377
167
  elsif valid_isbn?(isbn)
378
168
  # Seems to be a valid ISBN number.
379
169
  numbers[0..-2] + [isbn_checksum(numbers[0..-2])]
380
- else
381
- raise InvalidISBNError, isbn
382
170
  end
383
171
 
172
+ return unless canonical
173
+
384
174
  canonical.map(&:to_s).join
385
175
  end
386
176
 
@@ -390,14 +180,8 @@ module Alexandria
390
180
  # book.saved_ident ||= book.ident
391
181
  book.saved_ident = book.ident if book.saved_ident.nil? || book.saved_ident.empty?
392
182
  if book.ident != book.saved_ident
393
- # log.debug { "Backwards compatibility step: #{book.saved_ident.inspect}, #{book.ident.inspect}" }
394
183
  FileUtils.rm(yaml(book.saved_ident))
395
- end
396
- if File.exist?(cover(book.saved_ident))
397
- begin
398
- FileUtils.mv(cover(book.saved_ident), cover(book.ident))
399
- rescue
400
- end
184
+ FileUtils.mv(cover(book.saved_ident), cover(book.ident)) if File.exist?(cover(book.saved_ident))
401
185
  end
402
186
  book.saved_ident = book.ident
403
187
 
@@ -488,6 +272,7 @@ module Alexandria
488
272
  if book.nil?
489
273
  # Delete the whole library.
490
274
  raise if @@deleted_libraries.include?(self)
275
+
491
276
  @@deleted_libraries << self
492
277
  else
493
278
  if @deleted_books.include?(book)
@@ -515,9 +300,11 @@ module Alexandria
515
300
  if book.nil?
516
301
  # Undelete the whole library.
517
302
  raise unless @@deleted_libraries.include?(self)
303
+
518
304
  @@deleted_libraries.delete(self)
519
305
  else
520
306
  raise unless @deleted_books.include?(book)
307
+
521
308
  @deleted_books.delete(book)
522
309
  unless include?(book)
523
310
  changed
@@ -573,7 +360,7 @@ module Alexandria
573
360
  end
574
361
 
575
362
  def name=(name)
576
- File.rename(path, File.join(DIR, name))
363
+ File.rename(path, File.join(dir, name))
577
364
  @name = name
578
365
  end
579
366
 
@@ -594,6 +381,7 @@ module Alexandria
594
381
  FileUtils.mkdir(somewhere)
595
382
  each do |book|
596
383
  next unless File.exist?(cover(book))
384
+
597
385
  FileUtils.cp(cover(book),
598
386
  File.join(somewhere, final_cover(book)))
599
387
  end
@@ -610,80 +398,10 @@ module Alexandria
610
398
 
611
399
  protected
612
400
 
613
- def initialize(name)
401
+ def initialize(name, store = nil)
614
402
  @name = name
403
+ @store = store
615
404
  @deleted_books = []
616
405
  end
617
406
  end
618
-
619
- class Libraries
620
- attr_reader :all_libraries, :ruined_books, :deleted_books
621
-
622
- include Observable
623
- include Singleton
624
-
625
- def reload
626
- @all_libraries.clear
627
- @all_libraries.concat(Library.loadall)
628
- @all_libraries.concat(SmartLibrary.loadall)
629
-
630
- ruined = []
631
- deleted = []
632
- all_regular_libraries.each { |library|
633
- ruined += library.ruined_books
634
- # make deleted books from each library accessible so we don't crash on smart libraries
635
- deleted += library.deleted_books
636
- }
637
- @ruined_books = ruined
638
- @deleted_books = deleted
639
- end
640
-
641
- def all_regular_libraries
642
- @all_libraries.select { |x| x.is_a?(Library) }
643
- end
644
-
645
- def all_smart_libraries
646
- @all_libraries.select { |x| x.is_a?(SmartLibrary) }
647
- end
648
-
649
- # def all_dynamic_libraries
650
- # @all_libraries.select { |x| x.is_a?(SmartLibrary) }
651
- # end
652
-
653
- LIBRARY_ADDED = 1
654
- LIBRARY_REMOVED = 2
655
-
656
- def add_library(library)
657
- @all_libraries << library
658
- notify(LIBRARY_ADDED, library)
659
- end
660
-
661
- def remove_library(library)
662
- @all_libraries.delete(library)
663
- notify(LIBRARY_REMOVED, library)
664
- end
665
-
666
- def really_delete_deleted_libraries
667
- Library.really_delete_deleted_libraries
668
- SmartLibrary.really_delete_deleted_libraries
669
- end
670
-
671
- def really_save_all_books
672
- all_regular_libraries.each do |library|
673
- library.each { |book| library.save(book, true) }
674
- end
675
- end
676
-
677
- private
678
-
679
- def initialize
680
- @all_libraries = []
681
- @deleted_books = []
682
- end
683
-
684
- def notify(action, library)
685
- changed
686
- notify_observers(self, action, library)
687
- end
688
- end
689
407
  end