From 86b767b0f9a5aeac4708e48231d2010215b35e2b Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 12 Mar 2012 18:49:49 -0400 Subject: v3dv: sqlite3 discreet .sql.db file for each document (possibility added) * in addition to existing possibility of a shared db in sqlite3 or postgresql --- conf/sisu/v3dv/sisurc.yml | 8 +- data/doc/sisu/CHANGELOG_v3 | 3 + lib/sisu/v3dv/db_create.rb | 4 +- lib/sisu/v3dv/db_dbi.rb | 12 +- lib/sisu/v3dv/db_drop.rb | 2 +- lib/sisu/v3dv/db_select.rb | 50 ++++---- lib/sisu/v3dv/dbi.rb | 2 +- lib/sisu/v3dv/dbi_discreet.rb | 158 ++++++++++++++++++++++++ lib/sisu/v3dv/hub.rb | 8 +- lib/sisu/v3dv/options.rb | 6 + lib/sisu/v3dv/sysenv.rb | 276 ++++++++++++++++++++++++++---------------- lib/sisu/v3dv/urls.rb | 2 +- 12 files changed, 384 insertions(+), 147 deletions(-) create mode 100644 lib/sisu/v3dv/dbi_discreet.rb diff --git a/conf/sisu/v3dv/sisurc.yml b/conf/sisu/v3dv/sisurc.yml index 5416a65e..de2288f9 100644 --- a/conf/sisu/v3dv/sisurc.yml +++ b/conf/sisu/v3dv/sisurc.yml @@ -49,11 +49,11 @@ show_output_on: 'filesystem_url' #% flag - set (non-default) processing flag shortcuts -1, -2 etc. (here adding colour and verbosity as default) flag: color: true # making colour default -c is toggle, and will now toggle colour off - default: '-NhewpotbxXyYv' # -m run by default; includes verbose + default: '-NhewpotbxXyYdv' # -m run by default; includes verbose i: '-Nhewpoty' # -m run by default - ii: '-NhewpotbxX' # -m run by default - iii: '-NhewpotbxXY' # -m run by default - iv: '-NhewpotbxXiIY' # -m run by default + ii: '-NhewpotbxXd' # -m run by default + iii: '-NhewpotbxXYd' # -m run by default + iv: '-NhewpotbxXiIYd' # -m run by default v: '-NhewpotbxXYDv --update' # -m run by default; includes verbose #% papersize, (LaTeX/pdf) available values: A4, US_letter, book_b5, book_a5, US_legal diff --git a/data/doc/sisu/CHANGELOG_v3 b/data/doc/sisu/CHANGELOG_v3 index b432aab8..d2a460b9 100644 --- a/data/doc/sisu/CHANGELOG_v3 +++ b/data/doc/sisu/CHANGELOG_v3 @@ -73,6 +73,9 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_3.1.15.orig.tar.xz * v3dv, documentation sisu_commands, rearranged & update with regard to excludes +* v3dv, sqlite3 discreet .sql.db file for each document (in addition to + existing possibility of a shared db in sqlite3 or postgresql) + * texinfo, fix (break holding back 3.2 merge) [proposed next version starts 3.2, (merge dev branch after 3.1.15)] diff --git a/lib/sisu/v3dv/db_create.rb b/lib/sisu/v3dv/db_create.rb index 6420c3ec..627f0ea5 100644 --- a/lib/sisu/v3dv/db_create.rb +++ b/lib/sisu/v3dv/db_create.rb @@ -81,9 +81,9 @@ module SiSU_DbCreate def create_db @env=SiSU_Env::InfoEnv.new(@opt.fns) tell=(@sql_type=='sqlite') \ - ? SiSU_Screen::Ansi.new(@opt.cmd,'invert','Create Sqlite db tables in:',%{"#{@env.path.output}/sisu_sqlite.db"}) + ? SiSU_Screen::Ansi.new(@opt.cmd,'invert','Create Sqlite db tables in:',%{"#{@file}"}) : SiSU_Screen::Ansi.new(@opt.cmd,'invert','Create PG db tables in:',%{"#{Db[:name_prefix]}#{@env.path.stub_pwd}"}) - tell.colorize if @opt.cmd =~/vVM/ + tell.colorize if @opt.cmd =~/[vVM]/ SiSU_Env::SystemCall.new.create_pg_db(@env.path.stub_pwd) if @sql_type=='pg' #watch use of path.stub_pwd instead of stub end def output_dir? diff --git a/lib/sisu/v3dv/db_dbi.rb b/lib/sisu/v3dv/db_dbi.rb index f15b2456..0c19578f 100644 --- a/lib/sisu/v3dv/db_dbi.rb +++ b/lib/sisu/v3dv/db_dbi.rb @@ -69,17 +69,17 @@ module SiSU_DbDBI require_relative 'db_import' # db_import.rb class ColumnSize < SiSU_DbColumns::ColumnSize # db_columns.rb end - class Test < SiSU_DbTests::Test # db_tests.rb + class Test < SiSU_DbTests::Test # db_tests.rb end - class Create . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Ralph Amissah + + + + ** Description: postgresql module, dbi import frame + +=end +module SiSU_DBI_Discreet #% database building + require_relative 'help' # help.rb + require_relative 'sysenv' # sysenv.rb + include SiSU_Env; include SiSU_Screen + require_relative 'param' # param.rb + include SiSU_Param + require_relative 'db_dbi' # db_dbi.rb + include SiSU_DbDBI + require_relative 'shared_html_lite' # shared_html_lite.rb + include SiSU_FormatShared + require 'fileutils' + include FileUtils::Verbose + class SQL + def initialize(opt) + SiSU_Env::Load.new('dbi',true).prog + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + @md=@particulars.md + if @opt.cmd =~/[d]/ \ + or @opt.mod.inspect =~/--((?:sq)?lite)/ + @sql_type='sqlite' + maintenance_check(@opt,__FILE__,__LINE__) if @opt.cmd.inspect =~/M/ + end + @output_path=@md.file.output_path.sqlite_discreet.dir + @filename=@md.file.base_filename.sqlite_discreet + @file="#{@output_path}/#{@filename}" + end + def build + prepare + create_and_populate + end + def maintenance_check(opt,file,line) + p opt.mod + p opt.cmd + p "at #{file} #{line}" + end + def prepare + if not FileTest.directory?(@output_path) + FileUtils::mkdir_p(@output_path) + elsif @file + FileUtils::rm_rf(@file) + end + end + def db_exist?(db,conn) + msg=%{no connection with sqlite database established, createdb "#{db.sqlite.db}"?} + if (not (FileTest.file?(db.sqlite.db)) \ + or FileTest.zero?(db.sqlite.db)) + puts msg + exit + end + if conn.class==NilClass + puts msg + exit + end + end + def create_and_populate + db=SiSU_Env::DbOp.new(@md) + conn=db.sqlite_discreet.conn_sqlite3 + sdb=SiSU_DbDBI::Create.new(@opt,conn,@file,'sqlite') + sdb_index=SiSU_DbDBI::Index.new(@opt,conn,@file,'sqlite') + sdb.output_dir? + begin + sdb.create_db + sdb.create_table.metadata_and_text + sdb.create_table.doc_objects + sdb.create_table.endnotes + sdb.create_table.endnotes_asterisk + sdb.create_table.endnotes_plus + sdb.create_table.urls + sdb_index.create_indexes + db_exist?(db,conn) + sdb_import=SiSU_DbDBI::Import.new(@opt,conn,@file,'sqlite') + sdb_import.marshal_load + tell=SiSU_Screen::Ansi.new(@opt.cmd,"sqlite3 #{db.sqlite.db} database?") + tell.puts_grey if @opt.cmd =~/v/ + rescue; SiSU_Errors::InfoError.new($!,$@,'-d').error; sdb.output_dir? + end + end + def read_sqlite + begin + @conn=@db.sqlite.conn_sqlite3 + rescue + ensure + end + end + def connect + begin + sql_type='sqlite' + SiSU_Screen::Ansi.new(@opt.cmd,"DBI (#{@sql_type}) #{@opt.mod}",@opt.fns).dbi_title unless @opt.cmd =~/q/ + @db.sqlite_discreet.conn_sqlite3 + rescue + SiSU_Errors::InfoError.new($!,$@,@cf,@opt.fns).error + ensure + end + end + def populate + end + end +end +__END__ diff --git a/lib/sisu/v3dv/hub.rb b/lib/sisu/v3dv/hub.rb index fd7909ec..5f256314 100644 --- a/lib/sisu/v3dv/hub.rb +++ b/lib/sisu/v3dv/hub.rb @@ -224,7 +224,8 @@ module SiSU when /^qrcode$/; SiSU_QRcode::Source.new(@opt).read # -Q qrcode.rb when /^sitemaps$/; SiSU_Sitemaps::Source.new(@opt).read # -Y sitemaps.rb when /^zap$/; SiSU_Zap::Source.new(@opt).read # -Z zap.rb - when /^dbi$/; SiSU_DBI::SQL.new(@opt).connect # -D -d dbi.rb + when /^dbi$/; SiSU_DBI::SQL.new(@opt).connect # -D -d dbi.rb + when /^dbi_discreet$/; SiSU_DBI_Discreet::SQL.new(@opt).build # -d dbi_discreet.rb end @n_do=@n_do+1 SiSU_Screen::Ansi.new(@opt.cmd,@n_do,"#{@req.upcase} processed").files_processed if @opt.cmd =~/[MVv]/ @@ -255,7 +256,7 @@ module SiSU end end end - elsif @req =~/^dbi$/; SiSU_DBI::SQL.new(@opt).connect # -D -d + elsif @req =~/^dbi$/; SiSU_DBI::SQL.new(@opt).connect # -D -d elsif @req=~/^sisupod_make$/; SiSU_Doc::Source.new(@opt).read # -S end SiSU::Operations.new.counter @@ -564,6 +565,9 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/ if @opt.act[:psql][:bool] #% --pg, -D DB postgresql op('dbi','postgresql') end + if @opt.act[:sqlite_discreet][:bool] #% --sqlite, -d DB sqlite + op('dbi_discreet','sqlite') + end if @opt.act[:sqlite][:bool] #% --sqlite, -d DB sqlite op('dbi','sqlite') end diff --git a/lib/sisu/v3dv/options.rb b/lib/sisu/v3dv/options.rb index 44eb1020..11d03e1d 100644 --- a/lib/sisu/v3dv/options.rb +++ b/lib/sisu/v3dv/options.rb @@ -665,6 +665,12 @@ module SiSU_Commandline && (mod.inspect =~/"--createdb"|"--create"|"--recreate"|"--dropall"|"--recreate"|"--import"|"--update"|"--remove"/) \ ? { bool: true, set: :on } : { bool: false, set: :na } + act[:sqlite_discreet]=(cmd =~/d/ \ + || mod.inspect =~/"--sql"|"--sqlite"/) \ + && (mod.inspect =~/"--both"/ \ + || mod.inspect !~/"--createdb"|"--create"|"--recreate"|"--dropall"|"--recreate"|"--import"|"--update"|"--remove"/) \ + ? { bool: true, set: :on } + : { bool: false, set: :na } act[:harvest]=(mod.inspect =~/"--harvest"/) \ ? { bool: true, set: :on } : { bool: false, set: :na } diff --git a/lib/sisu/v3dv/sysenv.rb b/lib/sisu/v3dv/sysenv.rb index 95ebf6d9..4383a893 100644 --- a/lib/sisu/v3dv/sysenv.rb +++ b/lib/sisu/v3dv/sysenv.rb @@ -2733,7 +2733,7 @@ WOK and not (@rc['flag']['default'].nil? \ or @rc['flag']['default'].empty?) @rc['flag']['default'] - else '-NQhewpotbxXyYv' + else '-NQhewpotbxXdyYv' end end def cf_1 #processing flag shortcuts @@ -2749,7 +2749,7 @@ WOK and not (@rc['flag']['ii'].nil? \ or @rc['flag']['ii'].empty?) @rc['flag']['ii'] - else '-NQhewpotbxXy' + else '-NQhewpotbxXdy' end end def cf_3 #processing flag shortcuts @@ -2757,7 +2757,7 @@ WOK and not (@rc['flag']['iii'].nil? \ or @rc['flag']['iii'].empty?) @rc['flag']['iii'] - else '-NQhewpotbxXyY' + else '-NQhewpotbxXdyY' end end def cf_4 #processing flag shortcuts @@ -2765,7 +2765,7 @@ WOK and not (@rc['flag']['iv'].nil? \ or @rc['flag']['iv'].empty?) @rc['flag']['iv'] - else '-NQhewpotbxXDyY --update' + else '-NQhewpotbxXdDyY --update' end end def cf_5 #processing flag shortcuts @@ -2773,7 +2773,7 @@ WOK and not (@rc['flag']['v'].nil? \ or @rc['flag']['v'].empty?) @rc['flag']['v'] - else '-NQhewpotbxXDyYv --update' + else '-NQhewpotbxXdDyYv --update' end end end @@ -3795,6 +3795,134 @@ WOK self end end + class InfoDb < InfoEnv + @@rc=nil + def initialize + @@pwd ||=Dir.pwd + @pwd=Dir.pwd + @env=SiSU_Env::InfoEnv.new + pt=Pathname.new(@pwd) + r=Px[:lng_lst].join('|') + u=/.+?\/([^\/]+)(?:\/(?:#{r})$|$)/ + @pwd_stub=pt.realpath.to_s[u,1] + @rc=@@rc ||=GetInit.instance.sisu_yaml.rc + @defaults=SiSU_Env::InfoEnv.new.defaults + end + def share_source? + ((defined? @rc['db']['share_source']) \ + && @rc['db']['share_source']==true) \ + ? @rc['db']['share_source'] + : false + end + def engine + def default + ((defined? @rc['db']['engine']['default']) \ + && @rc['db']['engine']['default']=~/postgresql|sqlite/) \ + ? @rc['db']['engine']['default'] + : 'sqlite' + end + self + end + def psql + def user + ((defined? @rc['db']['postgresql']['user']) \ + && @rc['db']['postgresql']['user']=~/\S+/) \ + ? @rc['db']['postgresql']['user'] + : @env.user + end + def db #db_name + "#{Db[:name_prefix]}#{@pwd_stub}" + end + def port #PGPORT + ((defined? @rc['db']['postgresql']['port']) \ + && ( @rc['db']['postgresql']['port'] =~/\d+/ \ + || @rc['db']['postgresql']['port'].class==Fixnum)) \ + ? @rc['db']['postgresql']['port'] + : (@defaults[:postgresql_port]) + end + def password + ((defined? @rc['db']['postgresql']['password']) \ + && @rc['db']['postgresql']['password']=~/\S+/) \ + ? @rc['db']['postgresql']['password'] + : '' + end + def host + ((defined? @rc['db']['postgresql']['host']) \ + && @rc['db']['postgresql']['host']=~/(?:\S{1,3}\.){3}\S{1,3}|\S+?\.\S+/) \ + ? @rc['db']['postgresql']['host'] + : '' + end + def dbi + (psql.host =~/(?:\S{1,3}\.){3}\S{1,3}|\S+?\.\S+/) \ + ? "DBI:Pg:database=#{psql.db};host=#{psql.host};port=#{psql.port}" + : "DBI:Pg:database=#{psql.db};port=#{psql.port}" + end + def conn_dbi + DBI.connect(psql.dbi,psql.user,psql.db) + end + self + end + def mysql + def db + #"#{Db[:name_prefix]}#{@pwd_stub}" + end + def port + '**' + end + def dbi + "dbi:Mysql:database=#{mysql.db};port=#{mysql.port}" + end + self + end + def sqlite + def db + "#{@env.path.webserv}/#{@pwd_stub}/sisu_sqlite.db" + end + def db_discreet(md) + # "#{@env.path.webserv}/#{@pwd_stub}/sisu_sqlite.db" + end + def dbi + "DBI:SQLite3:#{sqlite.db}" #sqlite3 ? + end + def sqlite3 + sqlite.db #sqlite3 ? + end + def conn_dbi + DBI.connect(sqlite.dbi) + end + def conn_sqlite3 + SQLite3::Database.new(sqlite.sqlite3) + end + self + end + end + class DbOp