lib/sportdb/cli/main.rb in sportdb-1.9.13 vs lib/sportdb/cli/main.rb in sportdb-1.9.14
- old
+ new
@@ -15,12 +15,14 @@
# our own code / additional for cli only
require 'logutils/db'
require 'sportdb/cli/opts'
-
-
+
+require 'datafile' ## lets us use Datafile::Builder,Datafile etc.
+
+
program_desc 'sport.db command line tool'
version SportDb::VERSION
@@ -77,10 +79,18 @@
db_config = {
:adapter => 'sqlite3',
:database => "#{options.db_path}/#{options.db_name}"
}
+ ## todo/check: use if defined?( JRUBY_VERSION ) instead ??
+ if RUBY_PLATFORM =~ /java/ && db_config[:adapter] == 'sqlite3'
+ # quick hack for JRuby sqlite3 support via jdbc
+ require 'jdbc/sqlite3'
+ ## todo: check if require for activerecord jdbc adapter for sqlite is required to
+ end
+
+
puts "Connecting to db using settings: "
pp db_config
ActiveRecord::Base.establish_connection( db_config )
@@ -111,12 +121,13 @@
desc "Build DB (download/create/read); use ./Datafile - zips get downloaded to ./tmp"
command [:build,:b] do |c|
c.action do |g,o,args|
- builder = SportDb::Builder.load_file( './Datafile' )
- builder.download # builder step 1 - download all datasets/zips
+ builder = Datafile::Builder.load_file( './Datafile' )
+ datafile = builder.datafile
+ datafile.download # datafile step 1 - download all datasets/zips
connect_to_db( opts )
LogDb.create
ConfDb.create
@@ -125,11 +136,11 @@
PersonDb.create
SportDb.create
SportDb.read_builtin # e.g. seasons.txt etc
- builder.read # builder step 2 - read all datasets
+ datafile.read # datafile step 2 - read all datasets
puts 'Done.'
end # action
end # command setup
@@ -139,12 +150,13 @@
c.action do |g,o,args|
connect_to_db( opts )
- builder = SportDb::Builder.load_file( './Datafile' )
- builder.read
+ builder = Datafile::Builder.load_file( './Datafile' )
+ datafile = builder.datafile
+ datafile.read
puts 'Done.'
end # action
end # command setup
@@ -153,12 +165,13 @@
c.action do |g,o,args|
# note: no database connection needed (check - needed for logs?? - not setup by default???)
- builder = SportDb::Builder.load_file( './Datafile' )
- builder.download
+ builder = Datafile::Builder.load_file( './Datafile' )
+ datafile = builder.datafile
+ datafile.download
puts 'Done.'
end # action
end # command setup
@@ -174,12 +187,13 @@
worker = Fetcher::Worker.new
worker.copy( "https://github.com/openfootball/datafile/raw/master/#{setup}.rb", './Datafile' )
## step 2: same as command build (todo - reuse code)
- builder = SportDb::Builder.load_file( './Datafile' )
- builder.download # builder step 1 - download all datasets/zips
+ builder = Datafile::Builder.load_file( './Datafile' )
+ datafile = builder.datafile
+ datafile.download # datafile step 1 - download all datasets/zips
connect_to_db( opts ) ### todo: check let connect go first?? - for logging (logs) to db ???
LogDb.create
ConfDb.create
@@ -188,11 +202,11 @@
PersonDb.create
SportDb.create
SportDb.read_builtin # e.g. seasons.txt etc
- builder.read # builder step 2 - read all datasets
-
+ datafile.read # datafile step 2 - read all datasets
+
puts 'Done.'
end # action
end # command setup
\ No newline at end of file