require 'dbi'
require 'thread'
$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
require "SocketJobRequestListener.rb"
require "JobManager.rb"
require "JobClean.rb"
require "PackageSync.rb"
require "ProjectManager.rb"
require "DistributionManager.rb"
+require "db_utils.rb"
class BuildServer
attr_accessor :id, :path, :status, :host_os, :log
end
def gen_db()
- case @db_dsn
- when /^SQLite3:/ then puts "SQLite3 DB#{@db_dsn.split(':')[1]} generating"
- when /^Mysql:/ then
- name = nil
- host = nil
- port = nil
- socket = nil
- flag = nil
- dsn = @db_dsn.split(':')
- if dsn[2].nil? then
- dsn[1].split(';').each do |attr|
- case attr.split('=')[0].strip
- when /database/i then
- name = attr.split('=')[1].strip
- when /host/i then
- host = attr.split('=')[1].strip
- when /port/i then
- port = attr.split('=')[1].strip
- when /socket/i then
- socket = attr.split('=')[1].strip
- when /flag/i then
- flag = attr.split('=')[1].strip
- else
- etc = attr.split('=')[1].strip
- end
- end
- else
- name = dsn[1].strip
- host = dsn[2].strip
- end
+ hash = DBUtils.dsn_parser @db_dsn
+ case hash[:database]
+ when "SQLite3" then puts "SQLite3 DB#{@db_dsn.split(':')[1]} generating"
+ when "Mysql" then
File.open("create_db.txt","w") do |f|
- f.puts "GRANT ALL ON #{name}.* TO '#{@db_user}'@'%' IDENTIFIED BY '#{@db_passwd}';"
- f.puts "CREATE DATABASE #{name};"
+ f.puts "GRANT ALL ON #{hash[:name]}.* TO '#{@db_user}'@'%' IDENTIFIED BY '#{@db_passwd}';"
+ f.puts "CREATE DATABASE #{hash[:name]};"
end
- if host.eql? "localhost" or host.eql? "127.0.0.1" then
+ if hash[:host].eql? "localhost" or hash[:host].eql? "127.0.0.1" then
socket_str = ""
- socket_str = "--socket=#{socket}" if not socket.nil?
- puts "Mysql DB #{name} generating"
- system("mysql -h #{host} #{socket_str} -u #{@db_user} --password=#{@db_passwd} < create_db.txt")
+ socket_str = "--socket=#{hash[:socket]}" if not hash[:socket].nil?
+ puts "Mysql DB #{hash[:name]} generating"
+ system("mysql -h #{hash[:host]} #{socket_str} -u #{@db_user} --password=#{@db_passwd} < create_db.txt")
else
port_str = ""
- port_str = "-P #{port}" if not port.nil?
- puts "Mysql DB #{name} generating"
- system("mysql -h #{host} #{port_str} -u #{@db_user} --password=#{@db_passwd} < create_db.txt")
+ port_str = "-P #{hash[:port]}" if not port.nil?
+ puts "Mysql DB #{hash[:name]} generating"
+ system("mysql -h #{hash[:host]} #{port_str} -u #{@db_user} --password=#{@db_passwd} < create_db.txt")
end
else puts "not support DB #{@db_dsn}"
end
--- /dev/null
+=begin
+
+ db_utils.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+class DBUtils
+ def DBUtils.dsn_parser (db_dsn)
+ dsn_hash={}
+ case db_dsn
+ when /^SQLite3:/ then puts "SQLite3 DB#{db_dsn.split(':')[1]} generating"
+ dsn_hash[:database] = "SQLite3"
+ when /^Mysql:/ then
+ dsn_hash[:database] = "Mysql"
+ dsn = db_dsn.split(':')
+ if dsn[2].nil? then
+ dsn[1].split(';').each do |attr|
+ case attr.split('=')[0].strip
+ when /database/i then
+ dsn_hash[:name] = attr.split('=')[1].strip
+ when /host/i then
+ dsn_hash[:host] = attr.split('=')[1].strip
+ when /port/i then
+ dsn_hash[:port] = attr.split('=')[1].strip
+ when /socket/i then
+ dsn_hash[:socket] = attr.split('=')[1].strip
+ when /flag/i then
+ dsn_hash[:flag] = attr.split('=')[1].strip
+ else
+ dsn_hash[:etc] = attr.split('=')[1].strip
+ end
+ end
+ else
+ dsn_hash[:name] = dsn[1].strip
+ dsn_hash[:host] = dsn[2].strip
+ end
+ end
+ return dsn_hash
+ end
+end