aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v4/cgi_sqlite.rb
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2013-05-29 19:45:23 -0400
committerRalph Amissah <ralph@amissah.com>2013-05-29 19:45:23 -0400
commitd8369e7a159aaa2a1b12ed7ba6ede361e62cea9a (patch)
tree3d2139ea94b0cdb35c8b4523c911aab18b2d1de2 /lib/sisu/v4/cgi_sqlite.rb
parentv4 v5: document version check, disable (diff)
v4 v5: cgi helper script, sample search form generator, adjust/improve
* adds settings * db type --db-pq or db-sqlite * webserver for cgi script & db --webserv-search='' * webserver for sisu ouptut files --webserv-output='' * cgi search form link name --cgi-search-form-name='' * db user (pg) --db-user=''
Diffstat (limited to 'lib/sisu/v4/cgi_sqlite.rb')
-rw-r--r--lib/sisu/v4/cgi_sqlite.rb77
1 files changed, 55 insertions, 22 deletions
diff --git a/lib/sisu/v4/cgi_sqlite.rb b/lib/sisu/v4/cgi_sqlite.rb
index 05c7e6a7..93129b5c 100644
--- a/lib/sisu/v4/cgi_sqlite.rb
+++ b/lib/sisu/v4/cgi_sqlite.rb
@@ -56,7 +56,7 @@
<ralph@amissah.com>
<ralph.amissah@gmail.com>
- ** Description: generates naive cgi search form for search of sisu database (pgsql sqlite)
+ ** Description: generates naive cgi search form for search of sisu database (sqlite)
=end
module SiSU_CGI_SQLite #% database building documents
@@ -66,17 +66,19 @@ module SiSU_CGI_SQLite
class SearchSQLite < CGI_Common
def initialize(opt,webserv)
@opt,@webserv=opt,webserv
+ @cX=SiSU_Screen::Ansi.new(opt.cmd).cX
@env=SiSU_Env::InfoEnv.new('',opt)
- @image_src="#{@env.url.webserv_cgi}/_sisu/image_sys"
+ @image_src="#{@env.url.webserv_cgi(@opt)}/_sisu/image_sys"
@common=SiSU_CGI_SQL::CGI_Common.new(@webserv,@opt,@image_src,@env)
@cgi_file_name="#{Db[:name_prefix_db]}by_#{opt.dir_structure_by.to_s}_sqlite.cgi"
+ @name_of_sqlite_db_file='sisu_sqlite.db'
end
def sqlite
serve=[]
Dir.foreach(@env.path.webserv) do |x|
if x !~/^\./ \
and FileTest.directory?("#{@env.path.webserv}/#{x}")
- if FileTest.file?("#{@env.path.webserv}/#{x}/sisu_sqlite.db")
+ if FileTest.file?("#{@env.path.webserv}/#{x}/#{@name_of_sqlite_db_file}")
serve << x unless x =~/^_\S+/
end
end
@@ -91,32 +93,62 @@ module SiSU_CGI_SQLite
f2 << %{ when /#{Db[:name_prefix]}#{x}/; '<option value="#{Db[:name_prefix]}#{x}">#{x}</option>'\n}
end
f2 << " end\n"
- f3 << %{ db_name='sisu_sqlite.db'\n}
+ f3 << %{ db_name='#{@name_of_sqlite_db_file}'\n}
f3 << %{ db_sqlite=case cgi['db']\n}
serve.each do |x|
- f3 << %{ when /#{Db[:name_prefix]}#{x}/; "#{@env.path.webserv}/#{x}/sisu_sqlite.db"\n}
+ f3 << %{ when /#{Db[:name_prefix]}#{x}/; "#{@env.path.webserv}/#{x}/\#{db_name}"\n}
end
- f3 << %{ else '#{@env.path.webserv}/#{serve[0]}/sisu_sqlite.db'\n end\n}
+ f3 << %{ else '#{@env.path.webserv}/#{serve[0]}/\#{db_name}'\n end\n}
if FileTest.writable?('.')
output=File.open(@cgi_file_name,'w')
output << header0 << header1 << header_desc << header2 << f1 << buttons1 << buttons2 << search_request << search_statement << search_statement_common << search_query1 << @common.pages << search_query2 << @common.tail << @common.main1 << f2 << f3 << dbi_connect << @common.main2 << @common.dir_structure << @common.main3
- a=%{ generated sisu_sqlite.cgi,
- BASED ON ALREADY CREATED sisu_sqlite.db OUTPUT, (-d)
- }
- SiSU_Screen::Ansi.new(@opt.cmd,a).print_grey
- c=case @webserv
+ puts <<-WOK
+ generated sample search form: #{@cX.green}#{@cgi_file_name}#{@cX.off}
+ default database name: #{@cX.green}#{Db[:name_prefix]}#{@env.path.stub_pwd}#{@cX.off} (#{@env.path.stub_pwd})
+ cgi & db host on: #{@cX.blue}#{@env.url.webserv_base_cgi(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-sqlite --webserv-search='#{@env.url.webserv_base_cgi(@opt)}'#{@cX.off}
+ sisu output on: #{@cX.blue}#{@env.url.webserv_files_from_db(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-sqlite --webserv-output='#{@env.url.webserv_files_from_db(@opt)}'#{@cX.off}
+ cgi search form link name: #{@cX.green}#{@env.url.cgi_sample_search_form_name(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-sqlite --cgi-search-form-name='#{@env.url.cgi_sample_search_form_name(@opt)}'#{@cX.off}
+ #{@cX.fuschia}(settings priority: command line; sisurc.yml; else defaults)#{@cX.off}
+
+ #{@cX.fuschia}NOTE it is first necessary to create the database and tables and populate it#{@cX.off}
+
+ sisu --sqlite --dropall # removes existing postgresql db & tables
+ sisu --sqlite --createall -v # creates postgresql db & tables
+ sisu --sqlite --update -v *.sst *.ssm # populate the db
+ sisu --sample-search-form --sqlite # creates the postgresql search form
+ # this should be done after creating the db
+ # to be searched
+ sisu --webrick & # starts ruby webrick web server
+
+ # if necessary make the directory '/usr/lib/cgi-bin'
+ # here we copy the postgresql search form to cgi-bin
+ # (copy #{@cgi_file_name} to your cgi directory)
+ # set file permissions to 755, &
+ # make symbolic link to #{@cgi_link_name}
+ WOK
+ a=case @webserv
when /pwd/; ''
- else "if necessary make the directory /usr/lib/cgi-bin :
- sudo cp -vi #{Dir.pwd}/#{@cgi_file_name} /usr/lib/cgi-bin/.
- sudo chmod -v 755 /usr/lib/cgi-bin/#{@cgi_file_name}
- sudo ln -s /usr/lib/cgi-bin/#{@cgi_file_name} /usr/lib/cgi-bin/sisu_sqlite.cgi
- (copy #{@cgi_file_name} to your cgi directory) set file permissions to 755, and make symbolic link to sisu_sqlite.cgi"
+ else <<-WOK
+
+ sudo cp -vi #{Dir.pwd}/#{@cgi_file_name} /usr/lib/cgi-bin/.; \\
+ cd /usr/lib/cgi-bin && \\
+ sudo chmod -v 755 #{@cgi_file_name}; \\
+ sudo rm -vi #{@env.url.cgi_sample_search_form_name(@opt)}; \\
+ sudo ln -sf #{@cgi_file_name} #{@env.url.cgi_sample_search_form_name(@opt)}; \\
+ cd -
+ WOK
end
- a=%{#{c}
- #{@env.webserv_base_cgi}/cgi-bin/sisu_sqlite.cgi
- }
b='(to create and populate sisu sqlite database see "man sisu" and in particular the -d flag)'
SiSU_Screen::Ansi.new(@opt.cmd,a,b).warn
+ a=<<-WOK
+
+ #{@env.webserv_base_cgi(@opt)}/cgi-bin/#{@cgi_link_name}
+
+ WOK
+ SiSU_Screen::Ansi.new(@opt.cmd,a).print_blue
else puts "failed in attempt to write #{@cgi_file_name} to present directory, is directory writable?"
end
end
@@ -132,10 +164,11 @@ module SiSU_CGI_SQLite
require 'fcgi'
require 'dbi'
@stub_default='sisu_sqlite'
- @image_src='#{@env.url.webserv_cgi}/_sisu/image_sys'
- @hosturl_cgi='#{@env.url.webserv_base_cgi}/cgi-bin'
- @hosturl_files='#{@env.url.webserv_files_from_db}'
+ @image_src='#{@image_src}'
+ @hosturl_cgi='#{@env.url.webserv_base_cgi(@opt)}/cgi-bin'
+ @hosturl_files='#{@env.url.webserv_files_from_db(@opt)}'
@db_name_prefix='#{Db[:name_prefix]}'
+ @base='#{@env.url.webserv_base_cgi(@opt)}/cgi-bin/#{@env.url.cgi_sample_search_form_name(@opt)}' #fix sqlite
WOK_SQL
end
def search_statement