Add `arrived` attribute (file creation timestamp) to books table.
[quanlib.git] / main.rb
diff --git a/main.rb b/main.rb
index 2d7f68b25c33c6bf45dbb0e909e17e3146f53e5b..e294b4a15e3391a0e4b84d41235b2eee1265ca31 100644 (file)
--- a/main.rb
+++ b/main.rb
@@ -1,67 +1,56 @@
-require 'walkdir'
-
-outputDir = 'output'
+require_relative 'navigator'
+require_relative 'page'
+require_relative 'store'
+require_relative 'walk_dir'
+
+@outputDir = 'output'
+
+@config_file = 'quanlib.ini'
+@skip_class = false
+
+def handleArg(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
 
-books = []
-imageCount = 0
+@store = Store.new(@config_file)
+@store.connect()
 
 for arg in ARGV
-  w = WalkDir.new(arg)
-  books += (w.books)
+  handleArg(arg)
 end
 
-if ! Dir.exist?(outputDir)
-  Dir.mkdir(outputDir)
+@store.init_db(@skip_class)
+
+for arg in ARGV
+  if ! arg.start_with?("--")
+    puts 'Scanning directory "' + arg + '"...'
+    w = WalkDir.new(@config_file, arg)
+    w.books
+  end
 end
 
-open(outputDir + '/index.html', 'w') do |fd|
-  fd.puts '<html>'
-  fd.puts '  <head>'
-  fd.puts '    <meta charset="utf-8"/>'
-  fd.puts '    <title>Books</title>'
-  fd.puts '    <style>'
-  fd.puts 'div { '
-  fd.puts '  display: inline-block;'
-  fd.puts '  width: 400px;'
-  fd.puts '  margin: 10px;'
-  fd.puts '  border 3px solid #73ad21;'
-  fd.puts '}'
-  fd.puts 'span.popup {  }'
-  fd.puts 'span.popup:hover {text-decoration: none; background: #cfffff; z-index: 6; }'
-  fd.puts 'span.popup span {display: none; position: absolute; '
-  fd.puts '  margin: 4px 0 0 0px; padding: 3px 3px 3px 3px;'
-  fd.puts '  border-style:solid; border-color:black; border-width:1px;}'
-  fd.puts 'span.popup:hover span {display: block; margin: 20px 0 0 0px; background: #ffffaf; z-index:6;}'
-  fd.puts '    </style>'
-  fd.puts '  </head>'
-  fd.puts '  <body>'
-  
-  for book in books
-    image = nil
-    if nil != book.cover
-      imageCount += 1
-      (path, mimeType) = book.cover.writeImage(outputDir, 'image' + imageCount.to_s)
-      image = '<img height="200px" src="' + path + '"/>'
-    else
-      image = '(No cover image)'
-    end
+@store.cross_reference_lists
 
-    fd.puts '    <div><table>'
-    fd.puts '      <tr><td><a href="' + book.path + '">' + image + '</a></td>'
+puts 'Creating output...'
 
-    heading = book.heading()
-    description = book.description()
-    if nil != description
-      fd.puts '          <td><span class="popup">' + heading + '<span><p>' + heading + '</p><p>' + description + '</p></span></span></td></tr>'
-    else
-      fd.puts '          <td>' + heading + '</td></tr>'
-    end
-      
-    fd.puts '    </table></div>'
-  end
-  
-  fd.puts "    </table>"
-  fd.puts "  </body>"
-  fd.puts "</html>"
-end
+navigator = Navigator.new(@store)
+navigator.write_atoz_pages()
+navigator.write_series_listing()
+navigator.write_dewey()
+
+@store.disconnect()