Add `arrived` attribute (file creation timestamp) to books table.
[quanlib.git] / main.rb
diff --git a/main.rb b/main.rb
index f3371b7d44daf55b9d65c3bbaf488b213d0f091b..e294b4a15e3391a0e4b84d41235b2eee1265ca31 100644 (file)
--- a/main.rb
+++ b/main.rb
-require 'page'
-require 'store'
-require 'walkdir'
+require_relative 'navigator'
+require_relative 'page'
+require_relative 'store'
+require_relative 'walk_dir'
 
-outputDir = 'output'
+@outputDir = 'output'
 
-book_ids = []
-imageCount = 0
+@config_file = 'quanlib.ini'
+@skip_class = false
 
 def handleArg(arg)
-  if "--purge" == arg
+  if arg.start_with?("--config=")
+    @config_file = arg[9..-1]
+    puts 'Using config file "' + @config_file + '".'
+  elsif "--purge" == arg
     puts 'Purging database...'
     @store.dropSchema()
+    if File.exists?(@store.unclassified_csv)
+      File.delete(@store.unclassified_csv)
+    end
+  elsif "--skip-class" == arg
+    puts 'Skipping load of classification table.'
+    @skip_class = true
   elsif arg.start_with?("--")
     abort('ERROR:  Unrecognized option "' + arg + '".')
   end
 end
 
-@store = Store.new()
+@store = Store.new(@config_file)
 @store.connect()
 
 for arg in ARGV
   handleArg(arg)
 end
 
-@store.init_db()
+@store.init_db(@skip_class)
 
 for arg in ARGV
   if ! arg.start_with?("--")
     puts 'Scanning directory "' + arg + '"...'
-    w = WalkDir.new(@store, arg)
-    book_ids += (w.books)
-  end
-end
-
-puts 'Creating output...'
-
-atoz_counts = {}
-
-('A'..'Z').each do |letter| 
-  book_ids = @store.query_books_by_author(letter + '%')
-  puts 'Authors starting with "' + letter + '":  ' + book_ids.length.to_s() + ' books.'
-  atoz_counts[letter] = book_ids.length
-
-  page = Page.new(@store)
-  if 'A' != letter
-    page.back = ['../atoz/output_' + (letter.ord - 1).chr + '.html', 'Prev']
-  end
-  if 'Z' != letter
-    page.forward = ['../atoz/output_' + (letter.ord + 1).chr + '.html', 'Next']
+    w = WalkDir.new(@config_file, arg)
+    w.books
   end
-  page.output_dir = 'atoz'
-  page.index_file = 'output_' + letter + '.html'
-  page.title = "Authors starting with '" + letter + "'"
-  page.up = ['../atoz/index.html', 'Index']
-
-  page.write_html(book_ids)
 end
 
+@store.cross_reference_lists
 
-ages = ['beginner', 'junior', 'ya', 'adult']
-
-series_infos = []
-
-ages.each do |age|
-  puts 'Series for "' + age + '" readers...'
-
-  series_ids = @store.query_series_by_age(age)
-
-  series_ids.each do |id|
-    series = @store.load_series(id)
-    book_ids = @store.query_books_by_series_id(id)
-    if nil != book_ids and book_ids.length > 0
-      series_infos.push( [series, book_ids] )
-    end
-  end
-
-  for idx in 0 .. (series_infos.length - 1) do 
-    #puts series.descr + ': ' + book_ids.length.to_s + ' books.'
-
-    back = nil
-    fwd = nil
-
-    if idx > 0
-      back = series_infos[idx-1]
-    end
-    if idx < (series_infos.length - 1)
-      fwd = series_infos[idx+1]
-    end
+puts 'Creating output...'
 
-    cur = series_infos[idx]
-    series = cur[0]
-    book_ids = cur[1]
+navigator = Navigator.new(@store)
+navigator.write_atoz_pages()
+navigator.write_series_listing()
+navigator.write_dewey()
 
-    page = Page.new(@store)
-    if nil != back
-      page.back = [back[0].key + '.html', 'Back']
-    end
-    if nil != fwd
-      page.forward = [fwd[0].key + '.html', 'Forward']
-    end
-    page.output_dir = 'series'
-    page.index_file = series.key + '.html'
-    page.title = 'Series &ldquo;' + series.descr + '&rdquo; (' + book_ids.length.to_s + ' books)'
-    page.up = ['../atoz/index.html', 'Index']
-  
-    page.write_html(book_ids)
-  end
-end
-
-content = '<table><tr><th>Author</th><th>Books</th></tr>'
-('A'..'Z').each do |letter|
-  content += '  <tr><td><a href="../atoz/output_' + letter + '.html">Starting with ' + letter + '</a></td><td>' + atoz_counts[letter].to_s + '</td></tr>'
-end
-page = Page.new(@store)
-page.output_dir = 'atoz'
-page.special = content
-page.write_html( [] )
-  
 @store.disconnect()