#!/usr/bin/ruby
=begin
-
+
build-cli
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
require "FileTransferViaDirect"
-#option parsing
+#option parsing
begin
- option = option_parse
+ option = option_parse
rescue => e
- puts e.message
- exit 0
+ puts e.message
+ exit 0
end
def query_system_info(ip, port)
# HOST SYSTEM INFO
- puts "* SYSTEM INFO *"
+ puts "* SYSTEM INFO *"
data = query( ip, port, "SYSTEM")
if data.nil? then exit 1 end
puts "MAX_WORKING_JOBS: #{result[1]}"
# FTP INFO
- puts "\n* FTP *"
+ puts "\n* FTP *"
data = query(ip, port, "FTP")
if data.nil? then exit 1 end
puts "FTP_USERNAME: #{result[1]}"
# SUPPORTED OS INFO
- puts "\n* SUPPORTED OS LIST *"
+ puts "\n* SUPPORTED OS LIST *"
data = query(ip, port, "OS")
if data.nil? then exit 1 end
end
# Friend lists
- puts "\n* FRIEND SERVER LIST (WAIT|WORK/MAX) jobs [transfer count] *"
+ puts "\n* FRIEND SERVER LIST (WAIT|WORK/MAX) jobs [transfer count] *"
data = query(ip, port, "FRIEND")
if data.nil? then exit 1 end
i = 0
# if "--os" is not specified, use pe
if option[:os].nil? then
- option[:os] = "default"
+ option[:os] = "default"
end
if option[:domain].nil? then
begin
case option[:cmd]
when "build"
- result = Utils.parse_server_addr(option[:domain])
- if result.nil? then
- puts "Server address is incorrect. (#{option[:domain]})"
- puts "Tune as following format."
- puts " <ip>:<port>"
- exit 1
- end
+ result = Utils.parse_server_addr(option[:domain])
+ if result.nil? then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
client = BuildCommClient.create( result[0], result[1], nil, 0 )
if not client.nil? then
client.send "BUILD|GIT|#{option[:project]}|#{option[:passwd]}|#{option[:os]}|#{option[:async]}|#{option[:noreverse]}|#{option[:dist]}"
- client.print_stream
+ client.print_stream
client.terminate
else
puts "Connection to server failed!"
exit 1
end
when "resolve"
- result = Utils.parse_server_addr(option[:domain])
- if result.nil? then
- puts "Server address is incorrect. (#{option[:domain]})"
- puts "Tune as following format."
- puts " <ip>:<port>"
- exit 1
- end
+ result = Utils.parse_server_addr(option[:domain])
+ if result.nil? then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
client = BuildCommClient.create( result[0], result[1], nil, 0 )
if not client.nil? then
client.send "RESOLVE|GIT|#{option[:project]}|#{option[:passwd]}|#{option[:os]}|#{option[:async]}|#{option[:dist]}"
- client.print_stream
+ client.print_stream
client.terminate
end
when "query"
- result = Utils.parse_server_addr(option[:domain])
- if result.nil? then
- puts "Server address is incorrect. (#{option[:domain]})"
- puts "Tune as following format."
- puts " <ip>:<port>"
- exit 1
- end
+ result = Utils.parse_server_addr(option[:domain])
+ if result.nil? then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
query_system_info( result[0], result[1] )
puts ""
query_job_list( result[0], result[1])
when "query-system"
- result = Utils.parse_server_addr(option[:domain])
- if result.nil? then
- puts "Server address is incorrect. (#{option[:domain]})"
- puts "Tune as following format."
- puts " <ip>:<port>"
- exit 1
- end
+ result = Utils.parse_server_addr(option[:domain])
+ if result.nil? then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
query_system_info( result[0], result[1] )
when "query-project"
- result = Utils.parse_server_addr(option[:domain])
- if result.nil? then
- puts "Server address is incorrect. (#{option[:domain]})"
- puts "Tune as following format."
- puts " <ip>:<port>"
- exit 1
- end
+ result = Utils.parse_server_addr(option[:domain])
+ if result.nil? then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
query_project_list( result[0], result[1])
when "query-job"
- result = Utils.parse_server_addr(option[:domain])
- if result.nil? then
- puts "Server address is incorrect. (#{option[:domain]})"
- puts "Tune as following format."
- puts " <ip>:<port>"
- exit 1
- end
+ result = Utils.parse_server_addr(option[:domain])
+ if result.nil? then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
query_job_list( result[0], result[1] )
when "cancel"
- result = Utils.parse_server_addr(option[:domain])
- if result.nil? then
- puts "Server address is incorrect. (#{option[:domain]})"
- puts "Tune as following format."
- puts " <ip>:<port>"
- exit 1
- end
+ result = Utils.parse_server_addr(option[:domain])
+ if result.nil? then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
if not option[:job].nil? then
client = BuildCommClient.create( result[0], result[1], nil, 0 )
if not client.nil? then
client.send "CANCEL|#{option[:job]}|#{option[:passwd]}"
- result1 = client.receive_data()
+ result1 = client.receive_data()
if result1.nil? then
client.terminate
exit(-1)
exit(-1)
end
- result = Utils.parse_server_addr(option[:domain])
- if result.nil? then
- puts "Server address is incorrect. (#{option[:domain]})"
- puts "Tune as following format."
- puts " <ip>:<port>"
- exit 1
- end
+ result = Utils.parse_server_addr(option[:domain])
+ if result.nil? then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
bs_ip = result[0]
bs_port = result[1]
if not option[:fdomain].nil? then
- ftp_result = Utils.parse_ftpserver_url(option[:fdomain])
- if ftp_result.nil? or ftp_result.length != 4 then
- puts "FTP server url is incorrect. (#{option[:fdomain]})"
- puts "Tune as following format."
- puts " ftp://<usrename>:<passwd>@<address>"
- exit 1
- end
+ ftp_result = Utils.parse_ftpserver_url(option[:fdomain])
+ if ftp_result.nil? or ftp_result.length != 4 then
+ puts "FTP server url is incorrect. (#{option[:fdomain]})"
+ puts "Tune as following format."
+ puts " ftp://<usrename>:<passwd>@<address>"
+ exit 1
+ end
ip = ftp_result[0]
- port = ftp_result[1]
+ port = ftp_result[1]
username = ftp_result[2]
passwd = ftp_result[3]
transporter = FileTransferFTP.new( nil, ip, port, username, passwd )
exit(-1)
end
client.send("REGISTER|BINARY|#{File.basename(option[:package])}|#{option[:passwd]}|#{dock}|#{option[:dist]}")
- client.print_stream
+ client.print_stream
client.terminate
else
#!/usr/bin/ruby
=begin
-
+
build-svr
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
require "BuildServerOptionParser"
require "BuildServerController"
-#option parsing
+#option parsing
begin
option = option_parse
rescue => e
begin
case option[:cmd]
when "create"
- ftpsvr_addr = nil; ftpsvr_port = nil; ftpsvr_username = nil; ftpsvr_passwd = nil
+ ftpsvr_addr = nil; ftpsvr_port = nil; ftpsvr_username = nil; ftpsvr_passwd = nil
if not option[:fdomain].nil? then
- ftp_result = Utils.parse_ftpserver_url(option[:fdomain])
- if ftp_result.nil? or ftp_result.length != 4 then
- puts "FTP server url is incorrect. (#{option[:fdomain]})"
- puts "Tune as following format."
- puts " ftp://<usrename>:<passwd>@<address>:<port>"
- exit 1
- end
- ftpsvr_addr = ftp_result[0]
- ftpsvr_port = ftp_result[1]
- ftpsvr_username = ftp_result[2]
- ftpsvr_passwd = ftp_result[3]
+ ftp_result = Utils.parse_ftpserver_url(option[:fdomain])
+ if ftp_result.nil? or ftp_result.length != 4 then
+ puts "FTP server url is incorrect. (#{option[:fdomain]})"
+ puts "Tune as following format."
+ puts " ftp://<usrename>:<passwd>@<address>:<port>"
+ exit 1
+ end
+ ftpsvr_addr = ftp_result[0]
+ ftpsvr_port = ftp_result[1]
+ ftpsvr_username = ftp_result[2]
+ ftpsvr_passwd = ftp_result[3]
end
pkgsvr_url = pkgsvr_addr = pkgsvr_port = nil
if not option[:domain].nil? and not option[:url].nil? then
- svr_result = Utils.parse_server_addr(option[:domain])
- if svr_result.nil? or svr_result.length != 2 then
- puts "Server address is incorrect. (#{option[:domain]})"
- puts "Tune as following format."
- puts " <ip>:<port>"
- exit 1
- end
- pkgsvr_url = option[:url]
- pkgsvr_addr = svr_result[0]
- pkgsvr_port = svr_result[1]
+ svr_result = Utils.parse_server_addr(option[:domain])
+ if svr_result.nil? or svr_result.length != 2 then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
+ pkgsvr_url = option[:url]
+ pkgsvr_addr = svr_result[0]
+ pkgsvr_port = svr_result[1]
end
BuildServerController.create_server( option[:name], Utils::WORKING_DIR, ftpsvr_addr, ftpsvr_port, ftpsvr_username, ftpsvr_passwd, pkgsvr_url, pkgsvr_addr, pkgsvr_port )
when "remove"
- BuildServerController.remove_server( option[:name] )
+ BuildServerController.remove_server( option[:name] )
when "start"
if( option[:child] ) then # Child Process
- BuildServerController.start_server( option[:name], option[:port] )
+ BuildServerController.start_server( option[:name], option[:port] )
else # Parent Process
- # check server config
- if not File.exist? "#{BuildServer::CONFIG_ROOT}/#{option[:name]}/server.cfg"
+ # check server config
+ if not File.exist? "#{BuildServer::CONFIG_ROOT}/#{option[:name]}/server.cfg"
raise RuntimeError, "The server \"#{option[:name]}\" does not exist!"
end
log.info "Down Build Server."
break
elsif ($?.exitstatus == 99) then # DIBS UPGRADE
- cmd = "#{File.dirname(__FILE__)}/upgrade -l #{File.dirname(__FILE__)} -S -t BUILDSERVER -n #{option[:name]} -p #{option[:port]}"
+ cmd = "#{File.dirname(__FILE__)}/upgrade -l #{File.dirname(__FILE__)} -S -t BUILDSERVER -n #{option[:name]} -p #{option[:port]}"
cmd = Utils.generate_shell_command(cmd)
puts cmd
Utils.spawn(cmd)
end
end
when "stop"
- BuildServerController.stop_server( option[:name] )
+ BuildServerController.stop_server( option[:name] )
when "upgrade"
- BuildServerController.upgrade_server( option[:name] )
+ BuildServerController.upgrade_server( option[:name] )
when "add-svr"
- svr_result = Utils.parse_server_addr(option[:domain])
- if svr_result.nil? or svr_result.length != 2 then
- puts "Server address is incorrect. Tune as following format."
- puts " <ip>:<port>"
- exit 1
- end
- pkgsvr_addr = svr_result[0]
- pkgsvr_port = svr_result[1]
- BuildServerController.add_remote_server( option[:name], pkgsvr_addr, pkgsvr_port )
+ svr_result = Utils.parse_server_addr(option[:domain])
+ if svr_result.nil? or svr_result.length != 2 then
+ puts "Server address is incorrect. Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
+ pkgsvr_addr = svr_result[0]
+ pkgsvr_port = svr_result[1]
+ BuildServerController.add_remote_server( option[:name], pkgsvr_addr, pkgsvr_port )
when "remove-svr"
BuildServerController.remove_remote_server( option[:name], pkgsvr_addr, pkgsvr_port )
-
+
when "add-os"
- BuildServerController.add_target_os( option[:name], option[:os] )
+ BuildServerController.add_target_os( option[:name], option[:os] )
when "remove-os"
- BuildServerController.remove_target_os( option[:name], option[:os] )
+ BuildServerController.remove_target_os( option[:name], option[:os] )
when "add-dist"
- svr_result = Utils.parse_server_addr(option[:domain])
- if svr_result.nil? or svr_result.length != 2 then
- puts "Server address is incorrect. (#{option[:domain]})"
- puts "Tune as following format."
- puts " <ip>:<port>"
- exit 1
- end
- pkgsvr_url = option[:url]
- pkgsvr_addr = svr_result[0]
- pkgsvr_port = svr_result[1]
- BuildServerController.add_distribution( option[:name], option[:dist], pkgsvr_url, pkgsvr_addr, pkgsvr_port )
+ svr_result = Utils.parse_server_addr(option[:domain])
+ if svr_result.nil? or svr_result.length != 2 then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
+ pkgsvr_url = option[:url]
+ pkgsvr_addr = svr_result[0]
+ pkgsvr_port = svr_result[1]
+ BuildServerController.add_distribution( option[:name], option[:dist], pkgsvr_url, pkgsvr_addr, pkgsvr_port )
when "remove-dist"
- BuildServerController.remove_distribution( option[:name], option[:dist] )
+ BuildServerController.remove_distribution( option[:name], option[:dist] )
when "add-sync"
- BuildServerController.add_sync_package_server( option[:name], option[:url], option[:dist] )
+ BuildServerController.add_sync_package_server( option[:name], option[:url], option[:dist] )
when "remove-sync"
- BuildServerController.remove_sync_package_server( option[:name], option[:url], option[:dist] )
+ BuildServerController.remove_sync_package_server( option[:name], option[:url], option[:dist] )
when "add-prj"
if not option[:git].nil? then
- BuildServerController.add_project( option[:name], option[:pid],
- option[:git], option[:branch], option[:remote], option[:passwd],
- option[:os], option[:dist] )
+ BuildServerController.add_project( option[:name], option[:pid],
+ option[:git], option[:branch], option[:remote], option[:passwd],
+ option[:os], option[:dist] )
else
- BuildServerController.add_binary_project( option[:name], option[:pid],
- option[:package], option[:passwd], option[:os], option[:dist] )
+ BuildServerController.add_binary_project( option[:name], option[:pid],
+ option[:package], option[:passwd], option[:os], option[:dist] )
end
when "remove-prj"
- BuildServerController.remove_project( option[:name], option[:pid], option[:dist] )
+ BuildServerController.remove_project( option[:name], option[:pid], option[:dist] )
when "fullbuild"
- BuildServerController.build_all_projects( option[:name], option[:dist] )
+ BuildServerController.build_all_projects( option[:name], option[:dist] )
when "register"
- BuildServerController.register_package( option[:name], option[:package], option[:dist] )
+ BuildServerController.register_package( option[:name], option[:package], option[:dist] )
when "query"
- BuildServerController.query_server( option[:name] )
+ BuildServerController.query_server( option[:name] )
when "set-attr"
- BuildServerController.set_server_attribute( option[:name], option[:attr], option[:value] )
+ BuildServerController.set_server_attribute( option[:name], option[:attr], option[:value] )
when "get-attr"
- BuildServerController.get_server_attribute( option[:name], option[:attr] )
+ BuildServerController.get_server_attribute( option[:name], option[:attr] )
else
raise RuntimeError, "input option incorrect : #{option[:cmd]}"
-#!/usr/bin/ruby
+#!/usr/bin/ruby
=begin
-
+
pkg-build
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
require "optionparser"
begin
- option = parse
+ option = parse
rescue => e
- puts e.message
- exit 0
+ puts e.message
+ exit 0
end
#generate server when local package server is not set
end
path = Dir.pwd
-if not File.exist? "package" then
- puts "current dirctory \"#{path}\" is not package root directory"
- exit 1
-end
+if not File.exist? "package" then
+ puts "current dirctory \"#{path}\" is not package root directory"
+ exit 1
+end
# if url specified
if not option[:url].nil? then
begin
- builder = Builder.get("default")
+ builder = Builder.get("default")
if builder.pkgserver_url != option[:url] then
puts "Package server URL has been changed! Creating new builder..."
- builder = Builder.create("default", option[:url], nil, nil, nil)
+ builder = Builder.create("default", option[:url], nil, nil, nil)
end
rescue
puts "Default builder does not exist! Creating new builder..."
- builder = Builder.create("default", option[:url], nil, nil, nil)
+ builder = Builder.create("default", option[:url], nil, nil, nil)
end
else # if url is not specified
- begin
- builder = Builder.get("default")
+ begin
+ builder = Builder.get("default")
rescue
puts "Default builder does not exist! Creating new builder..."
- builder = Builder.create("default", "http://172.21.111.132/pkgserver/unstable",nil, nil, nil)
+ builder = Builder.create("default", "http://172.21.111.132/pkgserver/unstable",nil, nil, nil)
end
-end
+end
#build project
if not builder.build( Utils::WORKING_DIR, option[:os], option[:clean], [], true) then
puts "Build Failed!"
- exit 1
+ exit 1
else
puts "Build Succeeded!"
- exit 0
+ exit 0
end
-#!/usr/bin/ruby
+#!/usr/bin/ruby
=begin
-
+
pkg-clean
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
require "CleanOptionParser"
path = Dir.pwd
-if not File.exist? "package" then
- puts "current dirctory \"#{path}\" is not package root directory"
- exit 1
-end
+if not File.exist? "package" then
+ puts "current dirctory \"#{path}\" is not package root directory"
+ exit 1
+end
option = parse
exit 1
end
-begin
- builder = Builder.get("default")
+begin
+ builder = Builder.get("default")
rescue
puts "Default builder does not exist! Creating new builder..."
- builder = Builder.create("default", "http://172.21.111.132/pkgserver/unstable",nil)
+ builder = Builder.create("default", "http://172.21.111.132/pkgserver/unstable",nil)
end
#build project
#!/usr/bin/ruby
=begin
-
+
pkg-cli
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
option = option_parse
rescue => e
# if option parse error print help message
- puts e.message
+ puts e.message
exit 0
end
case option[:cmd]
when "update" then
- client = Client.new( option[:url], nil, nil )
- #client.update()
+ client = Client.new( option[:url], nil, nil )
+ #client.update()
when "clean" then
- client = Client.new( nil, option[:loc], nil )
- client.clean(option[:f])
+ client = Client.new( nil, option[:loc], nil )
+ client.clean(option[:f])
when "download" then
- client = Client.new( option[:url], option[:loc], nil )
- #if not option[:url].nil? then
- # client.update()
- #end
+ client = Client.new( option[:url], option[:loc], nil )
+ #if not option[:url].nil? then
+ # client.update()
+ #end
file_loc = client.download( option[:pkg], option[:os], option[:t] )
when "install" then
- client = Client.new( option[:url], option[:loc], nil )
- #if not option[:url].nil? then
- # client.update()
- #end
- client.install( option[:pkg], option[:os], option[:t], option[:f] )
+ client = Client.new( option[:url], option[:loc], nil )
+ #if not option[:url].nil? then
+ # client.update()
+ #end
+ client.install( option[:pkg], option[:os], option[:t], option[:f] )
when "install-file" then
- client = Client.new( option[:url], option[:loc], nil )
+ client = Client.new( option[:url], option[:loc], nil )
client.install_local_pkg( option[:pkg], option[:t], option[:f] )
when "uninstall" then
- client = Client.new( nil, option[:loc], nil )
- client.uninstall( option[:pkg], option[:t] )
+ client = Client.new( nil, option[:loc], nil )
+ client.uninstall( option[:pkg], option[:t] )
when "upgrade" then
- client = Client.new( option[:url], option[:loc], nil )
- #if not option[:url].nil? then
- # client.update()
- #end
- client.upgrade( option[:os], option[:t] )
+ client = Client.new( option[:url], option[:loc], nil )
+ #if not option[:url].nil? then
+ # client.update()
+ #end
+ client.upgrade( option[:os], option[:t] )
when "check-upgrade" then
- client = Client.new( option[:url], option[:loc], nil )
- #if not option[:url].nil? then
- # client.update()
+ client = Client.new( option[:url], option[:loc], nil )
+ #if not option[:url].nil? then
+ # client.update()
#end
- client.check_upgrade( option[:os] )
+ client.check_upgrade( option[:os] )
when "show-rpkg" then
- client = Client.new( option[:url], nil, nil )
- #if not option[:url].nil? then
- # client.update()
- #end
+ client = Client.new( option[:url], nil, nil )
+ #if not option[:url].nil? then
+ # client.update()
+ #end
puts client.show_pkg_info( option[:pkg], option[:os] )
when "list-rpkg" then
- client = Client.new( option[:url], nil, nil )
- #if not option[:url].nil? then
- # client.update()
- #end
+ client = Client.new( option[:url], nil, nil )
+ #if not option[:url].nil? then
+ # client.update()
+ #end
result = client.show_pkg_list( option[:os] )
- if not result.nil? and not result.empty? then
- result.each do |i|
- name = i[0].strip
- version = i[1].strip
- desc = i[2].strip
- puts name + " (" + version + ")"
- end
- end
+ if not result.nil? and not result.empty? then
+ result.each do |i|
+ name = i[0].strip
+ version = i[1].strip
+ desc = i[2].strip
+ puts name + " (" + version + ")"
+ end
+ end
when "show-lpkg" then
- client = Client.new( nil, option[:loc], nil )
- puts client.show_installed_pkg_info( option[:pkg] )
+ client = Client.new( nil, option[:loc], nil )
+ puts client.show_installed_pkg_info( option[:pkg] )
when "list-lpkg" then
- client = Client.new( nil, option[:loc], nil )
+ client = Client.new( nil, option[:loc], nil )
result = client.show_installed_pkg_list()
- if not result.nil? and not result.empty? then
- result.each do |i|
- name = i[0].strip
- version = i[1].strip
- desc = i[2].strip
- puts name + " (" + version + ")"
- end
- else
- puts "Info: There is no any package."
- end
+ if not result.nil? and not result.empty? then
+ result.each do |i|
+ name = i[0].strip
+ version = i[1].strip
+ desc = i[2].strip
+ puts name + " (" + version + ")"
+ end
+ else
+ puts "Info: There is no any package."
+ end
when "build-dep" then
- client = Client.new( nil, nil, nil )
+ client = Client.new( nil, nil, nil )
result = client.get_build_dependent_packages( option[:pkg], option[:os], true )
- ret = ""
- result.each do |i|
- ret = ret + i + " --> "
- end
- ret = ret.strip
- ret[-3..-1] = ""
- puts ret
+ ret = ""
+ result.each do |i|
+ ret = ret + i + " --> "
+ end
+ ret = ret.strip
+ ret[-3..-1] = ""
+ puts ret
when "install-dep" then
- client = Client.new( nil, nil, nil )
+ client = Client.new( nil, nil, nil )
result = client.get_install_dependent_packages( option[:pkg], option[:os], true, false )
- ret = ""
- result.each do |i|
- ret = ret + i + " --> "
- end
- ret = ret.strip
- ret[-3..-1] = ""
- puts ret
+ ret = ""
+ result.each do |i|
+ ret = ret + i + " --> "
+ end
+ ret = ret.strip
+ ret[-3..-1] = ""
+ puts ret
else
- raise RuntimeError, "Input is incorrect : #{option[:cmd]}"
+ raise RuntimeError, "Input is incorrect : #{option[:cmd]}"
end
#!/usr/bin/ruby
=begin
-
+
pkg-svr
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
=begin
-
+
BinaryUploadProject.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
# create new job
def create_new_job( filename, dock = "0" )
- new_name = filename.sub(/(.*)_(.*)_(.*)\.zip/,'\1,\2,\3')
- pkg_name = new_name.split(",")[0]
- os = new_name.split(",")[2]
+ new_name = filename.sub(/(.*)_(.*)_(.*)\.zip/,'\1,\2,\3')
+ pkg_name = new_name.split(",")[0]
+ os = new_name.split(",")[2]
# check file name
if @pkg_name != pkg_name then
#set up change log
change_log = {}
begin
- change_log = Parser.read_changelog "#{pkginfo_dir}/changelog" if File.exist? "#{pkginfo_dir}/changelog"
+ change_log = Parser.read_changelog "#{pkginfo_dir}/changelog" if File.exist? "#{pkginfo_dir}/changelog"
rescue => e
@server.log.error( e.message, Log::LV_USER)
return nil
=begin
-
+
BuildClientOptionParser.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
class BuildClientUsage
BUILD="build-cli build -N <project name> -d <server address> [-o <os>] [-w <password>] [--async] [-D <distribution name>]"
- RESOLVE="build-cli resolve -N <project name> -d <server address> [-o <os>] [-w <password>] [--async] [-D <distribution name>]"
- QUERY="build-cli query -d <server address>"
- QUERY_SYSTEM="build-cli query-system -d <server address>"
- QUERY_PROJECT="build-cli query-project -d <server address>"
- QUERY_JOB="build-cli query-job -d <server address>"
- CANCEL="build-cli cancel -j <job number> -d <server address> [-w <password>]"
- REGISTER="build-cli register -P <package file> -d <server address> [-t <ftp server url>] [-w <password>] [-D <distribution name>]"
+ RESOLVE="build-cli resolve -N <project name> -d <server address> [-o <os>] [-w <password>] [--async] [-D <distribution name>]"
+ QUERY="build-cli query -d <server address>"
+ QUERY_SYSTEM="build-cli query-system -d <server address>"
+ QUERY_PROJECT="build-cli query-project -d <server address>"
+ QUERY_JOB="build-cli query-job -d <server address>"
+ CANCEL="build-cli cancel -j <job number> -d <server address> [-w <password>]"
+ REGISTER="build-cli register -P <package file> -d <server address> [-t <ftp server url>] [-w <password>] [-D <distribution name>]"
end
def option_error_check( options )
- case options[:cmd]
-
- when "build" then
- if options[:project].nil? or options[:project].empty? or
- options[:domain].nil? or options[:domain].empty? then
- raise ArgumentError, "Usage: " + BuildClientUsage::BUILD
- end
-
- when "resolve" then
- if options[:project].nil? or options[:project].empty? or
- options[:domain].nil? or options[:domain].empty? then
- raise ArgumentError, "Usage: " + BuildClientUsage::RESOLVE
- end
-
- when "query" then
- if options[:domain].nil? or options[:domain].empty? then
- raise ArgumentError, "Usage: " + BuildClientUsage::QUERY
- end
-
- when "query-system" then
- if options[:domain].nil? or options[:domain].empty? then
- raise ArgumentError, "Usage: " + BuildClientUsage::QUERY_SYSTEM
- end
-
- when "query-project" then
- if options[:domain].nil? or options[:domain].empty? then
- raise ArgumentError, "Usage: " + BuildClientUsage::QUERY_PROJECT
- end
-
- when "query-job" then
- if options[:domain].nil? or options[:domain].empty? then
- raise ArgumentError, "Usage: " + BuildClientUsage::QUERY_JOB
- end
-
- when "cancel" then
- if options[:job].nil? or options[:job].empty? or
- options[:domain].nil? or options[:domain].empty? then
- raise ArgumentError, "Usage: " + BuildClientUsage::CANCEL
- end
- when "register" then
- if options[:package].nil? or options[:package].empty? or
- options[:domain].nil? or options[:domain].empty? then
- raise ArgumentError, "Usage: " + BuildClientUsage::REGISTER
- end
-
- else
- raise ArgumentError, "Input is incorrect : #{options[:cmd]}"
- end
+ case options[:cmd]
+
+ when "build" then
+ if options[:project].nil? or options[:project].empty? or
+ options[:domain].nil? or options[:domain].empty? then
+ raise ArgumentError, "Usage: " + BuildClientUsage::BUILD
+ end
+
+ when "resolve" then
+ if options[:project].nil? or options[:project].empty? or
+ options[:domain].nil? or options[:domain].empty? then
+ raise ArgumentError, "Usage: " + BuildClientUsage::RESOLVE
+ end
+
+ when "query" then
+ if options[:domain].nil? or options[:domain].empty? then
+ raise ArgumentError, "Usage: " + BuildClientUsage::QUERY
+ end
+
+ when "query-system" then
+ if options[:domain].nil? or options[:domain].empty? then
+ raise ArgumentError, "Usage: " + BuildClientUsage::QUERY_SYSTEM
+ end
+
+ when "query-project" then
+ if options[:domain].nil? or options[:domain].empty? then
+ raise ArgumentError, "Usage: " + BuildClientUsage::QUERY_PROJECT
+ end
+
+ when "query-job" then
+ if options[:domain].nil? or options[:domain].empty? then
+ raise ArgumentError, "Usage: " + BuildClientUsage::QUERY_JOB
+ end
+
+ when "cancel" then
+ if options[:job].nil? or options[:job].empty? or
+ options[:domain].nil? or options[:domain].empty? then
+ raise ArgumentError, "Usage: " + BuildClientUsage::CANCEL
+ end
+ when "register" then
+ if options[:package].nil? or options[:package].empty? or
+ options[:domain].nil? or options[:domain].empty? then
+ raise ArgumentError, "Usage: " + BuildClientUsage::REGISTER
+ end
+
+ else
+ raise ArgumentError, "Input is incorrect : #{options[:cmd]}"
+ end
if ARGV.length > 1 then
raise ArgumentError, "Unknown argument value : #{ARGV[1]}"
end
def option_parse
- options = {}
- banner = "Requiest service to build-server command-line tool." + "\n" \
- + "\n" + "Usage: build-cli <SUBCOMMAND> [OPTS] or build-cli (-h|-v)" + "\n" \
- + "\n" + "Subcommands:" + "\n" \
- + "\t" + "build Build and create package." + "\n" \
- + "\t" + "resolve Request change to resolve-status for build-conflict." + "\n" \
- + "\t" + "query Query information about build-server." + "\n" \
- + "\t" + "query-system Query system information about build-server." + "\n" \
- + "\t" + "query-project Query project information about build-server." + "\n" \
- + "\t" + "query-job Query job information about build-server." + "\n" \
- + "\t" + "cancel Cancel a building project." + "\n" \
- + "\t" + "register Register the package to the build-server." + "\n" \
- + "\n" + "Subcommand usage:" + "\n" \
- + "\t" + BuildClientUsage::BUILD + "\n" \
- + "\t" + BuildClientUsage::RESOLVE + "\n" \
- + "\t" + BuildClientUsage::QUERY + "\n" \
- + "\t" + BuildClientUsage::QUERY_SYSTEM + "\n" \
- + "\t" + BuildClientUsage::QUERY_PROJECT + "\n" \
- + "\t" + BuildClientUsage::QUERY_JOB + "\n" \
- + "\t" + BuildClientUsage::CANCEL + "\n" \
- + "\t" + BuildClientUsage::REGISTER + "\n" \
- + "\n" + "Options:" + "\n"
-
- optparse = OptionParser.new(nil, 32, ' '*8) do|opts|
-
- # Set a banner, displayed at the top
- # of the help screen.
+ options = {}
+ banner = "Requiest service to build-server command-line tool." + "\n" \
+ + "\n" + "Usage: build-cli <SUBCOMMAND> [OPTS] or build-cli (-h|-v)" + "\n" \
+ + "\n" + "Subcommands:" + "\n" \
+ + "\t" + "build Build and create package." + "\n" \
+ + "\t" + "resolve Request change to resolve-status for build-conflict." + "\n" \
+ + "\t" + "query Query information about build-server." + "\n" \
+ + "\t" + "query-system Query system information about build-server." + "\n" \
+ + "\t" + "query-project Query project information about build-server." + "\n" \
+ + "\t" + "query-job Query job information about build-server." + "\n" \
+ + "\t" + "cancel Cancel a building project." + "\n" \
+ + "\t" + "register Register the package to the build-server." + "\n" \
+ + "\n" + "Subcommand usage:" + "\n" \
+ + "\t" + BuildClientUsage::BUILD + "\n" \
+ + "\t" + BuildClientUsage::RESOLVE + "\n" \
+ + "\t" + BuildClientUsage::QUERY + "\n" \
+ + "\t" + BuildClientUsage::QUERY_SYSTEM + "\n" \
+ + "\t" + BuildClientUsage::QUERY_PROJECT + "\n" \
+ + "\t" + BuildClientUsage::QUERY_JOB + "\n" \
+ + "\t" + BuildClientUsage::CANCEL + "\n" \
+ + "\t" + BuildClientUsage::REGISTER + "\n" \
+ + "\n" + "Options:" + "\n"
+
+ optparse = OptionParser.new(nil, 32, ' '*8) do|opts|
+
+ # Set a banner, displayed at the top
+ # of the help screen.
opts.banner = banner
if not Utils.multi_argument_test( project, "," ) then
raise ArgumentError, "Project variable parsing error : #{project}"
end
- options[:project] = project
- end
+ options[:project] = project
+ end
- options[:domain] = nil
+ options[:domain] = nil
opts.on( '-d', '--address <server address>', 'build server address: 127.0.0.1:2224' ) do|domain|
- options[:domain] = domain
- end
-
- options[:os] = nil
- opts.on( '-o', '--os <operating system>', 'target operating system: ubuntu-32/ubuntu-64/windows-32/windows-64/macos-64' ) do |os|
+ options[:domain] = domain
+ end
+
+ options[:os] = nil
+ opts.on( '-o', '--os <operating system>', 'target operating system: ubuntu-32/ubuntu-64/windows-32/windows-64/macos-64' ) do |os|
if not Utils.multi_argument_test( os, "," ) then
raise ArgumentError, "OS variable parsing error : #{os}"
end
- options[:os] = os
- end
+ options[:os] = os
+ end
- options[:async] = "NO"
+ options[:async] = "NO"
opts.on( '--async', 'asynchronous job' ) do
- options[:async] = "YES"
+ options[:async] = "YES"
end
- options[:noreverse] = "NO"
+ options[:noreverse] = "NO"
opts.on( '--noreverse', 'do not check reverse build' ) do
- options[:noreverse] = "YES"
- end
-
+ options[:noreverse] = "YES"
+ end
+
opts.on( '-j', '--job <job number>', 'job number' ) do|job|
- options[:job] = job
- end
+ options[:job] = job
+ end
- options[:passwd] = ""
+ options[:passwd] = ""
opts.on( '-w', '--passwd <password>', 'password for managing project' ) do|passwd|
- options[:passwd] = passwd
- end
+ options[:passwd] = passwd
+ end
opts.on( '-P', '--pkg <package file>', 'package file path' ) do|package|
- options[:package] = package.strip
- end
+ options[:package] = package.strip
+ end
opts.on( '-D', '--dist <distribution name>', 'distribution name' ) do|dist|
- options[:dist] = dist
- end
+ options[:dist] = dist
+ end
opts.on( '-t', '--ftp <ftp server url>', 'ftp server url: ftp://dibsftp:dibsftp@127.0.0.1' ) do|domain|
- options[:fdomain] = domain
- end
+ options[:fdomain] = domain
+ end
opts.on( '-h', '--help', 'display help' ) do
- opts.help.split("\n").each {|op| puts op if not op.include? "--noreverse"}
+ opts.help.split("\n").each {|op| puts op if not op.include? "--noreverse"}
exit
- end
+ end
opts.on( '-v', '--version', 'display version' ) do
- puts "DIBS(Distributed Intelligent Build System) version " + Utils.get_version()
+ puts "DIBS(Distributed Intelligent Build System) version " + Utils.get_version()
exit
- end
-
- end
-
+ end
+
+ end
+
cmd = ARGV[0]
- if cmd.eql? "build" or cmd.eql? "resolve" or
- cmd.eql? "query" or cmd.eql? "query-system" or
+ if cmd.eql? "build" or cmd.eql? "resolve" or
+ cmd.eql? "query" or cmd.eql? "query-system" or
cmd.eql? "query-project" or cmd.eql? "query-job" or
cmd.eql? "cancel" or
- cmd.eql? "register" or
- cmd =~ /(-v)|(--version)/ or
- cmd =~ /(help)|(-h)|(--help)/ then
+ cmd.eql? "register" or
+ cmd =~ /(-v)|(--version)/ or
+ cmd =~ /(help)|(-h)|(--help)/ then
- if cmd.eql? "help" then
+ if cmd.eql? "help" then
ARGV[0] = "-h"
end
- options[:cmd] = ARGV[0]
- else
- raise ArgumentError, "Usage: build-cli <SUBCOMMAND> [OPTS] or build-cli -h"
- end
+ options[:cmd] = ARGV[0]
+ else
+ raise ArgumentError, "Usage: build-cli <SUBCOMMAND> [OPTS] or build-cli -h"
+ end
+
+ optparse.parse!
- optparse.parse!
+ option_error_check options
- option_error_check options
-
- return options
+ return options
end
@type = "BUILD"
@cancel_state = "NONE"
- @resolve = false
+ @resolve = false
@host_os = Utils::HOST_OS
if not @server.distmgr.nil? then
@pkgsvr_url = @server.distmgr.get_distribution(project.dist_name).pkgsvr_url
@build_dep_prjs = nil # for cacnel pending job
# for resolving build-break
- @rev_fail_projects = [] # list of [project,os]
- @rev_success_jobs = [] # list of job
+ @rev_fail_projects = [] # list of [project,os]
+ @rev_success_jobs = [] # list of job
# remote build
@remote_server = nil
@external_pkgs.push "#{@job_root}/external_pkgs/#{file_name}"
end
-
+
#terminate
def terminate()
#do noting
client = BuildCommClient.create( @remote_server.ip, @remote_server.port, @log )
if not client.nil? then
client.send "CANCEL|#{@remote_id}|#{self.get_project.passwd}"
- result1 = client.receive_data()
+ result1 = client.receive_data()
if result1.nil? then
@log.info( "cancel operation failed [connection error] !!", Log::LV_USER)
else
# and add it into rev_fail_project list if not exist
p_sub_jobs = @server.jobmgr.jobs.select do |j|
( not j.pending_ancestor.nil? and
- "#{j.pending_ancestor.id}" == "#{@pending_ancestor.id}" and
- j.is_build_dependent_project(@project, @os) )
+ "#{j.pending_ancestor.id}" == "#{@pending_ancestor.id}" and
+ j.is_build_dependent_project(@project, @os) )
end
p_sub_jobs.each do |d|
@pending_ancestor.remove_rev_success_job(d)
not (Version.new(@pkginfo.get_version()) == Version.new(o.pkginfo.get_version())) then
return false
end
-
+
# check compat os
@pkginfo.get_target_packages(@os).each do |p|
if not p.os_list.include?(o.os) then return false end
return true
end
-
+
def has_build_dependency?(other_job)
if has_same_packages?(other_job) or
- does_depend_on?(other_job) or
- does_depended_by?(other_job) then
+ does_depend_on?(other_job) or
+ does_depended_by?(other_job) then
return true
else
if get_distribution_name() != wjob.get_distribution_name() then
return false
end
-
+
# same package must have same os
if not @os.eql? wjob.os then
return false
def does_depend_on?( wjob )
-
+
# must have same distribution
if get_distribution_name() != wjob.get_distribution_name() then
return false
end
end
end
-
+
return false
end
prjs = @server.prjmgr.get_projects_from_pkgs(pkgs)
@build_dep_prjs = prjs
end
-
+
return @build_dep_prjs
end
@log.info( "Invoking a thread for building Job #{@id}", Log::LV_USER)
if @status == "ERROR" then return end
@log.info( "New Job #{@id} is started", Log::LV_USER)
-
+
# checking build dependency
if not @is_remote_job and not @is_internal_job and
not check_build_dependency() then
elsif not @parent.nil? and not @is_rev_build_check_job then
copy_result_files(@parent.source_path)
end
-
+
# INFO. don't change this string
@log.info( "Job is completed!", Log::LV_USER)
@status = "FINISHED"
# return pending job that wait for me
def get_pending_ancestor_job()
- @server.jobmgr.get_pending_jobs.each do |job|
+ @server.jobmgr.get_pending_jobs.each do |job|
# must have same distribution
if get_distribution_name() != job.get_distribution_name() then
next
end
-
- if job.is_rev_fail_project(@project,@os) then
- return job
- end
- end
+
+ if job.is_rev_fail_project(@project,@os) then
+ return job
+ end
+ end
return nil
end
end
end
if compat_found then break end
-
+
# check other package already in package server
ver_svr = @pkgsvr_client.get_attr_from_pkg( p.package_name, o, "version")
if not ver_svr.nil? and p.version.eql? ver_svr then
end
else
builder = Builder.create( "JB#{@id}", @pkgsvr_url, nil,
- "#{@buildroot_dir}", @server.build_cache_dir )
+ "#{@buildroot_dir}", @server.build_cache_dir )
if builder.nil?
@log.error( "Creating job builder failed", Log::LV_USER)
return false
@log.info( " - Build Cache Path : #{@server.build_cache_dir}" )
end
@log.info( " - Log Path : #{@log.path}" )
-
+
# if sub job, install dependent packages of parent-pkgs and not clean
use_clean = true
local_pkgs = []
end
# check reverse dependecy if not sub jobs
-
+
if not @no_reverse then
if not @is_rev_build_check_job and not @is_internal_job and
not ReverseBuildChecker.check( self, true ).empty? then
end
else
builder = Builder.create( "JB#{@id}", @pkgsvr_url, nil,
- "#{@buildroot_dir}/#{@os}", @server.build_cache_dir )
+ "#{@buildroot_dir}/#{@os}", @server.build_cache_dir )
if builder.nil?
@log.error( "Creating job builder failed", Log::LV_USER)
return false
if @is_remote_job then
result = builder.build_job(self, [])
else
- result = builder.build_job(self, true, [], false )
+ result = builder.build_job(self, true, [], false )
end
- if not result then
- @log.error( "Building job failed", Log::LV_USER)
+ if not result then
+ @log.error( "Building job failed", Log::LV_USER)
write_log_url()
- return false
- end
+ return false
+ end
# check reverse dependecy
@rev_fail_projects = ReverseBuildChecker.check(self, false)
return true
end
- # pending
- @status = "PENDING"
- @log.info( "Entered the PENDING state ...", Log::LV_USER)
+ # pending
+ @status = "PENDING"
+ @log.info( "Entered the PENDING state ...", Log::LV_USER)
old_msg = ""
- while @status == "PENDING"
+ while @status == "PENDING"
new_msg = @rev_fail_projects.map {|p| "#{p[0].name}(#{p[1]})"}.join(", ")
if old_msg != new_msg then
- @log.error( " * Waiting for building next projects: #{new_msg}", Log::LV_USER)
+ @log.error( " * Waiting for building next projects: #{new_msg}", Log::LV_USER)
old_msg = new_msg
end
- sleep 1
- end
+ sleep 1
+ end
return true
end
end
else
builder = Builder.create( "JB#{@id}", @pkgsvr_url, nil,
- "#{@buildroot_dir}/#{@os}", @server.build_cache_dir )
+ "#{@buildroot_dir}/#{@os}", @server.build_cache_dir )
if builder.nil?
@log.error( "Creating job builder failed", Log::LV_USER)
return false
end
# update the status of pending job
- @status = "PENDING"
- @pending_ancestor.remove_rev_fail_project(@project, @os)
+ @status = "PENDING"
+ @pending_ancestor.remove_rev_fail_project(@project, @os)
@pending_ancestor.rev_success_jobs.push self
if @pending_ancestor.rev_fail_projects.empty? then
@pending_ancestor.status = "RESOLVED"
- @pending_ancestor.rev_success_jobs.each do |job|
- job.status = "RESOLVED"
- end
- else
- @log.info( "Entered the PENDING state ...", Log::LV_USER)
+ @pending_ancestor.rev_success_jobs.each do |job|
+ job.status = "RESOLVED"
+ end
+ else
+ @log.info( "Entered the PENDING state ...", Log::LV_USER)
old_msg = ""
while @status == "PENDING"
new_msg = @pending_ancestor.rev_fail_projects.map {|p| "#{p[0].name}(#{p[1]})"}.join(", ")
sleep 1
end
- end
+ end
return true
end
def upload()
@log.info( "Uploading ...", Log::LV_USER)
-
+
# get package path list
binpkg_path_list = Dir.glob("#{@source_path}/*_*_#{@os}.zip")
return false
end
-
+
# update local
@log.info( "Upload succeeded. Sync local pkg-server again...", Log::LV_USER)
@pkgsvr_client.update
@log.info("Snapshot: #{snapshot}", Log::LV_USER)
-
+
return true
end
def copy_result_files(dst_path)
@log.info( "Copying result files to #{dst_path}", Log::LV_USER)
-
+
# get package path list
binpkg_path_list = Dir.glob("#{@source_path}/*_*_#{@os}.zip")
@log.info( " * #{file}", Log::LV_USER)
FileUtils.cp(file,"#{dst_path}/")
end
-
+
return true
end
@log.info( "Copying log to #{outgoing_dir}", Log::LV_USER)
file = "#{@source_path}/../log"
FileUtils.copy_file(file, "#{outgoing_dir}/remote_log")
-
+
# copy result files, if not reverse build
if not @is_rev_build_check_job then
return copy_result_files( outgoing_dir )
chained_deps = []
chained_deps += deps
-
+
# if parent is multi build job, gether all install dependency of dependency.
if parent.type == "MULTIBUILD" then
begin
dep_target_os = @os
end
end
-
+
end
@test_time=0 #test time in mili-seconds
@password="0000"
@keep_time=86400
- @ftp_addr = ftpsvr_addr
- @ftp_port = ftpsvr_port
- @ftp_username = ftpsvr_username
- @ftp_passwd = ftpsvr_passwd
+ @ftp_addr = ftpsvr_addr
+ @ftp_port = ftpsvr_port
+ @ftp_username = ftpsvr_username
+ @ftp_passwd = ftpsvr_passwd
@cleaner=nil
@prjmgr = ProjectManager.new(self)
@distmgr = DistributionManager.new(self)
@pkg_sync = PackageServerSynchronizer.new(self)
@pkg_sync.start
end
-
+
# main loop
@log.info "Entering main loop..."
begin
if @test_time > 0 then start_time = Time.now end
while( not @finish )
-
+
# update friend server status
@friend_servers.each do |server|
# update state
server.update_state
end
-
+
# handle jobs
@jobmgr.handle()
-
+
# sleep
if @test_time > 0 then
curr_time = Time.now
# add new remote friend server
def add_remote_server( ip, port )
-
+
# if already exit, return false
@friend_servers.each do |svr|
if svr.ip.eql? ip and svr.port == port then
# add new remote pkg server
def add_sync_package_server( url, dist )
-
+
# if already exit, return false
@remote_pkg_servers.each do |e|
if e[0] == url and e[1] == dist then
# remove remote pkg server
def remove_sync_package_server( url, dist )
-
+
# if already exit, return false
@remote_pkg_servers.each do |e|
if e[0] == url and e[1] == dist then
# add new target OS.
# If already exist, return false , otherwise true
def add_target_os( os_name )
-
+
# if already exit, return false
@supported_os_list.each do |os|
if os.eql? os_name then
# get remote server
def get_available_server ( job )
candidates = []
-
+
# calculate empty rooms
# if sub job, his parent should be excluded
local_empty_rooms = @jobmgr.get_number_of_empty_room
# skip
if server == best_server then next end
-
+
# compare remain rooms
empty_room = server.get_number_of_empty_room
if empty_room > max_empty_room then
best_server = server
end
end
-
+
return best_server
end
return false
end
-
+
# return available working slot
def get_number_of_empty_room
return @jobmgr.get_number_of_empty_room
db.do "CREATE TABLE IF NOT EXISTS project_os(prj_id INTEGER, os_name VARCHAR(32))"
db.do "CREATE TABLE IF NOT EXISTS users(user_id INTEGER PRIMARY KEY AUTOINCREMENT, email VARCHAR(256), password VARCHAR(256), password_salt VARCHAR(256), user_name VARCHAR(256), group_id VARCHAR(256))"
db.do "CREATE TABLE IF NOT EXISTS groups(group_id INTEGER PRIMARY KEY AUTOINCREMENT, group_name VARCHAR(256))"
- rescue DBI::DatabaseError => e
- puts "DB Creation failed!"
- puts e.errstr
- result = false
- ensure
- db.disconnect if db
- end
- return result
- end
-
-
- # save
- def save_db()
-
- result = true
- # distribution
- @distmgr.save_db()
-
- sqlite_db_file = "DBI:SQLite3:#{BuildServer::CONFIG_ROOT}/#{@id}/server.db"
- begin
- # open DB
- db = DBI.connect(sqlite_db_file)
-
- # remote_build_servers
- db.do "DELETE FROM remote_build_servers"
- @friend_servers.each { |svr|
- db.do "INSERT INTO remote_build_servers (svr_addr) VALUES('#{svr.ip}:#{svr.port}')"
- }
-
- # sync_pkg_servers
- db.do "DELETE FROM sync_pkg_servers"
- @remote_pkg_servers.each { |svr|
- db.do "INSERT INTO sync_pkg_servers (pkgsvr_url,period,dist_name) VALUES('#{svr[0]}','#{@pkg_sync_period}','#{svr[1]}')"
- }
-
- # supported_os
- db.do "DELETE FROM supported_os"
- @supported_os_list.each { |os|
- db.do "INSERT INTO supported_os VALUES('#{os}')"
- }
-
- rescue DBI::DatabaseError => e
- puts "DB update failed!"
- puts e.errstr
- result = false
- ensure
- db.disconnect if db
- end
-
- return result
- end
+ rescue DBI::DatabaseError => e
+ puts "DB Creation failed!"
+ puts e.errstr
+ result = false
+ ensure
+ db.disconnect if db
+ end
+ return result
+ end
- # load
- def load_db()
+ # save
+ def save_db()
+
+ result = true
+ # distribution
+ @distmgr.save_db()
+
+ sqlite_db_file = "DBI:SQLite3:#{BuildServer::CONFIG_ROOT}/#{@id}/server.db"
+ begin
+ # open DB
+ db = DBI.connect(sqlite_db_file)
+
+ # remote_build_servers
+ db.do "DELETE FROM remote_build_servers"
+ @friend_servers.each { |svr|
+ db.do "INSERT INTO remote_build_servers (svr_addr) VALUES('#{svr.ip}:#{svr.port}')"
+ }
+
+ # sync_pkg_servers
+ db.do "DELETE FROM sync_pkg_servers"
+ @remote_pkg_servers.each { |svr|
+ db.do "INSERT INTO sync_pkg_servers (pkgsvr_url,period,dist_name) VALUES('#{svr[0]}','#{@pkg_sync_period}','#{svr[1]}')"
+ }
+
+ # supported_os
+ db.do "DELETE FROM supported_os"
+ @supported_os_list.each { |os|
+ db.do "INSERT INTO supported_os VALUES('#{os}')"
+ }
+
+ rescue DBI::DatabaseError => e
+ puts "DB update failed!"
+ puts e.errstr
+ result = false
+ ensure
+ db.disconnect if db
+ end
+
+ return result
+ end
- result = true
- # distribution
- @distmgr.load_db()
- sqlite_db_file = "DBI:SQLite3:#{BuildServer::CONFIG_ROOT}/#{@id}/server.db"
- begin
- # open DB
- db = DBI.connect(sqlite_db_file)
- #db.results_as_hash = true
-
- # remote_build_servers
- @friend_servers = []
- sth = db.execute "SELECT * FROM remote_build_servers"
- sth.fetch_hash { |row|
- add_remote_server(
- row['svr_addr'].split(":")[0],
- row['svr_addr'].split(":")[1].to_i)
- }
- sth.finish
- # sync_package_servers
- @remote_pkg_servers = []
- sth = db.execute "SELECT * FROM sync_pkg_servers"
- sth.fetch_hash { |row|
- add_sync_package_server( row['pkgsvr_url'], row['dist_name'] )
- @pkg_sync_period = row['period'].to_i
- }
- sth.finish
-
- # supported_os
- @supported_os_list = []
- sth = db.execute "SELECT * FROM supported_os"
- sth.fetch_hash { |row|
- add_target_os( row['name'] )
- }
- sth.finish
- rescue DBI::DatabaseError => e
- puts "DB loading failed!"
- puts e.errstr
- result = false
- ensure
- sth.finish if not sth.finished?
- db.disconnect if db
- end
- return result
- end
+ # load
+ def load_db()
+
+ result = true
+ # distribution
+ @distmgr.load_db()
+
+ sqlite_db_file = "DBI:SQLite3:#{BuildServer::CONFIG_ROOT}/#{@id}/server.db"
+ begin
+ # open DB
+ db = DBI.connect(sqlite_db_file)
+ #db.results_as_hash = true
+
+ # remote_build_servers
+ @friend_servers = []
+ sth = db.execute "SELECT * FROM remote_build_servers"
+ sth.fetch_hash { |row|
+ add_remote_server(
+ row['svr_addr'].split(":")[0],
+ row['svr_addr'].split(":")[1].to_i)
+ }
+ sth.finish
+ # sync_package_servers
+ @remote_pkg_servers = []
+ sth = db.execute "SELECT * FROM sync_pkg_servers"
+ sth.fetch_hash { |row|
+ add_sync_package_server( row['pkgsvr_url'], row['dist_name'] )
+ @pkg_sync_period = row['period'].to_i
+ }
+ sth.finish
+
+ # supported_os
+ @supported_os_list = []
+ sth = db.execute "SELECT * FROM supported_os"
+ sth.fetch_hash { |row|
+ add_target_os( row['name'] )
+ }
+ sth.finish
+ rescue DBI::DatabaseError => e
+ puts "DB loading failed!"
+ puts e.errstr
+ result = false
+ ensure
+ sth.finish if not sth.finished?
+ db.disconnect if db
+ end
+ return result
+ end
-end
+ end
@@instance_map[id].jobmgr.max_working_jobs= 2
@@instance_map[id].job_log_url=""
@@instance_map[id].send_mail="NO"
-
+
# write config
write_server_config( @@instance_map[id] )
# start server
def self.start_server( id, port = 2222 )
server = get_server(id)
-
+
# write run port
server_dir = "#{BuildServer::CONFIG_ROOT}/#{server.id}"
f = File.open( "#{server_dir}/run", "w" )
# terminate
client.terminate
-
+
if not stop_ok then
puts "Server stop failed!"
end
# terminate
client.terminate
-
+
if not upgrade_ok then
puts "Server upgrade failed!"
end
server = get_server(id)
server_dir = "#{BuildServer::CONFIG_ROOT}/#{id}"
-
+
if File.exist? "#{server_dir}/friends" then
File.open( "#{server_dir}/friends", "r" ) do |f|
f.each_line do |l|
if l.split(",").count < 2 then next end
ip = l.split(",")[0].strip
port = l.split(",")[1].strip
-
+
client = BuildCommClient.create( ip, port )
if client.nil? then
puts "Friend Server #{ip}:#{port} is not running!"
upgrade_ok = true
end
end
-
+
# terminate
client.terminate
-
+
if upgrade_ok then
puts "Friend Server #{ip}:#{port} upgrade requested!"
else
else
puts "No Friend Server."
end
-
+
return true
end
# add friend server
def self.add_remote_server( id, ip, port )
server = get_server(id)
-
+
# add
if server.add_remote_server( ip, port ) then
if server.save_db() then
# remove friend server
def self.remove_remote_server( id, ip, port )
server = get_server(id)
-
+
# add
if server.remove_remote_server( ip, port ) then
if server.save_db() then
# get server
server = get_server(id)
-
+
# add
if server.add_target_os( os_name ) then
if server.save_db() then
def self.remove_target_os( id, os_name )
# get server
server = get_server(id)
-
+
# add
if server.remove_target_os( os_name ) then
if server.save_db() then
def self.add_distribution( id, dist_name, pkgsvr_url, pkgsvr_ip, pkgsvr_port )
# get server
server = get_server(id)
-
+
# add
if server.distmgr.add_distribution( dist_name, pkgsvr_url, pkgsvr_ip, pkgsvr_port ) then
if server.save_db() then
def self.remove_distribution( id, dist_name )
# get server
server = get_server(id)
-
+
# remove
if server.distmgr.remove_distribution( dist_name ) then
if server.save_db() then
# add remote package server
def self.add_sync_package_server(id, url, dist_name)
server = get_server(id)
-
+
# check distribution
dist_name = check_distribution_name(dist_name, server)
if dist_name.nil? then return false end
# add project
def self.add_project( id, project_name, git_repos, git_branch, remote_server_id,
- passwd, os_string, dist_name )
+ passwd, os_string, dist_name )
# get server
server = get_server(id)
-
+
# get supported os for project.
# if not specified, all supported os of the server will be used
if os_string.nil? or os_string.empty? then
def self.add_binary_project( id, project_name, pkg_name, passwd, os_string, dist_name )
# get server
server = get_server(id)
-
+
# get supported os for project.
# if not specified, all supported os of the server will be used
if os_string.nil? or os_string == "default" then
# add
result = server.prjmgr.add_binary_project( project_name, pkg_name, passwd,
- os_list, dist_name )
+ os_list, dist_name )
if result then
puts "Adding project succeeded!"
return true
def self.remove_project( id, project_name, dist_name )
# get server
server = get_server(id)
-
+
# check distribution
dist_name = check_distribution_name(dist_name, server)
if dist_name.nil? then return false end
# terminate
client.terminate
-
+
if not fullbuild_ok then
puts "Full build failed!"
end
# terminate
client.terminate
-
+
if not success then
puts "Registering package failed!"
end
server.keep_time = value.to_i
when "FTP_ADDR"
server.ftp_addr = value
- when "FTP_PORT"
- server.ftp_port = value
+ when "FTP_PORT"
+ server.ftp_port = value
when "FTP_USERNAME"
server.ftp_username = value
when "FTP_PASSWD"
puts "#{server.keep_time}"
when "FTP_ADDR"
puts server.ftp_addr
- when "FTP_PORT"
- puts server.ftp_port
+ when "FTP_PORT"
+ puts server.ftp_port
when "FTP_USERNAME"
puts server.ftp_username
when "FTP_PASSWD"
elsif l.start_with?("JOB_KEEP_TIME=")
keep_time = l[idx,length].strip.to_i
elsif l.start_with?("FTP_URL=")
- ftp_result = Utils.parse_ftpserver_url(l[idx,length].strip)
- ftp_addr = ftp_result[0]
- ftp_port = ftp_result[1]
- ftp_username = ftp_result[2]
- ftp_passwd = ftp_result[3]
+ ftp_result = Utils.parse_ftpserver_url(l[idx,length].strip)
+ ftp_addr = ftp_result[0]
+ ftp_port = ftp_result[1]
+ ftp_username = ftp_result[2]
+ ftp_passwd = ftp_result[3]
elsif l.start_with?("PKG_SYNC_PERIOD=")
pkg_sync_period = l[idx,length].strip.to_i
elsif l.start_with?("CHANGELOG_CHECK=")
# set git binary path
obj.git_bin_path = git_bin_path
-
+
# set git binary path
obj.jobmgr.max_working_jobs = max_working_jobs
=begin
-
+
BuildServerOptionParser.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
end
def option_error_check( options )
- case options[:cmd]
-
- when "create"
- if options[:name].nil? or options[:name].empty? then
- raise ArgumentError, "Usage: " + BuildServerUsage::CREATE
- end
-
- when "remove"
- if options[:name].nil? or options[:name].empty? then
- raise ArgumentError, "Usage: " + BuildServerUsage::REMOVE
- end
-
- when "start"
- if options[:name].nil? or options[:name].empty? or
- options[:port].nil? then
- raise ArgumentError, "Usage: " + BuildServerUsage::START
- end
-
- when "stop"
- if options[:name].nil? or options[:name].empty? then
- raise ArgumentError, "Usage: " + BuildServerUsage::STOP
- end
-
- when "upgrade"
- if options[:name].nil? or options[:name].empty? then
- raise ArgumentError, "Usage: " + BuildServerUsage::UPGRADE
- end
-
- when "add-svr"
- if options[:name].nil? or options[:name].empty? or
+ case options[:cmd]
+
+ when "create"
+ if options[:name].nil? or options[:name].empty? then
+ raise ArgumentError, "Usage: " + BuildServerUsage::CREATE
+ end
+
+ when "remove"
+ if options[:name].nil? or options[:name].empty? then
+ raise ArgumentError, "Usage: " + BuildServerUsage::REMOVE
+ end
+
+ when "start"
+ if options[:name].nil? or options[:name].empty? or
+ options[:port].nil? then
+ raise ArgumentError, "Usage: " + BuildServerUsage::START
+ end
+
+ when "stop"
+ if options[:name].nil? or options[:name].empty? then
+ raise ArgumentError, "Usage: " + BuildServerUsage::STOP
+ end
+
+ when "upgrade"
+ if options[:name].nil? or options[:name].empty? then
+ raise ArgumentError, "Usage: " + BuildServerUsage::UPGRADE
+ end
+
+ when "add-svr"
+ if options[:name].nil? or options[:name].empty? or
(options[:domain].nil? or options[:domain].empty?) then
- raise ArgumentError, "Usage: " + BuildServerUsage::ADD_SVR
- end
+ raise ArgumentError, "Usage: " + BuildServerUsage::ADD_SVR
+ end
- when "remove-svr"
- if options[:name].nil? or options[:name].empty? or
+ when "remove-svr"
+ if options[:name].nil? or options[:name].empty? or
(options[:domain].nil? or options[:domain].empty?) then
- raise ArgumentError, "Usage: " + BuildServerUsage::REMOVE_SVR
- end
-
- when "add-os"
- if options[:name].nil? or options[:name].empty? or
- options[:os].nil? or options[:os].empty? then
- raise ArgumentError, "Usage: " + BuildServerUsage::ADD_OS
- end
-
- when "remove-os"
- if options[:name].nil? or options[:name].empty? or
- options[:os].nil? or options[:os].empty? then
- raise ArgumentError, "Usage: " + BuildServerUsage::REMOVE_OS
- end
-
- when "add-dist"
- if options[:name].nil? or options[:name].empty? or
- options[:dist].nil? or options[:dist].empty? or
- options[:url].nil? or options[:url].empty? or
+ raise ArgumentError, "Usage: " + BuildServerUsage::REMOVE_SVR
+ end
+
+ when "add-os"
+ if options[:name].nil? or options[:name].empty? or
+ options[:os].nil? or options[:os].empty? then
+ raise ArgumentError, "Usage: " + BuildServerUsage::ADD_OS
+ end
+
+ when "remove-os"
+ if options[:name].nil? or options[:name].empty? or
+ options[:os].nil? or options[:os].empty? then
+ raise ArgumentError, "Usage: " + BuildServerUsage::REMOVE_OS
+ end
+
+ when "add-dist"
+ if options[:name].nil? or options[:name].empty? or
+ options[:dist].nil? or options[:dist].empty? or
+ options[:url].nil? or options[:url].empty? or
options[:domain].nil? or options[:domain].empty? then
- raise ArgumentError, "Usage: " + BuildServerUsage::ADD_DIST
- end
-
- when "remove-dist"
- if options[:name].nil? or options[:name].empty? or
- options[:dist].nil? or options[:dist].empty? then
- raise ArgumentError, "Usage: " + BuildServerUsage::REMOVE_DIST
- end
-
- when "add-sync"
- if options[:name].nil? or options[:name].empty? or
- (options[:url].nil? or options[:url].empty?) then
- raise ArgumentError, "Usage: " + BuildServerUsage::ADD_SYNC
- end
-
- when "remove-sync"
- if options[:name].nil? or options[:name].empty? or
- (options[:url].nil? or options[:url].empty?) then
- raise ArgumentError, "Usage: " + BuildServerUsage::REMOVE_SYNC
- end
-
- when "add-prj"
- if options[:name].nil? or options[:name].empty? or
- options[:pid].nil? or options[:pid].empty? then
- raise ArgumentError, "Usage: " + BuildServerUsage::ADD_PRJ
- end
-
- when "remove-prj"
- if options[:name].nil? or options[:name].empty? or
- options[:pid].nil? or options[:pid].empty? then
- raise ArgumentError, "Usage: " + BuildServerUsage::REMOVE_PRJ
- end
-
- when "fullbuild"
- if options[:name].nil? or options[:name].empty? then
- raise ArgumentError, "Usage: " + BuildServerUsage::FULLBUILD
- end
-
- when "register"
- if options[:name].nil? or options[:name].empty? or
+ raise ArgumentError, "Usage: " + BuildServerUsage::ADD_DIST
+ end
+
+ when "remove-dist"
+ if options[:name].nil? or options[:name].empty? or
+ options[:dist].nil? or options[:dist].empty? then
+ raise ArgumentError, "Usage: " + BuildServerUsage::REMOVE_DIST
+ end
+
+ when "add-sync"
+ if options[:name].nil? or options[:name].empty? or
+ (options[:url].nil? or options[:url].empty?) then
+ raise ArgumentError, "Usage: " + BuildServerUsage::ADD_SYNC
+ end
+
+ when "remove-sync"
+ if options[:name].nil? or options[:name].empty? or
+ (options[:url].nil? or options[:url].empty?) then
+ raise ArgumentError, "Usage: " + BuildServerUsage::REMOVE_SYNC
+ end
+
+ when "add-prj"
+ if options[:name].nil? or options[:name].empty? or
+ options[:pid].nil? or options[:pid].empty? then
+ raise ArgumentError, "Usage: " + BuildServerUsage::ADD_PRJ
+ end
+
+ when "remove-prj"
+ if options[:name].nil? or options[:name].empty? or
+ options[:pid].nil? or options[:pid].empty? then
+ raise ArgumentError, "Usage: " + BuildServerUsage::REMOVE_PRJ
+ end
+
+ when "fullbuild"
+ if options[:name].nil? or options[:name].empty? then
+ raise ArgumentError, "Usage: " + BuildServerUsage::FULLBUILD
+ end
+
+ when "register"
+ if options[:name].nil? or options[:name].empty? or
options[:package].nil? or options[:package].empty? then
- raise ArgumentError, "Usage: " + BuildServerUsage::REGISTER
- end
-
- when "query"
- if options[:name].nil? or options[:name].empty? then
- raise ArgumentError, "Usage: " + BuildServerUsage::QUERY
- end
-
- when "set-attr"
- if options[:name].nil? or options[:name].empty? or
- options[:attr].nil? or options[:attr].empty? or
- options[:value].nil? or options[:value].empty? then
- raise ArgumentError, "Usage: " + BuildServerUsage::SET_ATTR
- end
-
- when "get-attr"
- if options[:name].nil? or options[:name].empty? or
- options[:attr].nil? or options[:attr].empty? then
- raise ArgumentError, "Usage: " + BuildServerUsage::SET_ATTR
- end
-
- else
- raise ArgumentError, "Input is incorrect : #{options[:cmd]}"
- end
+ raise ArgumentError, "Usage: " + BuildServerUsage::REGISTER
+ end
+
+ when "query"
+ if options[:name].nil? or options[:name].empty? then
+ raise ArgumentError, "Usage: " + BuildServerUsage::QUERY
+ end
+
+ when "set-attr"
+ if options[:name].nil? or options[:name].empty? or
+ options[:attr].nil? or options[:attr].empty? or
+ options[:value].nil? or options[:value].empty? then
+ raise ArgumentError, "Usage: " + BuildServerUsage::SET_ATTR
+ end
+
+ when "get-attr"
+ if options[:name].nil? or options[:name].empty? or
+ options[:attr].nil? or options[:attr].empty? then
+ raise ArgumentError, "Usage: " + BuildServerUsage::SET_ATTR
+ end
+
+ else
+ raise ArgumentError, "Input is incorrect : #{options[:cmd]}"
+ end
end
def option_parse
- options = {}
- banner = "Build-server administer service command-line tool." + "\n" \
- + "\n" + "Usage: build-svr <SUBCOMMAND> [OPTS] or build-svr (-h|-v)" + "\n" \
- + "\n" + "Subcommands:" + "\n" \
- + "\t" + "create Create the build-server." + "\n" \
- + "\t" + "remove Remove the build-server." + "\n" \
- + "\t" + "start Start the build-server." + "\n" \
- + "\t" + "stop Stop the build-server." + "\n" \
- + "\t" + "upgrade Upgrade the build-server include friends." + "\n" \
- + "\t" + "add-svr Add remote build/package server for support multi-OS or distribute build job." + "\n" \
- + "\t" + "remove-svr Remove remote build/package server for support multi-OS or distribute build job." + "\n" \
- + "\t" + "add-os Add supported OS." + "\n" \
- + "\t" + "remove-os Remove supported OS." + "\n" \
- + "\t" + "add-dist Add distribution." + "\n" \
- + "\t" + "remove-dist Remove distribution." + "\n" \
- + "\t" + "add-sync Add package repository URL to synchronize with." + "\n" \
- + "\t" + "remove-sync Remove package repository URL." + "\n" \
- + "\t" + "add-prj Add project to build." + "\n" \
- + "\t" + "remove-prj Remove project." + "\n" \
- + "\t" + "register Register the package to the build-server." + "\n" \
- + "\t" + "fullbuild Build all your projects and upload them to package server." + "\n" \
- + "\t" + "query Show build server configuration." + "\n" \
- + "\t" + "set-attr Set build server atribute." + "\n" \
- + "\t" + "get-attr Get build server atribute." + "\n" \
- + "\n" + "Subcommand usage:" + "\n" \
- + "\t" + BuildServerUsage::CREATE + "\n" \
- + "\t" + BuildServerUsage::REMOVE + "\n" \
- + "\t" + BuildServerUsage::START + "\n" \
- + "\t" + BuildServerUsage::STOP + "\n" \
- + "\t" + BuildServerUsage::UPGRADE + "\n" \
- + "\t" + BuildServerUsage::ADD_SVR + "\n" \
- + "\t" + BuildServerUsage::REMOVE_SVR + "\n" \
- + "\t" + BuildServerUsage::ADD_OS + "\n" \
- + "\t" + BuildServerUsage::REMOVE_OS + "\n" \
- + "\t" + BuildServerUsage::ADD_DIST + "\n" \
- + "\t" + BuildServerUsage::REMOVE_DIST + "\n" \
- + "\t" + BuildServerUsage::ADD_SYNC + "\n" \
- + "\t" + BuildServerUsage::REMOVE_SYNC + "\n" \
- + "\t" + BuildServerUsage::ADD_PRJ + "\n" \
- + "\t" + BuildServerUsage::REMOVE_PRJ + "\n" \
- + "\t" + BuildServerUsage::FULLBUILD + "\n" \
- + "\t" + BuildServerUsage::REGISTER + "\n" \
- + "\t" + BuildServerUsage::QUERY + "\n" \
- + "\t" + BuildServerUsage::SET_ATTR + "\n" \
- + "\t" + BuildServerUsage::GET_ATTR + "\n" \
- + "\n" + "Options:" + "\n"
-
- optparse = OptionParser.new(nil, 32, ' '*8) do|opts|
- # Set a banner, displayed at the top
- # of the help screen.
+ options = {}
+ banner = "Build-server administer service command-line tool." + "\n" \
+ + "\n" + "Usage: build-svr <SUBCOMMAND> [OPTS] or build-svr (-h|-v)" + "\n" \
+ + "\n" + "Subcommands:" + "\n" \
+ + "\t" + "create Create the build-server." + "\n" \
+ + "\t" + "remove Remove the build-server." + "\n" \
+ + "\t" + "start Start the build-server." + "\n" \
+ + "\t" + "stop Stop the build-server." + "\n" \
+ + "\t" + "upgrade Upgrade the build-server include friends." + "\n" \
+ + "\t" + "add-svr Add remote build/package server for support multi-OS or distribute build job." + "\n" \
+ + "\t" + "remove-svr Remove remote build/package server for support multi-OS or distribute build job." + "\n" \
+ + "\t" + "add-os Add supported OS." + "\n" \
+ + "\t" + "remove-os Remove supported OS." + "\n" \
+ + "\t" + "add-dist Add distribution." + "\n" \
+ + "\t" + "remove-dist Remove distribution." + "\n" \
+ + "\t" + "add-sync Add package repository URL to synchronize with." + "\n" \
+ + "\t" + "remove-sync Remove package repository URL." + "\n" \
+ + "\t" + "add-prj Add project to build." + "\n" \
+ + "\t" + "remove-prj Remove project." + "\n" \
+ + "\t" + "register Register the package to the build-server." + "\n" \
+ + "\t" + "fullbuild Build all your projects and upload them to package server." + "\n" \
+ + "\t" + "query Show build server configuration." + "\n" \
+ + "\t" + "set-attr Set build server atribute." + "\n" \
+ + "\t" + "get-attr Get build server atribute." + "\n" \
+ + "\n" + "Subcommand usage:" + "\n" \
+ + "\t" + BuildServerUsage::CREATE + "\n" \
+ + "\t" + BuildServerUsage::REMOVE + "\n" \
+ + "\t" + BuildServerUsage::START + "\n" \
+ + "\t" + BuildServerUsage::STOP + "\n" \
+ + "\t" + BuildServerUsage::UPGRADE + "\n" \
+ + "\t" + BuildServerUsage::ADD_SVR + "\n" \
+ + "\t" + BuildServerUsage::REMOVE_SVR + "\n" \
+ + "\t" + BuildServerUsage::ADD_OS + "\n" \
+ + "\t" + BuildServerUsage::REMOVE_OS + "\n" \
+ + "\t" + BuildServerUsage::ADD_DIST + "\n" \
+ + "\t" + BuildServerUsage::REMOVE_DIST + "\n" \
+ + "\t" + BuildServerUsage::ADD_SYNC + "\n" \
+ + "\t" + BuildServerUsage::REMOVE_SYNC + "\n" \
+ + "\t" + BuildServerUsage::ADD_PRJ + "\n" \
+ + "\t" + BuildServerUsage::REMOVE_PRJ + "\n" \
+ + "\t" + BuildServerUsage::FULLBUILD + "\n" \
+ + "\t" + BuildServerUsage::REGISTER + "\n" \
+ + "\t" + BuildServerUsage::QUERY + "\n" \
+ + "\t" + BuildServerUsage::SET_ATTR + "\n" \
+ + "\t" + BuildServerUsage::GET_ATTR + "\n" \
+ + "\n" + "Options:" + "\n"
+
+ optparse = OptionParser.new(nil, 32, ' '*8) do|opts|
+ # Set a banner, displayed at the top
+ # of the help screen.
opts.banner = banner
- opts.on( '-n', '--name <server name>', 'build server name' ) do|name|
- options[:name] = name
- end
-
+ opts.on( '-n', '--name <server name>', 'build server name' ) do|name|
+ options[:name] = name
+ end
+
opts.on( '-u', '--url <package server url>', 'package server url: http://127.0.0.1/dibs/unstable' ) do|url|
- options[:url] = url
- end
+ options[:url] = url
+ end
opts.on( '-d', '--address <server address>', 'server address: 127.0.0.1:2224' ) do|domain|
- options[:domain] = domain
- end
-
- options[:port] = 2222
+ options[:domain] = domain
+ end
+
+ options[:port] = 2222
opts.on( '-p', '--port <port>', 'server port number: 2224' ) do|port|
- options[:port] = port.strip.to_i
- end
+ options[:port] = port.strip.to_i
+ end
opts.on( '-P', '--pkg <package name/file>', 'package file path or name' ) do|package|
- options[:package] = package.strip
- end
+ options[:package] = package.strip
+ end
- options[:os] = nil
+ options[:os] = nil
opts.on( '-o', '--os <target os list>', 'ex) ubuntu-32,windows-32' ) do|os|
if not Utils.multi_argument_test( os, "," ) then
raise ArgumentError, "OS variable parsing error : #{os}"
end
- options[:os] = os
- end
+ options[:os] = os
+ end
opts.on( '-N', '--pname <project name>', 'project name' ) do|pid|
- options[:pid] = pid
- end
+ options[:pid] = pid
+ end
opts.on( '-g', '--git <git repository>', 'git repository' ) do|git|
- options[:git] = git
- end
+ options[:git] = git
+ end
opts.on( '-b', '--branch <git branch>', 'git branch' ) do|branch|
- options[:branch] = branch
- end
+ options[:branch] = branch
+ end
#opts.on( '-r', '--remote <remote server id>', 'remote server id' ) do|remote|
- # options[:remote] = remote
- #end
- options[:dist] = ""
+ # options[:remote] = remote
+ #end
+ options[:dist] = ""
opts.on( '-D', '--dist <distribution name>', 'distribution name' ) do |dist|
- options[:dist] = dist
+ options[:dist] = dist
end
- options[:passwd] = ""
+ options[:passwd] = ""
opts.on( '-w', '--passwd <password>', 'password for managing project' ) do|passwd|
- options[:passwd] = passwd
- end
+ options[:passwd] = passwd
+ end
opts.on( '-t', '--ftp <ftp server url>', 'ftp server url: ftp://dibsftp:dibsftp@127.0.0.1:1024' ) do|domain|
- options[:fdomain] = domain
- end
-
+ options[:fdomain] = domain
+ end
+
opts.on( '-A', '--attr <attribute name>', 'attribute' ) do |attr|
- options[:attr] = attr
+ options[:attr] = attr
end
opts.on( '-V', '--value <value>', 'value' ) do |value|
- options[:value] = value
+ options[:value] = value
end
opts.on( '-h', '--help', 'display this information' ) do
- opts.help.split("\n").each {|op| puts op if not op.include? "--CHILD"}
+ opts.help.split("\n").each {|op| puts op if not op.include? "--CHILD"}
exit
- end
+ end
opts.on( '-v', '--version', 'display version' ) do
- puts "DIBS(Distributed Intelligent Build System) version " + Utils.get_version()
+ puts "DIBS(Distributed Intelligent Build System) version " + Utils.get_version()
exit
- end
+ end
opts.on( '-C', '--CHILD', 'child process' ) do
- options[:child] = true
- end
-
- end
-
+ options[:child] = true
+ end
+
+ end
+
cmd = ARGV[0]
- if cmd.eql? "create" or cmd.eql? "remove" or
+ if cmd.eql? "create" or cmd.eql? "remove" or
cmd.eql? "start" or cmd.eql? "upgrade" or
cmd.eql? "stop" or
cmd.eql? "add-svr" or cmd.eql? "remove-svr" or
cmd.eql? "add-dist" or cmd.eql? "remove-dist" or
cmd.eql? "add-sync" or cmd.eql? "remove-sync" or
cmd.eql? "add-prj" or cmd.eql? "remove-prj" or
- cmd.eql? "fullbuild" or cmd.eql? "register" or
- cmd.eql? "query" or
+ cmd.eql? "fullbuild" or cmd.eql? "register" or
+ cmd.eql? "query" or
cmd.eql? "set-attr" or cmd.eql? "get-attr" or
- cmd =~ /(-v)|(--version)/ or
- cmd =~ /(help)|(-h)|(--help)/ then
+ cmd =~ /(-v)|(--version)/ or
+ cmd =~ /(help)|(-h)|(--help)/ then
- if cmd.eql? "help" then
+ if cmd.eql? "help" then
ARGV[0] = "-h"
end
- options[:cmd] = ARGV[0]
- else
- raise ArgumentError, "Usage: build-svr <SUBCOMMAND> [OPTS] or build-svr -h"
- end
+ options[:cmd] = ARGV[0]
+ else
+ raise ArgumentError, "Usage: build-svr <SUBCOMMAND> [OPTS] or build-svr -h"
+ end
+
+ optparse.parse!
- optparse.parse!
+ option_error_check options
- option_error_check options
-
- return options
+ return options
end
@log = logger
end
-
+
# execute
public
def execute(sync=false)
# parent job will call sub job's terminate method
if not is_sub_job? then terminate() end
- rescue => e
- @log.error e.message
- @log.error e.backtrace.inspect
- end
+ rescue => e
+ @log.error e.message
+ @log.error e.backtrace.inspect
+ end
}
if sync then
@thread.join
end
-
+
return true
end
# do nothing
end
-
+
protected
def kill_sub_process()
if @sub_pid != 0 then
@log.info("Killing sub process! id = #{@sub_pid}")
end
Utils.kill_process(@sub_pid)
- end
- end
+ end
+ end
end
=begin
-
+
CommonProject.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
read_ext_info
end
-
+
def init()
# create project directory if not exist
if not File.exist? @path then FileUtils.mkdir_p @path end
=begin
-
+
DistributionManager.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
@name = name
@pkgsvr_url = pkgsvr_url
@pkgsvr_ip = pkgsvr_ip
- @pkgsvr_port = pkgsvr_port
+ @pkgsvr_port = pkgsvr_port
end
end
if @distributions.count > 0 then
return @distributions[0].name
end
-
+
return nil
end
-
+
def get_default_pkgsvr_url()
if @distributions.count > 0 then
return @distributions[0].pkgsvr_url
return d
end
}
-
+
return nil
end
dist_addr = dist.pkgsvr_ip + ":" + dist.pkgsvr_port.to_s
db.do "INSERT INTO distributions VALUES('#{dist.name}','#{dist.pkgsvr_url}','#{dist_addr}')"
}
- rescue DBI::DatabaseError => e
- puts "DB update failed!"
- puts e.errstr
- result = false
- ensure
- db.disconnect if db
- end
- return result
- end
-
+ rescue DBI::DatabaseError => e
+ puts "DB update failed!"
+ puts e.errstr
+ result = false
+ ensure
+ db.disconnect if db
+ end
+ return result
+ end
- # load
- def load_db()
- result = true
- @distributions = []
- sqlite_db_file = "DBI:SQLite3:#{BuildServer::CONFIG_ROOT}/#{@server.id}/server.db"
- begin
- # open DB
- db = DBI.connect(sqlite_db_file)
+ # load
+ def load_db()
+ result = true
+ @distributions = []
+
+ sqlite_db_file = "DBI:SQLite3:#{BuildServer::CONFIG_ROOT}/#{@server.id}/server.db"
+ begin
+ # open DB
+ db = DBI.connect(sqlite_db_file)
+
+ # distributions
+ rs = db.execute "SELECT * FROM distributions"
+ rs.fetch_hash { |row|
+ pkgsvr_ip = row['pkgsvr_addr'].split(":")[0]
+ pkgsvr_port = row['pkgsvr_addr'].split(":")[1].to_i
+ add_distribution_internal(row['name'], row['pkgsvr_url'], pkgsvr_ip, pkgsvr_port)
+ }
+ rs.finish
+ rescue DBI::DatabaseError => e
+ puts "DB loading failed!"
+ puts e.errstr
+ result = false
+ ensure
+ rs.finish if not rs.finished?
+ db.disconnect if db
+ end
+ return result
+ end
- # distributions
- rs = db.execute "SELECT * FROM distributions"
- rs.fetch_hash { |row|
- pkgsvr_ip = row['pkgsvr_addr'].split(":")[0]
- pkgsvr_port = row['pkgsvr_addr'].split(":")[1].to_i
- add_distribution_internal(row['name'], row['pkgsvr_url'], pkgsvr_ip, pkgsvr_port)
- }
- rs.finish
- rescue DBI::DatabaseError => e
- puts "DB loading failed!"
- puts e.errstr
- result = false
- ensure
- rs.finish if not rs.finished?
- db.disconnect if db
- end
- return result
- end
+ def add_distribution_internal(name, pkgsvr_url, pkgsvr_ip, pkgsvr_port)
+ @distributions.push PackageDistribution.new(name, pkgsvr_url, pkgsvr_ip, pkgsvr_port, @server)
+ end
- def add_distribution_internal(name, pkgsvr_url, pkgsvr_ip, pkgsvr_port)
- @distributions.push PackageDistribution.new(name, pkgsvr_url, pkgsvr_ip, pkgsvr_port, @server)
- end
+ def remove_distribution_internal(name)
+ @distributions.delete get_distribution(name)
+ end
- def remove_distribution_internal(name)
- @distributions.delete get_distribution(name)
- end
-
- def get_all_distributions()
- return @distributions
- end
+ def get_all_distributions()
+ return @distributions
+ end
- #END
-end
+ #END
+ end
=begin
-
+
GitBuildJob.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
@log.info( "Updating the source info for project \"#{@project.name}\"" , Log::LV_USER)
@project.add_source_info( @pkginfo.get_version(), @git_commit)
@project.copy_package_info( @pkginfo.get_version(),
- "#{@source_path}/package/pkginfo.manifest")
+ "#{@source_path}/package/pkginfo.manifest")
@project.set_log_cnt( @log.cnt )
@project.write_ext_info
# set up pkg info
begin
- @pkginfo = PackageManifest.new("#{@source_path}/package/pkginfo.manifest")
+ @pkginfo = PackageManifest.new("#{@source_path}/package/pkginfo.manifest")
rescue => e
@log.error( e.message, Log::LV_USER)
return false
#set up change log
change_log = {}
begin
- change_log = Parser.read_changelog "#{@source_path}/package/changelog" if File.exist? "#{@source_path}/package/changelog"
+ change_log = Parser.read_changelog "#{@source_path}/package/changelog" if File.exist? "#{@source_path}/package/changelog"
rescue => e
@log.error( e.message, Log::LV_USER)
return false
if not File.exist? cache_path then
FileUtils.mkdir_p cache_path
end
-
+
# check branch name
if File.exist? git_path then
current_branch = git_cmd_return( "branch", git_path).select{|x| x.start_with?("*")}[0].split(" ")[1].strip
protected
- def git_cmd(cmd, working_dir, log)
- build_command = "cd \"#{working_dir}\";#{@server.git_bin_path} #{cmd}"
+ def git_cmd(cmd, working_dir, log)
+ build_command = "cd \"#{working_dir}\";#{@server.git_bin_path} #{cmd}"
pid, status = execute_command( build_command )
if not status.nil? and status.exitstatus != 0 then
protected
- def git_cmd_return(cmd, working_dir)
- build_command = "cd \"#{working_dir}\";#{@server.git_bin_path} #{cmd}"
+ def git_cmd_return(cmd, working_dir)
+ build_command = "cd \"#{working_dir}\";#{@server.git_bin_path} #{cmd}"
ret = Utils.execute_shell_return(build_command)
-
+
return ret
end
end
=begin
-
+
GitProject.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
if not commit.nil? then
new_job.git_commit = commit
end
-
+
return new_job
end
# add package info
def add_package_info( version, path )
begin
- pkginfo =PackageManifest.new(path)
+ pkginfo =PackageManifest.new(path)
rescue => e
puts e.message
return
pkg_list.each do |pkg|
if pkg.package_name.eql? name then return true end
end
-
+
return false
end
return true
end
-
+
def load_db()
# git
config_file = "#{@path}/build"
end
end
end
-
+
# read pkginfo
pkginfo_dir = "#{@path}/pkginfos"
if not File.exist? pkginfo_dir then FileUtils.mkdir_p pkginfo_dir end
Dir.new(pkginfo_dir).entries.each do |file|
if file.eql? "." or file.eql? ".." then next end
-
+
vlen = file.length - ".manifest".length
version = file[0,vlen]
add_package_info( version, "#{pkginfo_dir}/#{file}" )
=begin
-
+
JobClean.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
$access_listfile = Mutex.new
class JobCleanAction < Action
-
+
def initialize( time, job_path, list_file, server )
super(time,0)
hour = l.split(",")[4]
min = l.split(",")[5]
sec = l.split(",")[6]
-
+
# create job and register
job_path = "#{jobs_path}/#{id}"
time = Time.mktime(year.to_i, month.to_i, day.to_i, hour.to_i, min.to_i, sec.to_i)
@handler.start
end
-
+
# clean after some time
def clean_afterwards(job_id)
time = Time.now + @server.keep_time
=begin
-
+
JobLog.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
=begin
-
+
JobManager.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
return new_idx
end
-
+
def create_new_register_job( file_path, dist_name )
return RegisterPackageJob.new( file_path, nil, @parent, nil, dist_name )
end
job.status = "WAITING"
end
@parent.log.info "Checking the job \"#{job.id}\" was finished!"
- rescue => e
- @parent.log.error e.message
- @parent.log.error e.backtrace.inspect
- end
+ rescue => e
+ @parent.log.error e.message
+ @parent.log.error e.backtrace.inspect
+ end
}
@parent.log.info "Job \"#{job.id}\" entered INITIALIZING status"
end
# call terminate process for job
job.terminate
- rescue => e
- @parent.log.error e.message
- @parent.log.error e.backtrace.inspect
- end
+ rescue => e
+ @parent.log.error e.message
+ @parent.log.error e.backtrace.inspect
+ end
}
end
if ( job.status == "WAITING" or job.status == "REMOTE_WORKING" or job.status == "PENDING") and
not job.is_asynchronous_job? and
not job.is_connected? then
-
+
job.status = "ERROR"
@jobs.delete( job )
@parent.log.info "Job \"#{job.id}\" is disconnected by user. Removed!"
end
parent_list.uniq!
-
+
return @max_working_jobs - working_cnt + parent_list.count
end
jobs.each do |job|
if job.cancel_state != "NONE" then next end
if job.status != "WAITING" then next end
-
+
# check build dependency against working job
pre_jobs = []
check_dep_jobs.each do |cjob|
if (cjob.status == "WORKING" or cjob.status == "REMOTE_WORKING" ) and
(job.has_build_dependency?( cjob ) or job.is_compatible_with?( cjob)) then
pre_jobs.push cjob
- # In case that "PENDING" job is depends on me (not depended )
+ # In case that "PENDING" job is depends on me (not depended )
elsif cjob.status == "PENDING" and (not job.does_depend_on? cjob) and
(job.has_build_dependency?( cjob ) or job.is_compatible_with?( cjob)) then
pre_jobs.push cjob
elsif check_dep_wait and cjob.status == "WAITING" and
(job.does_depend_on? cjob or
- (job.id > cjob.id and job.is_compatible_with? cjob) ) then
+ (job.id > cjob.id and job.is_compatible_with? cjob) ) then
pre_jobs.push cjob
end
end
@pkgsvr_ip = @server.distmgr.get_distribution(first_project.dist_name).pkgsvr_ip
@pkgsvr_port = @server.distmgr.get_distribution(first_project.dist_name).pkgsvr_port
@pkgsvr_client = Client.new(@pkgsvr_url, @job_working_dir, @log)
-
+
return true
end
#terminate
def terminate()
-
+
# report error
if @status == "ERROR" then
# register delayed clean action for sub jobs
@sub_jobs.each do |job|
- @server.cleaner.clean_afterwards(job.id)
+ @server.cleaner.clean_afterwards(job.id)
end
# register delayed clean action for me
@log.error( "Job is stopped by ERROR" , Log::LV_USER)
@server.cleaner.clean_afterwards(@id)
- elsif @status == "CANCELED" then
+ elsif @status == "CANCELED" then
# register delayed clean action for sub jobs
@sub_jobs.each do |job|
- @server.cleaner.clean_afterwards(job.id)
+ @server.cleaner.clean_afterwards(job.id)
end
# register delayed clean action for me
- @log.error( "Job is stopped by CANCEL" , Log::LV_USER)
- @server.cleaner.clean_afterwards(@id)
+ @log.error( "Job is stopped by CANCEL" , Log::LV_USER)
+ @server.cleaner.clean_afterwards(@id)
else
# terminate all sub jobs
def has_build_dependency?(other_job)
if has_same_packages?(other_job) or
- does_depend_on?(other_job) or
- does_depended_by?(other_job) then
+ does_depend_on?(other_job) or
+ does_depended_by?(other_job) then
return true
else
if get_distribution_name() != wjob.get_distribution_name() then
return false
end
-
+
# compare build dependency
get_build_dependencies(@os).each do |dep|
wjob.get_packages().each do |wpkg|
end
end
end
-
+
return false
end
@log.info( "Invoking a thread for MULTI-BUILD Job #{@id}", Log::LV_USER)
if @status == "ERROR" then return end
@log.info( "New Job #{@id} is started", Log::LV_USER)
-
+
# initialize status map
job_status_map = {}
@sub_jobs.each do |job|
job_status_map[job.id] = job.status
end
-
+
# add to internal job
@server.jobmgr.internal_job_schedule.synchronize {
@sub_jobs.each do |job|
# init finished, add internal_jobs
@server.jobmgr.add_internal_job(job)
@log.info( "Added new job \"#{job.get_project().name}\" for #{job.os}! (#{job.id})",
- Log::LV_USER)
- if not @server.job_log_url.empty? then
- @log.info( " * Log URL : #{@server.job_log_url}/#{job.id}/log", Log::LV_USER)
- end
+ Log::LV_USER)
+ if not @server.job_log_url.empty? then
+ @log.info( " * Log URL : #{@server.job_log_url}/#{job.id}/log", Log::LV_USER)
+ end
end
}
# show job status changes
all_jobs_finished = false
stop_status = "FINISHED"
- while not all_jobs_finished
+ while not all_jobs_finished
all_jobs_finished = true
@sub_jobs.each do |job|
# check status chanaged, if then print
# write url
write_log_url(job)
# cancel all other un-finished jobs
- @sub_jobs.each do |sub|
- if sub.status != "ERROR" and sub.status != "FINISHED" and
- sub.status != "CANCELED" and sub.cancel_state == "NONE" then
+ @sub_jobs.each do |sub|
+ if sub.status != "ERROR" and sub.status != "FINISHED" and
+ sub.status != "CANCELED" and sub.cancel_state == "NONE" then
@log.info(" * Sub-Job \"#{sub.get_project().name}(#{sub.os})\" has entered \"CANCELING\" state. (#{sub.id})", Log::LV_USER)
- sub.cancel_state = "INIT"
+ sub.cancel_state = "INIT"
end
end
private
def upload()
@log.info( "Uploading ...", Log::LV_USER)
-
+
# get package path list
binpkg_path_list = Dir.glob("#{@source_path}/*_*_*.zip")
return false
end
-
+
# update local
@log.info( "Upload succeeded. Sync local pkg-server again...", Log::LV_USER)
@pkgsvr_client.update
@log.info("Snapshot: #{snapshot}", Log::LV_USER)
-
+
return true
end
=begin
-
+
PackageSync.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
class PackageSyncAction < Action
@@new_id = 0
-
+
def initialize( time, url, dist_name, server )
super(time, server.pkg_sync_period)
my_id = @@new_id
def execute
@server.log.info "Executing package-sync action for server \"#{@pkgsvr_url}\""
-
+
begin
execute_internal()
rescue => e
# wait for finish all jobs
all_jobs_finished = false
- while not all_jobs_finished
+ while not all_jobs_finished
unfinished_jobs = registered_jobs.select { |j|
(j.status != "ERROR" and j.status != "FINISHED" and j.status != "CANCELED")
}
sleep 10
end
end
-
+
# remove files
downloaded_files.each { |file_path|
@server.log.info "Removed downloaded file: \"#{file_path}\""
if main_ver.nil? then next end
remote_ver = @pkgsvr_client.get_attr_from_pkg(pkg_name, os, "version")
if remote_ver.nil? then next end
-
+
if Version.new(main_ver) < Version.new(remote_ver) then
pkgs.push [pkg_name, os]
end
=begin
-
+
ProjectManager.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
@projects.each do |prj|
if prj.name == name and prj.dist_name == dist_name then return prj end
end
-
+
return nil
end
prj = get_project(name, dist_name)
if not prj.nil? then return false end
-
+
new_prj = GitBuildProject.new(name, @server, os_list, dist_name, repos, branch)
if not passwd.nil? and not passwd.empty? then
new_prj.passwd = passwd
prj = get_project(name, dist_name)
if not prj.nil? then return false end
-
+
new_prj = BinaryUploadProject.new(name, @server, os_list, dist_name, pkg_name)
if not passwd.nil? and not passwd.empty? then
new_prj.passwd = passwd
@projects.each do |prj|
if prj.type != "GIT" then next end
if prj.dist_name != dist_name then next end
-
+
prj.os_list.each do |os|
if not @server.supported_os_list.include? os then next end
-
+
new_job = create_new_job( prj.name, os, dist_name )
if new_job.nil? then next end
# This make project to build
# even though there is a package of same version on pkg-server
new_job.set_force_rebuild(true)
-
+
# add to multi job
result.add_sub_job( new_job )
end
return prj
end
}
-
+
return nil
end
if not prj.save_db() then raise RuntimeError ,"Save project DB is failed!" end
}
- rescue DBI::DatabaseError => e
- puts "DB update failed!"
- puts e.errstr
- result = false
- ensure
- db.disconnect if db
- end
- return result
- end
-
-
- # load
- def load_db()
- result = true
- @projects = []
-
- sqlite_db_file = "DBI:SQLite3:#{BuildServer::CONFIG_ROOT}/#{@server.id}/server.db"
- begin
- # open DB
- db = DBI.connect(sqlite_db_file)
-
- # distributions
- rs = db.execute "SELECT * FROM projects"
- rs.fetch_hash { |row|
- prj_id = row['id']
- prj_name = row['name']
- prj_type = row['type']
- prj_passwd = row['password']
- prj_dist = row['dist_name']
-
- @server.log.info "Loading project : #{prj_name}"
- # os
- prj_os_list = []
- rs2 = db.execute "SELECT os_name FROM project_os WHERE prj_id = #{prj_id}"
- rs2.fetch { |row2|
- prj_os_list.push row2[0]
- }
- rs2.finish
- if prj_type == "GIT" then
- new_project = GitBuildProject.new(prj_name, @server, prj_os_list, prj_dist)
- else
- new_project = BinaryUploadProject.new(prj_name, @server, prj_os_list, prj_dist)
+ rescue DBI::DatabaseError => e
+ puts "DB update failed!"
+ puts e.errstr
+ result = false
+ ensure
+ db.disconnect if db
+ end
+ return result
end
- if not prj_passwd.empty? then
- new_project.passwd = prj_passwd
+
+ # load
+ def load_db()
+ result = true
+ @projects = []
+
+ sqlite_db_file = "DBI:SQLite3:#{BuildServer::CONFIG_ROOT}/#{@server.id}/server.db"
+ begin
+ # open DB
+ db = DBI.connect(sqlite_db_file)
+
+ # distributions
+ rs = db.execute "SELECT * FROM projects"
+ rs.fetch_hash { |row|
+ prj_id = row['id']
+ prj_name = row['name']
+ prj_type = row['type']
+ prj_passwd = row['password']
+ prj_dist = row['dist_name']
+
+ @server.log.info "Loading project : #{prj_name}"
+ # os
+ prj_os_list = []
+ rs2 = db.execute "SELECT os_name FROM project_os WHERE prj_id = #{prj_id}"
+ rs2.fetch { |row2|
+ prj_os_list.push row2[0]
+ }
+ rs2.finish
+ if prj_type == "GIT" then
+ new_project = GitBuildProject.new(prj_name, @server, prj_os_list, prj_dist)
+ else
+ new_project = BinaryUploadProject.new(prj_name, @server, prj_os_list, prj_dist)
+ end
+
+ if not prj_passwd.empty? then
+ new_project.passwd = prj_passwd
+ end
+
+ if not new_project.load_db() then raise RuntimeError, "Project DB load failed!" end
+ @projects.push new_project
+ }
+ rs.finish
+ rescue DBI::DatabaseError => e
+ puts "DB loading failed!"
+ puts e.errstr
+ result = false
+ ensure
+ rs.finish if not rs.finished?
+ db.disconnect if db
+ end
+ return result
end
- if not new_project.load_db() then raise RuntimeError, "Project DB load failed!" end
- @projects.push new_project
- }
- rs.finish
- rescue DBI::DatabaseError => e
- puts "DB loading failed!"
- puts e.errstr
- result = false
- ensure
- rs.finish if not rs.finished?
- db.disconnect if db
- end
- return result
- end
+ # write configuration
+ def write_configuration(name, repos, branch, passwd, os_list )
+ config_file = "#{@project_root}/#{name}/build"
+ File.open( config_file, "w" ) do |f|
+ f.puts "TYPE=GIT"
+ if not passwd.nil? and not passwd.empty? then
+ f.puts "PASSWD=#{passwd}"
+ end
+ f.puts "GIT_REPOSITORY=#{repos}"
+ f.puts "GIT_BRANCH=#{branch}"
+ f.puts "OS_LIST=#{os_list.join(",")}"
+ end
+ end
- # write configuration
- def write_configuration(name, repos, branch, passwd, os_list )
- config_file = "#{@project_root}/#{name}/build"
- File.open( config_file, "w" ) do |f|
- f.puts "TYPE=GIT"
- if not passwd.nil? and not passwd.empty? then
- f.puts "PASSWD=#{passwd}"
- end
- f.puts "GIT_REPOSITORY=#{repos}"
- f.puts "GIT_BRANCH=#{branch}"
- f.puts "OS_LIST=#{os_list.join(",")}"
- end
- end
+ # write configuration
+ def write_configuration_for_binary_project(name, pkg_name, passwd, os_list )
+ config_file = "#{@project_root}/#{name}/build"
+ File.open( config_file, "w" ) do |f|
+ f.puts "TYPE=BINARY"
+ if not passwd.nil? and not passwd.empty? then
+ f.puts "PASSWD=#{passwd}"
+ end
+ f.puts "PACKAGE_NAME=#{pkg_name}"
+ f.puts "OS_LIST=#{os_list.join(",")}"
+ end
+ end
- # write configuration
- def write_configuration_for_binary_project(name, pkg_name, passwd, os_list )
- config_file = "#{@project_root}/#{name}/build"
- File.open( config_file, "w" ) do |f|
- f.puts "TYPE=BINARY"
- if not passwd.nil? and not passwd.empty? then
- f.puts "PASSWD=#{passwd}"
end
- f.puts "PACKAGE_NAME=#{pkg_name}"
- f.puts "OS_LIST=#{os_list.join(",")}"
- end
- end
-
-end
attr_accessor :source_path
attr_accessor :pkgsvr_client, :thread, :pkg_type
attr_accessor :pkg_name, :pkginfo, :cancel_state
-
+
# initialize
def initialize( local_path, project, server, ftpurl=nil, dist_name=nil )
@local_path=local_path
@file_path = nil
@filename = File.basename(local_path)
- if @filename =~ /.*_.*_.*\.zip/ then
+ if @filename =~ /.*_.*_.*\.zip/ then
@pkg_type = "BINARY"
new_name = @filename.sub(/(.*)_(.*)_(.*)\.zip/,'\1,\2,\3')
@pkg_name = new_name.split(",")[0]
def has_build_dependency?(other_job)
if has_same_packages?(other_job) or
- does_depended_by?(other_job) then
+ does_depended_by?(other_job) then
return true
else
# if this package has compatible OS, check
if @pkg_type == "BINARY" and
@pkginfo.packages[0].os_list.count > 1 then
-
+
pkg = @pkginfo.packages[0]
pkg.os_list.each do |os|
if @os == os then next end
else
rev_pkgs += @pkgsvr_client.get_reverse_source_dependent_packages(@pkg_name)
end
-
+
rev_projects = @server.prjmgr.get_projects_from_pkgs(rev_pkgs)
# create reverse build job
def upload()
@log.info( "Uploading ...", Log::LV_USER)
-
+
# get package path list
if @pkg_type == "ARCHIVE" then
binpkg_path_list = Dir.glob("#{@source_path}/#{@pkg_name}")
return false
end
-
+
# update local
@log.info( "Upload succeeded. Sync local pkg-server again...", Log::LV_USER)
@pkgsvr_client.update
@log.info("Snapshot: #{snapshot}", Log::LV_USER)
-
+
return true
end
@pkginfo.packages.each do |pkg|
ver_local = pkg.version
#ver_svr = @pkgsvr_client.get_package_version( pkg.package_name, @os )
- ver_svr = @pkgsvr_client.get_attr_from_pkg( pkg.package_name, @os, "version")
+ ver_svr = @pkgsvr_client.get_attr_from_pkg( pkg.package_name, @os, "version")
if not ver_svr.nil? and Version.new(ver_local) <= Version.new(ver_svr) then
@log.error( "Version must be increased : #{ver_local} <= #{ver_svr}", Log::LV_USER)
return false
=begin
-
+
RemoteBuildServer.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
if client.send("QUERY|JOB") then
result = client.read_lines do |l|
tok = l.split(",").map { |x| x.strip }
-
+
job_status = tok[0]
job_id = tok[1]
new_job = RemoteBuildJob.new(job_id,self)
# build
ret = build(@job.get_project().repository, @job.source_path, @job.os,
- @job.is_rev_build_check_job(), @job.git_commit, @job.no_reverse,
- local_pkgs, @job.get_project().dist_name )
+ @job.is_rev_build_check_job(), @job.git_commit, @job.no_reverse,
+ local_pkgs, @job.get_project().dist_name )
# reset job
@job = nil
return ret
end
-
+
# build
def build( git_repos, source_path, os, is_rev_build, srcinfo, no_reverse, local_pkgs, dist_name )
@log.info( "Start to build on remote server...", Log::LV_USER )
begin
@server.add_file_transfer()
local_pkgs.each do |pkg_path|
- @log.info( "Sending file... : #{pkg_path}", Log::LV_USER )
+ @log.info( "Sending file... : #{pkg_path}", Log::LV_USER )
result = send_file_to_remote( pkg_path, dock )
if not result then
- @log.error( "File transfering failed!", Log::LV_USER )
+ @log.error( "File transfering failed!", Log::LV_USER )
@server.remove_file_transfer()
return false
end
# send build request
@log.info( "Sending build request to remote server...", Log::LV_USER )
result, result_files = send_build_request(git_repos, os,
- is_rev_build, srcinfo, no_reverse, local_pkgs, dock, dist_name)
+ is_rev_build, srcinfo, no_reverse, local_pkgs, dock, dist_name)
- @log.info( "Receiving log file from remote server...", Log::LV_USER )
+ @log.info( "Receiving log file from remote server...", Log::LV_USER )
if not receive_file_from_remote( "#{source_path}/../remote_log", dock ) then
- @log.warn( "File transfering failed! : remote_log", Log::LV_USER )
+ @log.warn( "File transfering failed! : remote_log", Log::LV_USER )
end
if not result then
- @log.error( "Building job on remote server failed!", Log::LV_USER )
+ @log.error( "Building job on remote server failed!", Log::LV_USER )
return false
end
# receive binary package
result_files.each do |file_name|
- @log.info( "Receiving file from remote server : #{file_name}", Log::LV_USER )
+ @log.info( "Receiving file from remote server : #{file_name}", Log::LV_USER )
result = receive_file_from_remote( "#{source_path}/#{file_name}", dock )
if not result then
- @log.error( "File transfering failed! : #{file_name}", Log::LV_USER )
+ @log.error( "File transfering failed! : #{file_name}", Log::LV_USER )
return false
end
end
protected
def send_file_to_remote(file_path, dock = "0")
# create client
- client = BuildCommClient.create( @addr, @port, @log )
- if client.nil? then
+ client = BuildCommClient.create( @addr, @port, @log )
+ if client.nil? then
@log.error( "Creating communication client failed!", Log::LV_USER)
- return false
- end
+ return false
+ end
# upload file
result = true
#close connections
client.terminate
-
+
return result
end
def send_build_request(git_repos, os, is_rev_build, commit, no_reverse, local_pkgs, dock = "0", dist_name="BASE")
result_files = []
- client = BuildCommClient.create( @addr, @port, @log )
- if client.nil? then
+ client = BuildCommClient.create( @addr, @port, @log )
+ if client.nil? then
@log.error( "Creating communication client failed!", Log::LV_USER)
- return false, result_files
- end
-
+ return false, result_files
+ end
+
# get local package names
local_pkg_names = local_pkgs.map { |path| File.basename(path) }
- # send
+ # send
# format: BUILD|GIT|repository|passwd|os|async|no_reverse|internal|rev-build|commit|pkgs|dock_num|dist_name
# value : BUILD|GIT|repository| |os|NO |no_reverse|YES |rev-build|commit|pkgs|dock_num|dist_name
result = true
rev = is_rev_build ? "YES":"NO"
msg = "BUILD|GIT|#{git_repos}||#{os}|NO|#{no_reverse}|YES|#{rev}|#{commit}|#{pkg_list}|#{dock}|#{dist_name}"
r_job_number = Regexp.new('Added new job "([^"]*)"')
- if client.send( msg ) then
- result = client.read_lines do |l|
- # write log first
- @log.output( l.strip, Log::LV_USER)
+ if client.send( msg ) then
+ result = client.read_lines do |l|
+ # write log first
+ @log.output( l.strip, Log::LV_USER)
# set remote job id
if @remote_id.nil? and l =~ r_job_number then
@remote_id = $1
end
-
+
# check build result
- if l.include? "Job is stopped by ERROR" or
+ if l.include? "Job is stopped by ERROR" or
l.include? "Error:" then
- result = false
+ result = false
break
- end
+ end
# gather result files if not reverse build
if not is_rev_build and l =~ /Creating package file \.\.\. (.*)/ then
result_files.push file_name
end
- end
- end
-
- # close socket
- client.terminate
-
+ end
+ end
+
+ # close socket
+ client.terminate
+
return result, result_files
end
protected
def receive_file_from_remote(file_path, dock = "0")
# create client
- client = BuildCommClient.create( @addr, @port, @log )
- if client.nil? then
+ client = BuildCommClient.create( @addr, @port, @log )
+ if client.nil? then
@log.error( "Creating communication client failed!", Log::LV_USER)
- return false
- end
+ return false
+ end
# download file
result = true
file_name = file_path.split("/")[-1]
msg = "DOWNLOAD|#{dock}|#{file_name}"
- if client.send( msg ) then
- if not @ftp_addr.nil? then
- transporter=FileTransferFTP.new(@log, @ftp_addr, @ftp_port, @ftp_username, @ftp_passwd)
- else
- transporter=FileTransferDirect.new(@log)
- end
- result=client.receive_file(file_path, transporter)
- if not result then
- @log.error( "File downloading failed...#{file_name}", Log::LV_USER)
- end
+ if client.send( msg ) then
+ if not @ftp_addr.nil? then
+ transporter=FileTransferFTP.new(@log, @ftp_addr, @ftp_port, @ftp_username, @ftp_passwd)
+ else
+ transporter=FileTransferDirect.new(@log)
+ end
+ result=client.receive_file(file_path, transporter)
+ if not result then
+ @log.error( "File downloading failed...#{file_name}", Log::LV_USER)
+ end
end
#close connections
client.terminate
-
+
return result
end
end
=begin
-
+
ReverseBuildChecker.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
job.pending_ancestor.rev_fail_projects.each { |fp|
f_prj = fp[0]
f_os = fp[1]
-
+
if rev_prj == f_prj and rev_os == f_os then
found = true
break
# add to job manager
job.server.jobmgr.add_reverse_build_job(rev_job)
log.info( " * Added new job for reverse-build ... \
- #{rev_job.get_project().name}(#{rev_job.os}) (#{rev_job.id})", Log::LV_USER)
+ #{rev_job.get_project().name}(#{rev_job.os}) (#{rev_job.id})", Log::LV_USER)
end
# wait for job finish
=begin
-
+
SocketJobRequestListener.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
@log.error e.message
@log.error e.backtrace.inspect
end
- end
+ end
}
end
def stop_listening()
@finish_loop = true
end
-
+
private
# thread main
begin
if not @parent_server.ftp_addr.nil? then
ftp_url = Utils.generate_ftp_url(@parent_server.ftp_addr, @parent_server.ftp_port,
- @parent_server.ftp_username, @parent_server.ftp_passwd)
+ @parent_server.ftp_username, @parent_server.ftp_passwd)
else
ftp_url = nil
end
@log.info "Entering Control Listening Loop ... "
@finish_loop = false
@comm_server.wait_for_connection(@finish_loop) do |req|
- handle_job_request( req )
+ handle_job_request( req )
end
# quit
def wait_for_job_requests
req_list = []
req_list.push @tcp_server.accept
-
+
return req_list
end
if req_line.split("|").count > 0 then
cmd = req_line.split("|")[0].strip
end
-
+
case cmd
when "BUILD"
@log.info "Received REQ: #{req_line}"
handle_cmd_register( req_line, req )
@log.info "Handled REQ: #{req_line}"
when "DOWNLOAD"
- Thread.new {
+ Thread.new {
begin
- handle_cmd_download( req_line, req )
- rescue => e
- @log.error "Transfering file failed!"
- @log.error e.message
- @log.error e.backtrace.inspect
- end
- }
+ handle_cmd_download( req_line, req )
+ rescue => e
+ @log.error "Transfering file failed!"
+ @log.error e.message
+ @log.error e.backtrace.inspect
+ end
+ }
when "UPLOAD"
- Thread.new {
+ Thread.new {
begin
- handle_cmd_upload( req_line, req )
- rescue => e
- @log.error "Transfering file failed!"
- @log.error e.message
- @log.error e.backtrace.inspect
- end
- }
+ handle_cmd_upload( req_line, req )
+ rescue => e
+ @log.error "Transfering file failed!"
+ @log.error e.message
+ @log.error e.backtrace.inspect
+ end
+ }
else
@log.info "Received Unknown REQ: #{req_line}"
raise "Unknown request: #{req_line}"
raise "Multi-Build Job creation failed!"
end
- # transfered job
+ # transfered job
elsif is_internal then
git_repos = project_name_list[0]
os = os_list[0]
new_job = create_new_internal_job(git_repos, os, git_commit, pkg_files, dock_num, dist_name )
if rev_job then new_job.set_rev_build_check_job(nil) end
- # single job
+ # single job
elsif project_name_list.count == 1 and os_list.count == 1 then
pname = project_name_list[0]
os = os_list[0]
logger = JobLog.new( new_job, req )
if not async then new_job.set_logger(logger) end
logger.init
-
+
# notify that job has been received
logger.info( "Added new job \"#{new_job.id}\" for #{new_job.os}!", Log::LV_USER)
if not @parent_server.job_log_url.empty? then
raise "Project's password is not matched!!"
end
- # check project type
- if prj.type == "BINARY" then
- BuildCommServer.send_begin(req)
- req.puts "Can't build about Binary type package."
- BuildCommServer.send_end(req)
- raise "Can't build about Binary type package."
- end
+ # check project type
+ if prj.type == "BINARY" then
+ BuildCommServer.send_begin(req)
+ req.puts "Can't build about Binary type package."
+ BuildCommServer.send_end(req)
+ raise "Can't build about Binary type package."
+ end
end
end
case tok[1]
- # RESOLVE|GIT|repos|commit|os|async
+ # RESOLVE|GIT|repos|commit|os|async
when "GIT"
# parse
project_name=tok[2]
if prj.nil? then
raise "Requested project does not exist!"
end
-
+
# check passwd
if not check_project_password(prj, passwd, req) then
raise "Project's password is not matched!!"
raise "Unsupported OS name is used!"
end
os = os_list[0]
-
+
# create new job
new_job = create_new_job( project_name, os, dist_name )
if new_job.nil? then
logger = JobLog.new( new_job, req )
if not async then new_job.set_logger(logger) end
logger.init
-
+
# notify that job has been received
logger.info( "Added new job \"#{new_job.id}\" for #{new_job.os}!", Log::LV_USER)
if not @parent_server.job_log_url.empty? then
@log.info "Received Wrong REQ: #{line}"
raise "Invalid request format is used: #{line}"
end
-
+
case tok[1]
- # QUERY, FTP
+ # QUERY, FTP
when "FTP"
BuildCommServer.send_begin(req)
if not @parent_server.ftp_addr.nil? then
BuildCommServer.send_end(req)
BuildCommServer.disconnect(req)
- # QUERY,JOB
+ # QUERY,JOB
when "JOB"
#puts "Received QUERY JOB"
BuildCommServer.send_end(req)
BuildCommServer.disconnect(req)
- # QUERY,SYSTEM
+ # QUERY,SYSTEM
when "SYSTEM"
#puts "Received QUERY SYSTEM"
raise "There is no job \"#{tok[1]}\""
else
if cancel_job.cancel_state == "NONE" then
- # check passwd
- if cancel_job.type == "MULTIBUILD" then
- cancel_job.get_sub_jobs().select{|x| x.cancel_state == "NONE" }.each do |sub|
- if not check_project_password( sub.get_project, tok[2], req) then
- BuildCommServer.send(req, "Project's password is not matched!!")
- raise "Project's password is not matched!!"
+ # check passwd
+ if cancel_job.type == "MULTIBUILD" then
+ cancel_job.get_sub_jobs().select{|x| x.cancel_state == "NONE" }.each do |sub|
+ if not check_project_password( sub.get_project, tok[2], req) then
+ BuildCommServer.send(req, "Project's password is not matched!!")
+ raise "Project's password is not matched!!"
+ end
end
- end
- BuildCommServer.send(req, "\"#{cancel_job.id}, #{cancel_job.get_sub_jobs().map{|x| x.id}.join(", ")}\" will be canceled")
- cancel_job.cancel_state = "INIT"
- else
- if not check_project_password( cancel_job.get_project, tok[2], req) then
- BuildCommServer.send(req, "Project's password is not matched!!")
- raise "Project's password is not matched!!"
- else
- BuildCommServer.send(req, "\"#{cancel_job.id}\" will be canceled")
+ BuildCommServer.send(req, "\"#{cancel_job.id}, #{cancel_job.get_sub_jobs().map{|x| x.id}.join(", ")}\" will be canceled")
cancel_job.cancel_state = "INIT"
+ else
+ if not check_project_password( cancel_job.get_project, tok[2], req) then
+ BuildCommServer.send(req, "Project's password is not matched!!")
+ raise "Project's password is not matched!!"
+ else
+ BuildCommServer.send(req, "\"#{cancel_job.id}\" will be canceled")
+ cancel_job.cancel_state = "INIT"
+ end
end
- end
else
BuildCommServer.send(req, "\"#{cancel_job.id}\" is already canceled")
end
@log.info "Received Wrong REQ: #{line}"
raise "Invalid request format is used: #{line}"
end
-
+
BuildCommServer.send_begin(req)
if tok[1] != @parent_server.password then
BuildCommServer.send(req,"Password mismatched!")
@log.info "Received Wrong REQ: #{line}"
raise "Invalid request format is used: #{line}"
end
-
+
BuildCommServer.send_begin(req)
if tok[1] != @parent_server.password then
BuildCommServer.send(req,"Password mismatched!")
@log.info "Received Wrong REQ: #{line}"
raise "Invalid request format is used: #{line}"
end
-
+
server_passwd = tok[1]
dist_name = tok[2]
if (dist_name.nil? or dist_name.empty?) then
type = tok[1]
case type
- # REGISTER|BINARY-LOCAL|local_path|passwd|dist_name
- # REGISTER|SOURCE-LOCAL|local_path|passwd|dist_name
+ # REGISTER|BINARY-LOCAL|local_path|passwd|dist_name
+ # REGISTER|SOURCE-LOCAL|local_path|passwd|dist_name
when "BINARY-LOCAL", "SOURCE-LOCAL"
file_path = tok[2]
dist_name = tok[4]
# add
@parent_server.jobmgr.add_job( new_job )
- # REGISTER|BINARY|filename|passwd|dock|dist_name
+ # REGISTER|BINARY|filename|passwd|dock|dist_name
when "BINARY"
# parse
filename = tok[2]
passwd = tok[3]
dock = (tok[4].nil? or tok[4].empty?) ? "0" : tok[4].strip
- dist_name = tok[5]
+ dist_name = tok[5]
if (dist_name.nil? or dist_name.empty?) then
dist_name = @parent_server.distmgr.get_default_distribution_name()
end
if prj.nil? then
raise "No project is defined for this binary : #{filename}!"
end
-
+
# check passwd
if not check_project_password(prj, passwd, req) then
raise "Project's password is not matched!!"
end
-
+
# create new job
@log.info "Received a request for uploading binaries : #{filename}"
new_job = create_new_upload_job( prj.name, filename, dock, dist_name, req )
logger = JobLog.new( new_job, req )
new_job.set_logger(logger)
logger.init
-
+
# notify that job has been received
logger.info( "Added new job \"#{new_job.id}\" for #{new_job.os}!", Log::LV_USER)
if not @parent_server.job_log_url.empty? then
@log.info "Received Wrong REQ: #{line}"
raise "Invalid request format is used: #{line}"
end
-
+
end
dock_num = tok[1].strip
file_name = tok[2]
-
+
@log.info "Received a request for download file : #{file_name}"
outgoing_dir = "#{@parent_server.transport_path}/#{dock_num}"
BuildCommServer.send_begin(req)
private
def check_project_for_package_file_name(filename, dist_name, req)
# get package name
- new_name = filename.sub(/(.*)_(.*)_(.*)\.zip/,'\1,\2,\3')
- pkg_name = new_name.split(",")[0]
+ new_name = filename.sub(/(.*)_(.*)_(.*)\.zip/,'\1,\2,\3')
+ pkg_name = new_name.split(",")[0]
prj = @parent_server.prjmgr.get_project_from_package_name(pkg_name, dist_name)
if prj.nil? then
end
end
-
+
# create
def self.create (id, pkgserver_url, log_path, buildroot_dir, cache_dir)
if not pkginfo.package_exist?(os, build_host_os ) then
if is_local_build and File.exist? "#{src_path}/package/pkginfo.manifest.local" then
begin
- pkginfo = PackageManifest.new("#{src_path}/package/pkginfo.manifest.local")
+ pkginfo = PackageManifest.new("#{src_path}/package/pkginfo.manifest.local")
rescue => e
@log.error( e.message, Log::LV_USER)
return false
end
@log.info( " * #{dep.package_name}", Log::LV_USER)
- # get local dependent package
- pkgexp = Regexp.new("\/#{dep.package_name}_.*_#{dep_target_os}\.zip$")
- local_dep_pkgs = local_pkgs.select{|l| l =~ pkgexp}
+ # get local dependent package
+ pkgexp = Regexp.new("\/#{dep.package_name}_.*_#{dep_target_os}\.zip$")
+ local_dep_pkgs = local_pkgs.select{|l| l =~ pkgexp}
# install package from remote package server
if local_dep_pkgs.empty? then
- if not cl.install(dep.package_name, dep_target_os, true, false) then
+ if not cl.install(dep.package_name, dep_target_os, true, false) then
@log.error( "Installing \"#{dep.package_name}\" failed!", Log::LV_USER)
return false
end
if not File.exist? l then
@log.error( "File not found!: #{l}", Log::LV_USER )
end
- cl.install_local_pkg(l,true,false, repos_paths)
+ cl.install_local_pkg(l,true,false, repos_paths)
end
end
end
@log.info( "Downloading dependent source packages...", Log::LV_USER)
src_archive_list = []
- pkginfo.get_source_dependencies(os,build_host_os).each do |dep|
+ pkginfo.get_source_dependencies(os,build_host_os).each do |dep|
src_archive_list.push dep.package_name
- end
+ end
src_archive_list.uniq!
src_archive_list.each do |archive_name|
- @log.info( " * #{archive_name}", Log::LV_USER)
- if cl.download_dep_source(archive_name).nil? then
- @log.error( "Downloading \"#{archive_name}\" failed!", Log::LV_USER)
- return false
- end
+ @log.info( " * #{archive_name}", Log::LV_USER)
+ if cl.download_dep_source(archive_name).nil? then
+ @log.error( "Downloading \"#{archive_name}\" failed!", Log::LV_USER)
+ return false
+ end
end
# make clean
# read configuration
builder_dir = "#{CONFIG_ROOT}/#{id}"
- log_path = nil
+ log_path = nil
cache_dir = "#{CONFIG_ROOT}/#{id}/build_cache"
buildroot_dir = "#{CONFIG_ROOT}/#{id}/buildroot"
File.open( "#{builder_dir}/builder.cfg", "r" ) do |f|
f.each_line do |l|
if l.start_with?("PSERVER_URL=")
- pkgserver_url = l.split("=")[1].strip
- elsif l.start_with?("LOG-PATH=")
- log_path = l.split("=")[1].strip
- log_path = nil if log_path == "STDOUT"
- elsif l.start_with?("CACHE-DIR=")
- cache_dir = l.split("=")[1].strip
- elsif l.start_with?("BUILDROOT-DIR=")
- buildroot_dir = l.split("=")[1].strip
+ pkgserver_url = l.split("=")[1].strip
+ elsif l.start_with?("LOG-PATH=")
+ log_path = l.split("=")[1].strip
+ log_path = nil if log_path == "STDOUT"
+ elsif l.start_with?("CACHE-DIR=")
+ cache_dir = l.split("=")[1].strip
+ elsif l.start_with?("BUILDROOT-DIR=")
+ buildroot_dir = l.split("=")[1].strip
else
next
end
end
end
- if log_path.empty? then log_path = nil end
+ if log_path.empty? then log_path = nil end
# create object & return it
return new( id, pkgserver_url, log_path, buildroot_dir, cache_dir )
f.puts "echo \"success\""
end
Utils.execute_shell( "chmod +x #{src_path}/.build.sh" )
- build_command = "cd \"#{src_path}\";" + env_def + "./.build.sh"
+ build_command = "cd \"#{src_path}\";" + env_def + "./.build.sh"
# execute script
status = nil
install_dir = "#{src_path}/package/#{pkg.package_name}.package.#{os}"
if not File.exist? install_dir then
install_dir = "#{src_path}/package/#{pkg.package_name}.package.#{os_category}"
-
+
if not File.exist? install_dir then
@log.error( "Following directory must be created before writing pkginfo.manifest", Log::LV_USER)
@log.error( " * package/#{pkg.package_name}.package.#{os}", Log::LV_USER)
return false
end
end
-
+
# zip
@log.info( "Creating package file ... #{pkg.package_name}_#{pkg.version}_#{os}.zip", Log::LV_USER)
cmd = "cd \"#{install_dir}\"; zip -r -y #{src_path}/#{pkg.package_name}_#{pkg.version}_#{os}.zip *"
# create pkginfo
begin
- pkginfo = PackageManifest.new("#{src_path}/package/pkginfo.manifest")
+ pkginfo = PackageManifest.new("#{src_path}/package/pkginfo.manifest")
rescue => e
@log.error( e.message, Log::LV_USER)
return false
# clean local-only package's directory
if File.exist? "#{src_path}/package/pkginfo.manifest.local" then
begin
- pkginfo = PackageManifest.new("#{src_path}/package/pkginfo.manifest.local")
+ pkginfo = PackageManifest.new("#{src_path}/package/pkginfo.manifest.local")
rescue => e
@log.error( e.message, Log::LV_USER)
return false
=begin
-
+
CleanOptionParser.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
def parse()
- #option parsing
- option = {}
- optparse = OptionParser.new(nil, 32, ' '*8) do |opts|
- opts.banner = "Clean the package service command-line tool." + "\n" \
- + "\n" + "Usage: pkg-clean [-h] [-v]" + "\n" \
- + "\n" + "Options:" + "\n"
-
- opts.on('-h','--help', 'display help') do
- puts opts
- exit
- end
-
- opts.on('-v','--version', 'display version') do
- puts "DIBS(Distributed Intelligent Build System) version " + Utils.get_version()
- exit
- end
- end
-
- optparse.parse!
-
- return option
+ #option parsing
+ option = {}
+ optparse = OptionParser.new(nil, 32, ' '*8) do |opts|
+ opts.banner = "Clean the package service command-line tool." + "\n" \
+ + "\n" + "Usage: pkg-clean [-h] [-v]" + "\n" \
+ + "\n" + "Options:" + "\n"
+
+ opts.on('-h','--help', 'display help') do
+ puts opts
+ exit
+ end
+
+ opts.on('-v','--version', 'display version') do
+ puts "DIBS(Distributed Intelligent Build System) version " + Utils.get_version()
+ exit
+ end
+ end
+
+ optparse.parse!
+
+ return option
end
=begin
-
+
optionparser.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
def parse()
- #option parsing
- option = {}
- optparse = OptionParser.new do |opts|
- opts.banner = "Build and packaging service command-line tool." + "\n" \
- + "\n" + "Usage: pkg-build -u <package server url> [-o <os>] [-c] [-h] [-v]" + "\n" \
- + "\n" + "Options:" + "\n"
-
- opts.on('-u','--url <package server url>', 'remote package server url: http://127.0.0.1/dibs/unstable') do |url|
- option[:url] = url
- end
-
- option[:os] = nil
- opts.on('-o','--os <os>', 'operating system ') do |os|
- option[:os] = os
- end
-
- option[:clean] = false
- opts.on('-c','--clean', 'clean build') do
- option[:clean] = true
- end
-
- option[:rev] = false
- #opts.on('-r','--rev', 'reverse build dependency check') do
- # option[:rev] = true
- #end
-
- opts.on('-h','--help', 'display help') do
- puts opts
- exit
- end
-
- opts.on('-v','--version', 'display version') do
- puts "DIBS(Distributed Intelligent Build System) version " + Utils.get_version()
- exit
- end
- end
-
- optparse.parse!
-
- if option[:url].nil? or option[:url].empty? then
- raise ArgumentError, "Usage: pkg-build -u <package server url> [-o <os>] [-c] [-h]"
- end
-
- return option
+ #option parsing
+ option = {}
+ optparse = OptionParser.new do |opts|
+ opts.banner = "Build and packaging service command-line tool." + "\n" \
+ + "\n" + "Usage: pkg-build -u <package server url> [-o <os>] [-c] [-h] [-v]" + "\n" \
+ + "\n" + "Options:" + "\n"
+
+ opts.on('-u','--url <package server url>', 'remote package server url: http://127.0.0.1/dibs/unstable') do |url|
+ option[:url] = url
+ end
+
+ option[:os] = nil
+ opts.on('-o','--os <os>', 'operating system ') do |os|
+ option[:os] = os
+ end
+
+ option[:clean] = false
+ opts.on('-c','--clean', 'clean build') do
+ option[:clean] = true
+ end
+
+ option[:rev] = false
+ #opts.on('-r','--rev', 'reverse build dependency check') do
+ # option[:rev] = true
+ #end
+
+ opts.on('-h','--help', 'display help') do
+ puts opts
+ exit
+ end
+
+ opts.on('-v','--version', 'display version') do
+ puts "DIBS(Distributed Intelligent Build System) version " + Utils.get_version()
+ exit
+ end
+ end
+
+ optparse.parse!
+
+ if option[:url].nil? or option[:url].empty? then
+ raise ArgumentError, "Usage: pkg-build -u <package server url> [-o <os>] [-c] [-h]"
+ end
+
+ return option
end
=begin
-
+
Action.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
@download_cache_mutex = Mutex.new
end
- def self.create(port, log, ftp_url=nil, cache_dir=nil)
+ def self.create(port, log, ftp_url=nil, cache_dir=nil)
# checking port is available
if port_open? port then
raise "Port \"#{@port}\" is already in use."
FileUtils.mkdir_p cache_dir
end
- return new(port, log, ftp_url, cache_dir)
- end
+ return new(port, log, ftp_url, cache_dir)
+ end
# wait for connection and handle request
def wait_for_connection(quit_loop)
while( not quit_loop )
req = @tcp_server.accept
-
+
begin
yield req if block_given?
rescue
@tcp_server.close()
end
-
+
# send_begin
def self.send_begin( req )
send( req, "=BEGIN,#{VERSION}")
def send_file(req, src_file)
- begin
- if not File.exist? src_file then
- @log.error "\"#{src_file}\" file does not exist"
- req.puts "ERROR"
- return false
- end
-
- req.puts "READY"
+ begin
+ if not File.exist? src_file then
+ @log.error "\"#{src_file}\" file does not exist"
+ req.puts "ERROR"
+ return false
+ end
+
+ req.puts "READY"
@log.info "Ready to send file"
while line = req.gets()
transporter = FileTransferDirect.new(@log)
when "FTP"
if not @ftp_url.nil? then
- url_contents = Utils.parse_ftpserver_url(@ftp_url)
+ url_contents = Utils.parse_ftpserver_url(@ftp_url)
ip = url_contents[0]
port = url_contents[1]
- username = url_contents[2]
- passwd = url_contents[3]
+ username = url_contents[2]
+ passwd = url_contents[3]
transporter = FileTransferFTP.new(@log, ip, port, username, passwd)
else
transporter = FileTransferFTP.new(@log)
end
end
- rescue => e
- puts "[BuildCommServer] Exception"
+ rescue => e
+ puts "[BuildCommServer] Exception"
@log.error e.message
@log.error e.backtrace.inspect
return false
end
- return true
+ return true
end
# NOTE. dst_file can be directory
def receive_file(req, dst_file)
begin
- req.puts "READY"
+ req.puts "READY"
@log.info "Ready to receive file"
while line = req.gets()
file_name = tok[1]
file_size = tok[2].to_i
checksum = tok[3]
-
+
# check download cache
- if File.exist? dst_file and File.directory? dst_file then
+ if File.exist? dst_file and File.directory? dst_file then
target_file = File.join(dst_file,file_name)
- else
+ else
target_file = dst_file
end
if not @cache_dir.nil? and
transporter = FileTransferDirect.new(@log)
when "FTP"
if not @ftp_url.nil? then
- url_contents = Utils.parse_ftpserver_url(@ftp_url)
+ url_contents = Utils.parse_ftpserver_url(@ftp_url)
ip = url_contents[0]
port = url_contents[1]
- username = url_contents[2]
- passwd = url_contents[3]
+ username = url_contents[2]
+ passwd = url_contents[3]
transporter = FileTransferFTP.new(@log, ip, port, username, passwd)
else
transporter = FileTransferFTP.new(@log)
if not @cache_dir.nil? then
add_download_cache(target_file)
end
- break
+ break
else
@log.warn "Unhandled message: #{line}"
end
end
rescue => e
- puts "[BuildCommServer] Exception"
+ puts "[BuildCommServer] Exception"
@log.error e.message
@log.error e.backtrace.inspect
return false
end
- return true
+ return true
end
private_class_method :new
def initialize(socket, log)
- @log = log
+ @log = log
@socket = socket
end
return false
end
-
+
# get contents
while line = @socket.gets()
if line.strip == "=END" then break end
yield line.strip if block_given?
end
rescue Timeout::Error
- puts "WARN: Connection timed out"
+ puts "WARN: Connection timed out"
return false
rescue => e
- puts e.message
+ puts e.message
return false
end
return nil
end
-
+
# get contents
while line = @socket.gets()
if line.strip == "=END" then break end
def send_file(src_file, transporter )
result = true
- begin
- l = @socket.gets()
- if l.nil? then
- @log.error "[BuildCommClient] Connection refused"
+ begin
+ l = @socket.gets()
+ if l.nil? then
+ @log.error "[BuildCommClient] Connection refused"
return false
end
# check protocol
if not protocol_matched? l.strip then
- @log.error "[BuildCommClient] Comm. Protocol version is mismatched! #{VERSION}"
+ @log.error "[BuildCommClient] Comm. Protocol version is mismatched! #{VERSION}"
return false
end
- while line = @socket.gets()
- cmd = line.split(",")[0].strip
+ while line = @socket.gets()
+ cmd = line.split(",")[0].strip
case cmd
- when "READY"
- @log.info "Server is ready!"
+ when "READY"
+ @log.info "Server is ready!"
file_name = File.basename(src_file)
file_size = File.size(src_file)
checksum = Utils.checksum(src_file)
- send "CHECK_CACHE,#{file_name},#{file_size},#{checksum}"
+ send "CHECK_CACHE,#{file_name},#{file_size},#{checksum}"
- when "CACHED"
- @log.info "Server already has cached file"
+ when "CACHED"
+ @log.info "Server already has cached file"
break
- when "NOT_CACHED"
- @log.info "Server does not have cached file"
+ when "NOT_CACHED"
+ @log.info "Server does not have cached file"
send "CHECK_TRANSPORTER,#{transporter.type}"
when "TRANSPORTER_OK"
if not transporter.send_file( src_file, @socket, true ) then
result = false
else
- @log.info "Sending file succeeded!"
+ @log.info "Sending file succeeded!"
end
when "TRANSPORTER_FAIL"
@log.warn "Server does not support transporter type: #{transporter.type}"
result = false
- when "ERROR"
+ when "ERROR"
result = false
- when "=END"
+ when "=END"
break
-
+
else
@log.warn "Unhandled message: #{line}"
- end
- end
- rescue => e
- puts "[BuildCommClient] Exception"
+ end
+ end
+ rescue => e
+ puts "[BuildCommClient] Exception"
@log.error e.message
@log.error e.backtrace.inspect
return false
return false
end
- while line = @socket.gets()
- cmd = line.split(",")[0].strip
+ while line = @socket.gets()
+ cmd = line.split(",")[0].strip
case cmd
- when "READY"
- @log.info "Server is ready!"
+ when "READY"
+ @log.info "Server is ready!"
send "CHECK_TRANSPORTER,#{transporter.type}"
when "TRANSPORTER_OK"
if not transporter.receive_file( dst_file, @socket, true ) then
result = false
else
- @log.info "Receiving file succeeded!"
+ @log.info "Receiving file succeeded!"
end
- when "ERROR"
+ when "ERROR"
result = false
- when "=END"
+ when "=END"
break
else
@log.warn "Unhandled message: #{line}"
- end
- end
+ end
+ end
rescue => e
- puts "[BuildCommServer] Exception"
+ puts "[BuildCommServer] Exception"
@log.error e.message
@log.error e.backtrace.inspect
return false
@socket.close
end
-
+
private
def send_file( src_file, conn, is_client=true )
- filename = File.basename(src_file)
+ filename = File.basename(src_file)
size = File.size( src_file )
checksum = Utils.checksum( src_file )
cmd = tok[0].strip
case cmd
when "SEND_REQ"
- conn.puts "FILE_INFO,#{filename},#{size},#{checksum}"
+ conn.puts "FILE_INFO,#{filename},#{size},#{checksum}"
# read file contents
# send via tcp/ip
File.open(src_file, "rb") {|io|
}
@log.info "Upload is succeeded!"
- conn.puts "SEND_OK"
+ conn.puts "SEND_OK"
- # wait for download result
+ # wait for download result
when "RECEIVE_OK"
@log.info "Received download success message from remote site"
return true
-
+
when "RECEIVE_FAIL"
@log.info "Received download fail message from remote site"
return false
def receive_file( dst_file, conn, is_client=false )
if is_client then
- conn.puts "SEND_REQ"
+ conn.puts "SEND_REQ"
end
while line = conn.gets()
cmd = tok[0].strip
case cmd
when "RECEIVE_REQ"
- conn.puts "SEND_REQ"
+ conn.puts "SEND_REQ"
when "FILE_INFO"
@log.info "Received file info from remote site"
filename = tok[1].strip
end
File.open( dst_file, "wb" ) { |io|
- while size > 0
- buf = conn.read(size > 1024*1024 ? 1024*1024 : size)
- io.write( buf )
- size -= buf.length
- end
+ while size > 0
+ buf = conn.read(size > 1024*1024 ? 1024*1024 : size)
+ io.write( buf )
+ size -= buf.length
+ end
}
conn.puts "RECEIVE_OK"
@log.info "Received success message from remote site"
return true
- else
+ else
@log.error "Unhandled message: #{line}"
return false
end
port = tok[2].strip
username = tok[3].strip
passwd = tok[4].strip
- @log.info "Using FTP information from remote... [#{ip}, #{port}]"
+ @log.info "Using FTP information from remote... [#{ip}, #{port}]"
end
# upload to ftp
ftp_filepath = nil
for attempt in ATTEMPTS
- ftp_filepath = putfile( src_file, ip, port, username, passwd )
+ ftp_filepath = putfile( src_file, ip, port, username, passwd )
if !ftp_filepath.nil? then
break
else
return false
else
@log.info "Upload is succeeded at #{attempt}"
- conn.puts "UPLOAD_OK,#{ftp_filepath}"
+ conn.puts "UPLOAD_OK,#{ftp_filepath}"
end
- # wait for download result
+ # wait for download result
when "DOWNLOAD_OK"
@log.info "Received download success message from remote site"
# clean
cleandir( ftp_filepath, ip, port, username, passwd)
- @log.info "Cleaned temporary dir on FTP server: #{ftp_filepath}"
+ @log.info "Cleaned temporary dir on FTP server: #{ftp_filepath}"
return true
-
+
when "DOWNLOAD_FAIL"
@log.info "Received download fail message from remote site"
return false
conn.puts "DOWNLOAD_FAIL"
return false
end
- conn.puts "UPLOAD_REQ,#{@ip},#{@port},#{@username},#{@passwd}"
+ conn.puts "UPLOAD_REQ,#{@ip},#{@port},#{@username},#{@passwd}"
end
ip = @ip; port = @port; username = @username; passwd = @passwd
port = tok[2].strip
username = tok[3].strip
passwd = tok[4].strip
- @log.info "Using FTP information from remote... [#{ip}, #{port}]"
+ @log.info "Using FTP information from remote... [#{ip}, #{port}]"
end
- conn.puts "UPLOAD_REQ,#{ip},#{port},#{username},#{passwd}"
+ conn.puts "UPLOAD_REQ,#{ip},#{port},#{username},#{passwd}"
when "UPLOAD_OK"
@log.info "Received upload success message from remote site"
filepath = tok[1].strip
@log.info "Received upload fail message from remote site"
return false
- else
+ else
@log.error "Unhandled message: #{line}"
return false
end
end
- def putfile( bpath, ip, port, username, passwd )
- filename = File.basename(bpath)
- uniqdir = Utils.create_uniq_name
- ftp_filepath = File.join(uniqdir, filename)
+ def putfile( bpath, ip, port, username, passwd )
+ filename = File.basename(bpath)
+ uniqdir = Utils.create_uniq_name
+ ftp_filepath = File.join(uniqdir, filename)
- begin
- ftp = Net::FTP.new
- if port.nil? or port == "" then
- ftp.connect(ip)
- else
- ftp.connect(ip, port)
- end
+ begin
+ ftp = Net::FTP.new
+ if port.nil? or port == "" then
+ ftp.connect(ip)
+ else
+ ftp.connect(ip, port)
+ end
@log.info "[FTP log] Connected FTP server (#{ip}:#{port})"
- ftp.login(username, passwd)
- ftp.binary = true
+ ftp.login(username, passwd)
+ ftp.binary = true
ftp.passive = true
- ftp.mkdir(uniqdir)
- ftp.chdir(uniqdir)
- ftp.put(bpath)
+ ftp.mkdir(uniqdir)
+ ftp.chdir(uniqdir)
+ ftp.put(bpath)
@log.info "[FTP log] Put a file"
@log.info "[FTP log] from \"#{bpath}\" to \"#{ftp_filepath}\""
files = ftp.list(filename)
@log.error "[FTP log] Failed to upload file (#{filename} does not exist)"
return nil
end
- ftp.quit
+ ftp.quit
@log.info "[FTP log] Disconnected FTP server"
- rescue => e
+ rescue => e
@log.error "[FTP log] Exception"
@log.error e.message
@log.error e.backtrace.inspect
return nil
- end
+ end
return ftp_filepath
- end
+ end
- def getfile( bpath, target, ip, port, username, passwd )
- dirname = File.dirname(bpath)
- filename = File.basename(bpath)
+ def getfile( bpath, target, ip, port, username, passwd )
+ dirname = File.dirname(bpath)
+ filename = File.basename(bpath)
- # target can be directory or file
- if File.directory? target then
- dst_file = File.join(target,filename)
- else
- dst_file = target
- end
+ # target can be directory or file
+ if File.directory? target then
+ dst_file = File.join(target,filename)
+ else
+ dst_file = target
+ end
- begin
- ftp = Net::FTP.new
- if port.nil? or port == "" then
- ftp.connect(ip)
- else
- ftp.connect(ip, port)
- end
+ begin
+ ftp = Net::FTP.new
+ if port.nil? or port == "" then
+ ftp.connect(ip)
+ else
+ ftp.connect(ip, port)
+ end
@log.info "[FTP log] Connected FTP server (#{ip}:#{port})"
- ftp.login(username, passwd)
- ftp.binary = true
+ ftp.login(username, passwd)
+ ftp.binary = true
ftp.passive = true
- ftp.chdir(dirname)
- ftp.get(filename, dst_file)
+ ftp.chdir(dirname)
+ ftp.get(filename, dst_file)
@log.info "[FTP log] Get a file"
@log.info "[FTP log] from \"#{bpath}\" to \"#{dst_file}\""
- ftp.quit
+ ftp.quit
@log.info "[FTP log] Disconnected FTP server"
- rescue => e
+ rescue => e
@log.error "[FTP log] Exception"
@log.error e.message
@log.error e.backtrace.inspect
@log.error "[FTP log] Failed to download file (#{dst_file} does not exist)"
return nil
end
- return bpath
- end
+ return bpath
+ end
- def cleandir(path, ip, port, username, passwd)
- dirname = File.dirname(path)
+ def cleandir(path, ip, port, username, passwd)
+ dirname = File.dirname(path)
- begin
- ftp = Net::FTP.new
- if port.nil? or port == "" then
- ftp.connect(ip)
- else
- ftp.connect(ip, port)
- end
+ begin
+ ftp = Net::FTP.new
+ if port.nil? or port == "" then
+ ftp.connect(ip)
+ else
+ ftp.connect(ip, port)
+ end
@log.info "[FTP log] Connected FTP server (#{ip}:#{port})"
- ftp.login(username, passwd)
- old_dir = ftp.pwd
- ftp.chdir(dirname)
- list = ftp.ls
- # TODO: if list is directory?
- list.each do |l|
- file = l.split(" ")[-1].strip
- ftp.delete(file)
- end
- ftp.chdir(old_dir)
- ftp.rmdir(dirname)
+ ftp.login(username, passwd)
+ old_dir = ftp.pwd
+ ftp.chdir(dirname)
+ list = ftp.ls
+ # TODO: if list is directory?
+ list.each do |l|
+ file = l.split(" ")[-1].strip
+ ftp.delete(file)
+ end
+ ftp.chdir(old_dir)
+ ftp.rmdir(dirname)
@log.info "[FTP log] Clean dir (#{dirname})"
- ftp.quit
+ ftp.quit
@log.info "[FTP log] Disconnected FTP server"
- rescue => e
+ rescue => e
@log.error "[FTP log] Exception"
@log.error e.message
@log.error e.backtrace.inspect
return nil
- end
+ end
- return true
+ return true
end
end
=begin
-
+
PackageManifest.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
end
end
list.uniq!
-
+
return list
end
-
+
# scan all source dependencies
def get_source_dependencies( target_os, host_os )
# for all
# package that has the target os
pkg.source_dep_list.each do |dep|
- # if dep.target_os_list.include? target_os
- list.push dep
- # end
+ # if dep.target_os_list.include? target_os
+ list.push dep
+ # end
end
end
list.uniq!
return true
end
-
+
return false
end
end
=begin
-
+
ScheduledActionHandler.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
@thread = Thread.new {
# main
thread_main()
-
+
# close
terminate()
}
=begin
-
+
Version.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
class Version < Array
- def initialize s
- super(s.split('.').map { |e| e.to_i })
+ def initialize s
+ super(s.split('.').map { |e| e.to_i })
end
def < x
(self <=> x) < 0
=begin
-
+
dependency.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
require "Version"
class Dependency
- attr_accessor :package_name, :comp, :base_version, :target_os_list
- def initialize (package_name, comp, base_version, target_os_list)
- @package_name = package_name
- @comp = comp
- @base_version = base_version
- @target_os_list = target_os_list
- end
+ attr_accessor :package_name, :comp, :base_version, :target_os_list
+ def initialize (package_name, comp, base_version, target_os_list)
+ @package_name = package_name
+ @comp = comp
+ @base_version = base_version
+ @target_os_list = target_os_list
+ end
+
+ def to_s
+ string = @package_name
+ if not @comp.nil? and not @base_version.nil? then
+ string = string + " ( #{@comp} #{@base_version} )"
+ end
- def to_s
- string = @package_name
- if not @comp.nil? and not @base_version.nil? then
- string = string + " ( #{@comp} #{@base_version} )"
- end
-
- if not @target_os_list.empty? then
- string = string + " [ #{@target_os_list.join("|")} ]"
- end
- return string
- end
+ if not @target_os_list.empty? then
+ string = string + " [ #{@target_os_list.join("|")} ]"
+ end
+ return string
+ end
def match? ver
if @base_version.nil?
#!/usr/bin/ruby
=begin
-
+
execute_with_log.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
# execute and write log
IO.popen("#{cmd} 2>&1") { |io|
io.each { |line|
- log.info line
- }
+ log.info line
+ }
}
# return exit code
=begin
-
+
log.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
# init
def initialize(path, lv=LV_USER)
@cnt = 0
- @path = path
+ @path = path
if @path.nil? then
@logger = Logger.new(STDOUT)
else
def info(msg, lv=LV_NORMAL)
- if @path.nil? and not @second_out.nil? then puts "Info: #{msg}"
- else @logger.info msg end
+ if @path.nil? and not @second_out.nil? then puts "Info: #{msg}"
+ else @logger.info msg end
if not @second_out.nil? and lv >= @second_out_level then
output_extra "Info: " + msg
end
end
def warn(msg, lv=LV_NORMAL)
- if @path.nil? and not @second_out.nil? then puts "Warn: #{msg}"
+ if @path.nil? and not @second_out.nil? then puts "Warn: #{msg}"
else @logger.warn msg end
if not @second_out.nil? and lv >= @second_out_level then
output_extra "Warn: " + msg
def error(msg, lv=LV_NORMAL)
- if @path.nil? and not @second_out.nil? then puts "Error: #{msg}"
+ if @path.nil? and not @second_out.nil? then puts "Error: #{msg}"
else @logger.error msg end
if not @second_out.nil? and lv >= @second_out_level then
output_extra "Error: " + msg
def output(msg, lv=LV_NORMAL)
- if @path.nil? and not @second_out.nil? then puts msg
+ if @path.nil? and not @second_out.nil? then puts msg
else @logger.info msg end
if not @second_out.nil? and lv >= @second_out_level then
output_extra msg
=begin
-
+
mail.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
def Mail.send_mail( mail_to, subject, contents )
if mail_to.nil? or mail_to.empty? \
- or subject.nil? or subject.empty? \
- or contents.nil? or contents.empty? then
+ or subject.nil? or subject.empty? \
+ or contents.nil? or contents.empty? then
return false
end
#{contents}
MESSAGE_END
-
- Mail.send_mail2( mail_to, message )
+
+Mail.send_mail2( mail_to, message )
end
def Mail.send_mail2( mail_to_list, message )
puts "There is no maintainer email address "
else
begin
- Net::SMTP.start('localhost') do |smtp|
- smtp.send_message( message, SENDER, mail_to_list)
+ Net::SMTP.start('localhost') do |smtp|
+ smtp.send_message( message, SENDER, mail_to_list)
end
rescue => e
puts "Can't send result email"
mail_list = []
low_email_list.split(",").each do | low_email |
ms = low_email.index('<')
- me = low_email.index('>')
- if ms.nil? or me.nil? then
- next
- else
- mail = low_email[(ms+1)..(me-1)]
- end
-
- if mail.include?("@") then mail_list.push mail end
+ me = low_email.index('>')
+ if ms.nil? or me.nil? then
+ next
+ else
+ mail = low_email[(ms+1)..(me-1)]
+ end
+
+ if mail.include?("@") then mail_list.push mail end
end
return mail_list
=end
class Package
- attr_accessor :package_name, :label, :version, :os, :build_host_os, :maintainer, :attribute, :install_dep_list, :build_dep_list, :source_dep_list, :conflicts, :source, :src_path, :path, :origin, :checksum, :size, :description, :os_list, :custom, :change_log
- def initialize (package_name)
- @package_name = package_name
- @label = ""
- @version = ""
- @os = ""
- @os_list = []
- @build_host_os = []
- @maintainer = ""
- @attribute = []
- @install_dep_list = []
- @build_dep_list = []
- @source_dep_list = []
- @conflicts = []
- @source = ""
- @src_path = ""
- @path = ""
- @origin = ""
- @checksum = ""
- @size = ""
- @description = ""
+ attr_accessor :package_name, :label, :version, :os, :build_host_os, :maintainer, :attribute, :install_dep_list, :build_dep_list, :source_dep_list, :conflicts, :source, :src_path, :path, :origin, :checksum, :size, :description, :os_list, :custom, :change_log
+ def initialize (package_name)
+ @package_name = package_name
+ @label = ""
+ @version = ""
+ @os = ""
+ @os_list = []
+ @build_host_os = []
+ @maintainer = ""
+ @attribute = []
+ @install_dep_list = []
+ @build_dep_list = []
+ @source_dep_list = []
+ @conflicts = []
+ @source = ""
+ @src_path = ""
+ @path = ""
+ @origin = ""
+ @checksum = ""
+ @size = ""
+ @description = ""
@custom = ""
@change_log = {}
- end
+ end
- def print
- puts self.to_s
- end
+ def print
+ puts self.to_s
+ end
- def to_s
- string = "Package : " + @package_name
- if not @label.empty? then string = string + "\n" + "Label : " + @label end
- if not @version.empty? then string = string + "\n" + "Version : " + @version end
- if not @os_list.empty? then string = string + "\n" + "OS : " + @os_list.join(", ") end
- if not @build_host_os.empty? then string = string + "\n" + "Build-host-os : " + @build_host_os.join(", ") end
- if not @maintainer.empty? then string = string + "\n" + "Maintainer : " + @maintainer end
- if not @attribute.empty? then string = string + "\n" + "Attribute : " + @attribute.join("|") end
- if not @install_dep_list.empty? then
- string = string + "\n" + "Install-dependency : " + @install_dep_list.map {|x| x.to_s}.join(", ")
- end
- if not @build_dep_list.empty? then
- string = string + "\n" + "Build-dependency : " + @build_dep_list.map {|x| x.to_s}.join(", ")
- end
- if not @source_dep_list.empty? then
- string = string + "\n" + "Source-dependency : " + @source_dep_list.map {|x| x.to_s}.join(", ")
- end
- if not @conflicts.empty? then
- string = string + "\n" + "Conflicts : " + @conflicts.map {|x| x.to_s}.join(", ")
- end
- if not @source.empty? then string = string + "\n" + "Source : " + @source end
- if not @src_path.empty? then string = string + "\n" + "Src-path : " + @src_path end
- if not @path.empty? then string = string + "\n" + "Path : " + @path end
- if not @origin.empty? then string = string + "\n" + "Origin : " + @origin end
- if not @checksum.empty? then string = string + "\n" + "SHA256 : " + @checksum end
- if not @size.empty? then string = string + "\n" + "Size : " + @size end
- if not @custom.empty? then string = string + "\n" + @custom end
- if not @description.empty? then string = string + "\n" + "Description : " + @description end
- return string
- end
+ def to_s
+ string = "Package : " + @package_name
+ if not @label.empty? then string = string + "\n" + "Label : " + @label end
+ if not @version.empty? then string = string + "\n" + "Version : " + @version end
+ if not @os_list.empty? then string = string + "\n" + "OS : " + @os_list.join(", ") end
+ if not @build_host_os.empty? then string = string + "\n" + "Build-host-os : " + @build_host_os.join(", ") end
+ if not @maintainer.empty? then string = string + "\n" + "Maintainer : " + @maintainer end
+ if not @attribute.empty? then string = string + "\n" + "Attribute : " + @attribute.join("|") end
+ if not @install_dep_list.empty? then
+ string = string + "\n" + "Install-dependency : " + @install_dep_list.map {|x| x.to_s}.join(", ")
+ end
+ if not @build_dep_list.empty? then
+ string = string + "\n" + "Build-dependency : " + @build_dep_list.map {|x| x.to_s}.join(", ")
+ end
+ if not @source_dep_list.empty? then
+ string = string + "\n" + "Source-dependency : " + @source_dep_list.map {|x| x.to_s}.join(", ")
+ end
+ if not @conflicts.empty? then
+ string = string + "\n" + "Conflicts : " + @conflicts.map {|x| x.to_s}.join(", ")
+ end
+ if not @source.empty? then string = string + "\n" + "Source : " + @source end
+ if not @src_path.empty? then string = string + "\n" + "Src-path : " + @src_path end
+ if not @path.empty? then string = string + "\n" + "Path : " + @path end
+ if not @origin.empty? then string = string + "\n" + "Origin : " + @origin end
+ if not @checksum.empty? then string = string + "\n" + "SHA256 : " + @checksum end
+ if not @size.empty? then string = string + "\n" + "Size : " + @size end
+ if not @custom.empty? then string = string + "\n" + @custom end
+ if not @description.empty? then string = string + "\n" + "Description : " + @description end
+ return string
+ end
- def print_to_file(file)
- file.puts self.to_s
- end
+ def print_to_file(file)
+ file.puts self.to_s
+ end
def change_log_string
if @change_log.empty? then return "" end
require "dependency"
class Parser
- def Parser.read_multy_pkginfo_from (file, only_common = false)
- pkglist = []
+ def Parser.read_multy_pkginfo_from (file, only_common = false)
+ pkglist = []
package = nil
common_source = ""
common_version = ""
#file check
- File.open file,"r" do |f|
- #variable initialize
+ File.open file,"r" do |f|
+ #variable initialize
state = "INIT"
- f.each_line do |l|
+ f.each_line do |l|
# commant
if l.strip.start_with? "#" then next end
return read_multy_pkginfo_from(file,true)[3]
end
- def Parser.read_single_pkginfo_from (file)
- return read_multy_pkginfo_from(file)[0]
- end
+ def Parser.read_single_pkginfo_from (file)
+ return read_multy_pkginfo_from(file)[0]
+ end
- def Parser.read_repo_pkg_list_from (file)
- result = {}
- read_multy_pkginfo_from(file).each { |x| result[x.package_name]=x }
- return result
- end
+ def Parser.read_repo_pkg_list_from (file)
+ result = {}
+ read_multy_pkginfo_from(file).each { |x| result[x.package_name]=x }
+ return result
+ end
#for test
def Parser.print (array)
end
end
- private
- def Parser.dep_parser (string_list)
- dependency_list = []
- string_list.each do |dep|
- #variable initialize
- package_name = ""
- comp = nil
- base_version = nil
- target_os_list = []
- #string trim
- dependency = dep.tr " \t\r\n", ""
- #version extract
- vs = dependency.index('(')
- ve = dependency.index(')')
- if not vs.nil? and not ve.nil? then
- comp = dependency[(vs+1)..(vs+2)]
- base_version = dependency[(vs+3)..(ve-1)]
- end
- #os list extract
- os = dependency.index('[')
- oe = dependency.index(']')
- if not os.nil? and not oe.nil? then
- target_os_list = dependency[(os+1)..(oe-1)].split("|")
- end
- # package_name extract
- pe = dependency.index(/[\]\[\)\(]/)
- if pe.nil?
- package_name = dependency
- else
- package_name = dependency[0..pe-1]
- end
- #package_name check
- if not package_name.empty? then
- dependency_list.push Dependency.new(package_name,comp,base_version,target_os_list)
- end
- end
- return dependency_list
- end
+ private
+ def Parser.dep_parser (string_list)
+ dependency_list = []
+ string_list.each do |dep|
+ #variable initialize
+ package_name = ""
+ comp = nil
+ base_version = nil
+ target_os_list = []
+ #string trim
+ dependency = dep.tr " \t\r\n", ""
+ #version extract
+ vs = dependency.index('(')
+ ve = dependency.index(')')
+ if not vs.nil? and not ve.nil? then
+ comp = dependency[(vs+1)..(vs+2)]
+ base_version = dependency[(vs+3)..(ve-1)]
+ end
+ #os list extract
+ os = dependency.index('[')
+ oe = dependency.index(']')
+ if not os.nil? and not oe.nil? then
+ target_os_list = dependency[(os+1)..(oe-1)].split("|")
+ end
+ # package_name extract
+ pe = dependency.index(/[\]\[\)\(]/)
+ if pe.nil?
+ package_name = dependency
+ else
+ package_name = dependency[0..pe-1]
+ end
+ #package_name check
+ if not package_name.empty? then
+ dependency_list.push Dependency.new(package_name,comp,base_version,target_os_list)
+ end
+ end
+ return dependency_list
+ end
end
=begin
-
+
utils.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
os = "UnsupportedOS"
case `uname -s`.strip
- when "Linux"
- if File.exist? "/etc/debian_version" then
- arch = (`uname -i`.strip == "x86_64") ? "64" : "32"
- os = "ubuntu-#{arch}"
- elsif File.exist? "/etc/redhat-release" then
- os = "redhat-unknown"
- elsif File.exist? "/etc/SuSE-release" then
- arch = (`uname -i`.strip == "x86_64") ? "64" : "32"
- os = "opensuse-#{arch}"
- elsif File.exist? "/etc/mandrake-release" then
- os = "mandrake-unknown"
- end
- when "MINGW32_NT-5.1"
- progfile_path = Utils.execute_shell_return("echo $PROGRAMFILES","windows")[0].strip
- if progfile_path.include?("(x86)") then arch = "64" else arch = "32" end
- os = "windows-#{arch}"
- when "MINGW32_NT-6.1"
- progfile_path = Utils.execute_shell_return("echo $PROGRAMFILES","windows")[0].strip
- if progfile_path.include?("(x86)") then arch = "64" else arch = "32" end
- os = "windows-#{arch}"
- when "Darwin"
- os = "macos-64"
+ when "Linux"
+ if File.exist? "/etc/debian_version" then
+ arch = (`uname -i`.strip == "x86_64") ? "64" : "32"
+ os = "ubuntu-#{arch}"
+ elsif File.exist? "/etc/redhat-release" then
+ os = "redhat-unknown"
+ elsif File.exist? "/etc/SuSE-release" then
+ arch = (`uname -i`.strip == "x86_64") ? "64" : "32"
+ os = "opensuse-#{arch}"
+ elsif File.exist? "/etc/mandrake-release" then
+ os = "mandrake-unknown"
+ end
+ when "MINGW32_NT-5.1"
+ progfile_path = Utils.execute_shell_return("echo $PROGRAMFILES","windows")[0].strip
+ if progfile_path.include?("(x86)") then arch = "64" else arch = "32" end
+ os = "windows-#{arch}"
+ when "MINGW32_NT-6.1"
+ progfile_path = Utils.execute_shell_return("echo $PROGRAMFILES","windows")[0].strip
+ if progfile_path.include?("(x86)") then arch = "64" else arch = "32" end
+ os = "windows-#{arch}"
+ when "Darwin"
+ os = "macos-64"
end
return os
end
- def Utils.create_uniq_name
- time = Time.new
+ def Utils.create_uniq_name
+ time = Time.new
- # uniq snapshot_name name is year_month_day_hour_min_sec_microsec
+ # uniq snapshot_name name is year_month_day_hour_min_sec_microsec
return time.strftime("%m%d%H%M%S") + time.usec.to_s.rjust(6, '0')
- end
-
- def Utils.is_url_remote(url)
- if url.nil? then
- return false
- end
-
- protocol = url.split(':')[0]
-
- case protocol
- when "http" then
- return true
- else
- return false
- end
- end
-
- # if source_ver > target_ver, return -1
- # if source_ver < target_ver, return 1
- # if source_ver == target_ver, return 0
- def Utils.compare_version(source_ver, target_ver)
- sver = source_ver.split('-')[0]
- tver = target_ver.split('-')[0]
-
- arr_sver = sver.split('.')
- arr_tver = tver.split('.')
-
- slen = arr_sver.length
- tlen = arr_tver.length
- len = tlen
-
- if slen > tlen then
- gap = slen - tlen
- gap.times do
- arr_tver.push("0")
- end
- len = slen
- elsif tlen > slen then
- gap = tlen - slen
- gap.times do
- arr_sver.push("0")
- end
- len = tlen
- end
-
- len.times do |i|
- if arr_sver[i].to_i < arr_tver[i].to_i then
- return 1
- elsif arr_sver[i].to_i > arr_tver[i].to_i then
- return -1
- end
- end
-
- return 0
- end
-
-
- def Utils.generate_shell_command(cmd, os_category = nil)
+ end
+
+ def Utils.is_url_remote(url)
+ if url.nil? then
+ return false
+ end
+
+ protocol = url.split(':')[0]
+
+ case protocol
+ when "http" then
+ return true
+ else
+ return false
+ end
+ end
+
+ # if source_ver > target_ver, return -1
+ # if source_ver < target_ver, return 1
+ # if source_ver == target_ver, return 0
+ def Utils.compare_version(source_ver, target_ver)
+ sver = source_ver.split('-')[0]
+ tver = target_ver.split('-')[0]
+
+ arr_sver = sver.split('.')
+ arr_tver = tver.split('.')
+
+ slen = arr_sver.length
+ tlen = arr_tver.length
+ len = tlen
+
+ if slen > tlen then
+ gap = slen - tlen
+ gap.times do
+ arr_tver.push("0")
+ end
+ len = slen
+ elsif tlen > slen then
+ gap = tlen - slen
+ gap.times do
+ arr_sver.push("0")
+ end
+ len = tlen
+ end
+
+ len.times do |i|
+ if arr_sver[i].to_i < arr_tver[i].to_i then
+ return 1
+ elsif arr_sver[i].to_i > arr_tver[i].to_i then
+ return -1
+ end
+ end
+
+ return 0
+ end
+
+
+ def Utils.generate_shell_command(cmd, os_category = nil)
if os_category.nil? then os_category = get_os_category( HOST_OS ) end
if os_category == "windows" then
mingw_path = "sh.exe -c "
cmd = cmd.gsub("\"", "\\\"")
- cmd = mingw_path + "\"#{cmd}\""
+ cmd = mingw_path + "\"#{cmd}\""
end
return cmd
end
- def Utils.execute_shell(cmd, os_category = nil)
- ret = false
-
+ def Utils.execute_shell(cmd, os_category = nil)
+ ret = false
+
# generate command
cmd = generate_shell_command(cmd, os_category)
`#{cmd}`
- if $?.to_i == 0 then ret = true else ret = false end
-
+ if $?.to_i == 0 then ret = true else ret = false end
+
return ret
end
- def Utils.execute_shell_return(cmd, os_category = nil)
+ def Utils.execute_shell_return(cmd, os_category = nil)
result_lines = []
# generate command
result_lines.push line
end
}
-
- if $?.to_i == 0 then
+
+ if $?.to_i == 0 then
return result_lines
else
return nil
end
end
- def Utils.execute_shell_return_ret(cmd, os_category = nil)
+ def Utils.execute_shell_return_ret(cmd, os_category = nil)
# generate command
cmd = generate_shell_command(cmd, os_category)
- return `#{cmd}`
- end
+ return `#{cmd}`
+ end
# create process and log its all output(stderr, stdout)
end
ruby_path=File.join(Config::CONFIG["bindir"],
- Config::CONFIG["RUBY_INSTALL_NAME"] +
- Config::CONFIG["EXEEXT"])
+ Config::CONFIG["RUBY_INSTALL_NAME"] +
+ Config::CONFIG["EXEEXT"])
# call execute
os_category = get_os_category( HOST_OS )
def Utils.execute_shell_with_stdout(cmd, os_category = nil)
logger = Logger.new(STDOUT)
-
+
# generate command
cmd = generate_shell_command(cmd, os_category)
end
- def Utils.spawn(cmd, os_category = nil)
-
+ def Utils.spawn(cmd, os_category = nil)
+
if os_category.nil? then os_category = get_os_category( HOST_OS ) end
if os_category == "windows" then
'L', # IN LPCSTR lpCurrentDirectory
'P', # IN LPSTARTUPINFOA lpStartupInfo
'P' # OUT LPPROCESS_INFORMATION lpProcessInformation
- ]
+ ]
returnValue = 'I' # BOOL
startupInfo = [STARTUP_INFO_SIZE].pack('I') + ([0].pack('I') * (STARTUP_INFO_SIZE - 4))
return lock_file
end
-
+
def Utils.file_unlock(lock_file)
lock_file.close
end
- def Utils.parse_server_addr(saddr)
- addr = saddr.split(":")
- return nil unless addr.length == 2
- return addr
- end
-
- def Utils.parse_ftpserver_url(surl)
- return nil unless surl.start_with? "ftp://"
-
- surl = surl[6..-1]
- parse1 = surl.split("@")
- return nil unless parse1.length == 2
-
- idpw = parse1[0]
- url = parse1[1]
- parse1 = idpw.split(":")
- return nil unless parse1.length == 2
-
- id = parse1[0]
- passwd = parse1[1]
- if url.end_with? "/" then url = url.chop end
-
- parse1 = url.split(":")
- if parse1.length == 2 then
- ip = parse1[0]
- port = parse1[1]
- elsif parse1.length == 1 then
- ip = parse1[0]
- port = 21
- else
- return nil
- end
-
- return [ip, port, id, passwd]
- end
-
-
- def Utils.generate_ftp_url(addr, port, username, passwd)
+ def Utils.parse_server_addr(saddr)
+ addr = saddr.split(":")
+ return nil unless addr.length == 2
+ return addr
+ end
+
+ def Utils.parse_ftpserver_url(surl)
+ return nil unless surl.start_with? "ftp://"
+
+ surl = surl[6..-1]
+ parse1 = surl.split("@")
+ return nil unless parse1.length == 2
+
+ idpw = parse1[0]
+ url = parse1[1]
+ parse1 = idpw.split(":")
+ return nil unless parse1.length == 2
+
+ id = parse1[0]
+ passwd = parse1[1]
+ if url.end_with? "/" then url = url.chop end
+
+ parse1 = url.split(":")
+ if parse1.length == 2 then
+ ip = parse1[0]
+ port = parse1[1]
+ elsif parse1.length == 1 then
+ ip = parse1[0]
+ port = 21
+ else
+ return nil
+ end
+
+ return [ip, port, id, passwd]
+ end
+
+
+ def Utils.generate_ftp_url(addr, port, username, passwd)
return "ftp://#{username}:#{passwd}@#{addr}:#{port}"
- end
-
-
- def Utils.extract_a_file(file_path, target_file, path)
- dirname = File.dirname(file_path)
- filename = File.basename(file_path)
- ext = File.extname(filename)
-
- # path should be unix path if it is used in tar command
- _package_file_path = Utils.get_unix_path(file_path)
- _path = Utils.get_unix_path(path)
-
- case ext
- when ".zip" then
- if not path.nil? then
- extract_file_command = "unzip -xo #{_package_file_path} #{target_file} -d #{_path}"
- else
- extract_file_command = "unzip -xo #{_package_file_path} #{target_file}"
- end
- when ".tar" then
- if not path.nil? then
- extract_file_command = "tar xf #{_package_file_path} -C #{_path} #{target_file}"
- else
- extract_file_command = "tar xf #{_package_file_path} #{target_file}"
- end
- end
+ end
+
+
+ def Utils.extract_a_file(file_path, target_file, path)
+ dirname = File.dirname(file_path)
+ filename = File.basename(file_path)
+ ext = File.extname(filename)
+
+ # path should be unix path if it is used in tar command
+ _package_file_path = Utils.get_unix_path(file_path)
+ _path = Utils.get_unix_path(path)
+
+ case ext
+ when ".zip" then
+ if not path.nil? then
+ extract_file_command = "unzip -xo #{_package_file_path} #{target_file} -d #{_path}"
+ else
+ extract_file_command = "unzip -xo #{_package_file_path} #{target_file}"
+ end
+ when ".tar" then
+ if not path.nil? then
+ extract_file_command = "tar xf #{_package_file_path} -C #{_path} #{target_file}"
+ else
+ extract_file_command = "tar xf #{_package_file_path} #{target_file}"
+ end
+ end
# check exit code
- ret = execute_shell "#{extract_file_command}"
+ ret = execute_shell "#{extract_file_command}"
if not ret then return false end
# check result file
- if not path.nil? then
- target_file_path = File.join(path, target_file)
- else
- target_file_path = target_file
- end
+ if not path.nil? then
+ target_file_path = File.join(path, target_file)
+ else
+ target_file_path = target_file
+ end
- if not File.exist? target_file_path then
+ if not File.exist? target_file_path then
return false
else
return true
end
- end
+ end
+
-
# check if the os is windows-like
def Utils.is_windows_like_os(os_name)
if os_name.start_with? "windows-" then
# check if the os is linux-like
def Utils.is_linux_like_os(os_name)
if os_name.start_with? "ubuntu-" or
- os_name.start_with? "opensuse-" then
+ os_name.start_with? "opensuse-" then
return true
else
return false
end
end
-
+
def Utils.get_os_category(os_name)
if os_name.start_with? "ubuntu-" or os_name.start_with? "opensuse-" then
return "linux"
def Utils.get_package_name_from_package_file( local_path )
filename = File.basename(local_path)
- if filename =~ /.*_.*_.*\.zip/ then
+ if filename =~ /.*_.*_.*\.zip/ then
new_name = filename.sub(/(.*)_(.*)_(.*)\.zip/,'\1,\2,\3')
return new_name.split(",")[0]
end
def Utils.get_version_from_package_file( local_path )
filename = File.basename(local_path)
- if filename =~ /.*_.*_.*\.zip/ then
+ if filename =~ /.*_.*_.*\.zip/ then
new_name = filename.sub(/(.*)_(.*)_(.*)\.zip/,'\1,\2,\3')
return new_name.split(",")[1]
end
def Utils.get_os_from_package_file( local_path )
filename = File.basename(local_path)
- if filename =~ /.*_.*_.*\.zip/ then
+ if filename =~ /.*_.*_.*\.zip/ then
new_name = filename.sub(/(.*)_(.*)_(.*)\.zip/,'\1,\2,\3')
return new_name.split(",")[2]
end
end
- def Utils.get_sub_processes(base=Process.pid)
- descendants = Hash.new{|ht,k| ht[k]=[k]}
+ def Utils.get_sub_processes(base=Process.pid)
+ descendants = Hash.new{|ht,k| ht[k]=[k]}
# generate pid => ppid hash
# NOTE. MinGW does not support "-o" option and has different output format
os_category = get_os_category(HOST_OS)
if os_category != "windows" then
- Hash[*`ps -eo pid,ppid`.scan(/\d+/).map{|x| x.to_i}].each{|pid,ppid|
- descendants[ppid] << descendants[pid]
- }
- return descendants[base].flatten - [base]
+ Hash[*`ps -eo pid,ppid`.scan(/\d+/).map{|x| x.to_i}].each{|pid,ppid|
+ descendants[ppid] << descendants[pid]
+ }
+ return descendants[base].flatten - [base]
else
result = []
require 'rubygems'
require 'sys/proctable'
win_pids = [base]
- Sys::ProcTable.ps { |proc|
- win_pids << proc.pid if win_pids.include?(proc.ppid)
- }
+ Sys::ProcTable.ps { |proc|
+ win_pids << proc.pid if win_pids.include?(proc.ppid)
+ }
result += win_pids
# gather MinGW/MSYS process id
Hash[*`ps -e`.scan(/^[\t\s]*(\d+)[\t\s]+(\d+)/).flatten.map{|x| x.to_i}].each {|pid,ppid|
- descendants[ppid] << descendants[pid]
- }
-
+ descendants[ppid] << descendants[pid]
+ }
+
# get sub processes of windows pids
win_pids.each { |pid|
if not descendants[pid].nil? then
return result
end
- end
+ end
=begin
-
+
DistSync.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
require "ScheduledActionHandler.rb"
class DistSyncAction < Action
-
+
def initialize(time, pkgserver, dist_name )
super(time, pkgserver.sync_interval)
+=begin
+
+ SocketRegisterListener.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
+
require 'socket'
require 'thread'
$LOAD_PATH.unshift File.dirname(__FILE__)
def stop_listening()
@finish_loop = true
end
-
+
private
# thread main
def wait_for_job_requests
req_list = []
req_list.push @tcp_server.accept
-
+
return req_list
end
if req_line.split("|").count > 0 then
cmd = req_line.split("|")[0].strip
end
-
+
case cmd
when "UPLOAD"
- Thread.new {
- handle_cmd_upload( req_line, req )
- }
+ Thread.new {
+ handle_cmd_upload( req_line, req )
+ }
when "REGISTER"
- Thread.new {
+ Thread.new {
handle_cmd_register( req_line, req )
- }
+ }
when "STOP"
handle_cmd_stop( req_line, req )
else
else
incoming_dir = "#{@parent_server.incoming_path}"
end
-
+
file_path_list = []
- begin
- @comm_server.receive_file(req, incoming_dir)
- rescue => e
- @log.error "Failed to transfer file"
- @log.error e.message
- @log.error e.backtrace.inspect
- end
- BuildCommServer.send_end(req)
+ begin
+ @comm_server.receive_file(req, incoming_dir)
+ rescue => e
+ @log.error "Failed to transfer file"
+ @log.error e.message
+ @log.error e.backtrace.inspect
+ end
+ BuildCommServer.send_end(req)
end
# "Register"
return
end
dist_name = tok[1].strip
-
+
if tok[2].start_with? "DOCK" then
dock_name = tok[3]
idx = 4
@parent_server.reload_dist_package()
snapshot_name = @parent_server.register( file_path_list, dist_name, true, false, true)
BuildCommServer.send(req,"SUCC|#{snapshot_name}")
- rescue => e
- @log.error "register failed"
- @log.error e.message
- @log.error e.backtrace.inspect
- BuildCommServer.send(req, "ERROR|#{e.message}")
- @parent_server.release_lock_file
- return
- end
+ rescue => e
+ @log.error "register failed"
+ @log.error e.message
+ @log.error e.backtrace.inspect
+ BuildCommServer.send(req, "ERROR|#{e.message}")
+ @parent_server.release_lock_file
+ return
+ end
}
-
+
if not dock_name.empty? then
FileUtils.rm_rf "#{@parent_server.incoming_path}/#{dock_name}"
end
BuildCommServer.send_end(req)
end
-
+
# "STOP"
def handle_cmd_stop( line, req )
@log.info "Received STOP REQ"
-
+
BuildCommServer.send_begin(req)
tok = line.split("|").map { |x| x.strip }
return
end
passwd = tok[1].strip
-
+
if @parent_server.passwd.eql? passwd then
@parent_server.finish = true
@log.info "Package server stop flag set"
$filemove_mutex = Mutex.new
class Client
- # constant
- PKG_LIST_FILE_PREFIX = "pkg_list_"
- INSTALLED_PKG_LIST_FILE = "installedpackage.list"
- CONFIG_PATH = "#{PackageServerConfig::CONFIG_ROOT}/client"
- PACKAGE_INFO_DIR = ".info"
- DEFAULT_INSTALL_DIR = "#{Utils::HOME}/build_root"
- DEFAULT_SERVER_ADDR = "http://172.21.17.55/dibs/unstable"
+ # constant
+ PKG_LIST_FILE_PREFIX = "pkg_list_"
+ INSTALLED_PKG_LIST_FILE = "installedpackage.list"
+ CONFIG_PATH = "#{PackageServerConfig::CONFIG_ROOT}/client"
+ PACKAGE_INFO_DIR = ".info"
+ DEFAULT_INSTALL_DIR = "#{Utils::HOME}/build_root"
+ DEFAULT_SERVER_ADDR = "http://172.21.17.55/dibs/unstable"
OS_INFO_FILE = "os_info"
ARCHIVE_PKG_LIST_FILE = "archive_pkg_list"
-
- attr_accessor :server_addr, :location, :pkg_hash_os, :is_server_remote, :installed_pkg_hash_loc, :archive_pkg_list, :all_dep_list, :log, :support_os_list, :config_dist_path, :download_path, :tmp_path, :snapshot_path, :snapshots_path, :snapshot_url
- public
- # initialize
- # create "remote package hash" and "installed package hash"
- # @server_addr = server address (can be included distribution, snapshot)
- # @location = client location (download and install file to this location)
- def initialize(server_addr, location, logger)
+ attr_accessor :server_addr, :location, :pkg_hash_os, :is_server_remote, :installed_pkg_hash_loc, :archive_pkg_list, :all_dep_list, :log, :support_os_list, :config_dist_path, :download_path, :tmp_path, :snapshot_path, :snapshots_path, :snapshot_url
- # create directory
+ public
+ # initialize
+ # create "remote package hash" and "installed package hash"
+ # @server_addr = server address (can be included distribution, snapshot)
+ # @location = client location (download and install file to this location)
+ def initialize(server_addr, location, logger)
+
+ # create directory
if not File.exist? CONFIG_PATH then FileUtils.mkdir_p "#{CONFIG_PATH}" end
- # set default server address, location
- if server_addr.nil? then server_addr = get_default_server_addr() end
+ # set default server address, location
+ if server_addr.nil? then server_addr = get_default_server_addr() end
if location.nil? then location = get_default_inst_dir() end
- # chop server address, if end with "/"
+ # chop server address, if end with "/"
if server_addr.strip.end_with? "/" then server_addr = server_addr.chop end
@snapshot_path = nil
@snapshot_url = true
@server_addr, @snapshot_path = split_addr_and_snapshot(server_addr)
else
- @server_addr = server_addr
+ @server_addr = server_addr
end
- @location = location
- @pkg_hash_os = {}
- @installed_pkg_hash_loc = {}
- @archive_pkg_list = []
- @all_dep_list = []
- @is_server_remote = Utils.is_url_remote(server_addr)
+ @location = location
+ @pkg_hash_os = {}
+ @installed_pkg_hash_loc = {}
+ @archive_pkg_list = []
+ @all_dep_list = []
+ @is_server_remote = Utils.is_url_remote(server_addr)
@support_os_list = []
@config_dist_path = CONFIG_PATH + "/" + get_flat_serveraddr
@download_path = @config_dist_path + "/downloads"
@tmp_path = @config_dist_path + "/tmp"
@snapshots_path = @config_dist_path + "/snapshots"
- # create directory
+ # create directory
if not File.exist? @config_dist_path then FileUtils.mkdir_p "#{@config_dist_path}" end
if not File.exist? @download_path then FileUtils.mkdir_p "#{@download_path}" end
if not File.exist? @snapshots_path then FileUtils.mkdir_p "#{@snapshots_path}" end
if not File.exist? @tmp_path then FileUtils.mkdir_p "#{@tmp_path}" end
- # set log
- if logger.nil? or logger.class.to_s.eql? "String" then
- @log = Log.new(logger)
- else
- @log = logger
+ # set log
+ if logger.nil? or logger.class.to_s.eql? "String" then
+ @log = Log.new(logger)
+ else
+ @log = logger
end
- # read installed pkg list, and create hash
+ # read installed pkg list, and create hash
if not File.exist? @location then FileUtils.mkdir_p "#{@location}" end
@log.info "Update local package list.. [#{@location}]"
read_installed_pkg_list()
@log.info "Initialize - #{server_addr}, #{location}"
end
- public
- # update package list from server
- def update()
+ public
+ # update package list from server
+ def update()
if not @snapshot_url then
$get_snapshot_mutex.synchronize {
@snapshot_path = get_lastest_snapshot(@is_server_remote)
else
@log.info "Snapshot information is not cached"
end
-
+
list_path = get_pkglist_path()
if list_path.nil? then
@log.error "Failed to get package list path"
end
$update_mutex.synchronize {
- create_default_config(@server_addr)
- @log.info "Update package list from \"#{@server_addr}\".. OK"
+ create_default_config(@server_addr)
+ @log.info "Update package list from \"#{@server_addr}\".. OK"
}
- return true
+ return true
end
private
@log.info "Cleard package list, supported os list.. OK"
end
- public
- # download package
- def download(pkg_name, os, trace, loc = nil)
+ public
+ # download package
+ def download(pkg_name, os, trace, loc = nil)
if loc.nil? then loc = @location end
- dependent_pkg_list = []
+ dependent_pkg_list = []
- # get dependent list
- if trace then
- dependent_pkg_list = get_install_dependent_packages(pkg_name, os, true, true)
- if dependent_pkg_list.nil? then
- @log.error "Failed to get dependency for \"#{pkg_name}\" package"
- return nil
- end
- else dependent_pkg_list = [pkg_name] end
+ # get dependent list
+ if trace then
+ dependent_pkg_list = get_install_dependent_packages(pkg_name, os, true, true)
+ if dependent_pkg_list.nil? then
+ @log.error "Failed to get dependency for \"#{pkg_name}\" package"
+ return nil
+ end
+ else dependent_pkg_list = [pkg_name] end
surl = @server_addr
- # download files
- file_local_path = []
- dependent_pkg_list.each do |p|
+ # download files
+ file_local_path = []
+ dependent_pkg_list.each do |p|
pkg_name = get_attr_from_pkg(p, os, "name")
- pkg_path = get_attr_from_pkg(p, os, "path")
- pkg_ver = get_attr_from_pkg(p, os, "version")
+ pkg_path = get_attr_from_pkg(p, os, "path")
+ pkg_ver = get_attr_from_pkg(p, os, "version")
pkg_checksum = get_attr_from_pkg(p, os, "checksum")
pkg_size = get_attr_from_pkg(p, os, "size")
- if pkg_path.nil? or pkg_ver.nil? then
- @log.error "\"#{p}\" package does not exist in package server. If it exist in package server, then try \"pkg-cli update\""
- return nil
- end
- url = surl + pkg_path
- filename = pkg_path.split('/')[-1]
-
- if not FileDownLoader.download(url, loc, @log) then
- end
-
- file_path = File.join(loc, filename)
- file_local_path.push(file_path)
- end
-
- if trace then
- @log.info "Downloaded \"#{pkg_name}\" package with all dependent packages.. OK"
- end
- @log.info " [path: #{file_local_path.join(", ")}]"
-
- return file_local_path
+ if pkg_path.nil? or pkg_ver.nil? then
+ @log.error "\"#{p}\" package does not exist in package server. If it exist in package server, then try \"pkg-cli update\""
+ return nil
+ end
+ url = surl + pkg_path
+ filename = pkg_path.split('/')[-1]
+
+ if not FileDownLoader.download(url, loc, @log) then
+ end
+
+ file_path = File.join(loc, filename)
+ file_local_path.push(file_path)
+ end
+
+ if trace then
+ @log.info "Downloaded \"#{pkg_name}\" package with all dependent packages.. OK"
+ end
+ @log.info " [path: #{file_local_path.join(", ")}]"
+
+ return file_local_path
end
private
$filemove_mutex.synchronize {
if not File.exist? distfile then
Utils.execute_shell("mv #{filepath} #{distfile}")
- else
- Utils.execute_shell("rm -f #{filepath}")
- return distfile
- end
+ else
+ Utils.execute_shell("rm -f #{filepath}")
+ return distfile
+ end
}
if File.exist? distfile then return distfile
return nil
end
- public
- # download dependent source
- def download_dep_source(file_name)
-
- file_url = @server_addr + "/source/#{file_name}"
- if not FileDownLoader.download(file_url, @location, @log) then
- @log.error "Failed download #{file_name}"
- return nil
- end
- file_local_path = File.join(@location, file_name)
- @log.info "Downloaded \"#{file_name}\" source file.. OK"
- @log.info " [path: #{file_local_path}]"
-
- return file_local_path
- end
-
- public
- # upload package
- def upload(ip, port, binary_path_list, ftp_addr=nil, ftp_port=nil, ftp_username=nil, ftp_passwd=nil)
-
- # check ip and port
- if ip.nil? or port.nil? then
- @log.error "Ip and port should be set."
- return nil
- end
-
- # check binary path list
- if binary_path_list.nil? or binary_path_list.empty? then
- @log.error "Binary package path should be set."
- return nil
- end
+ public
+ # download dependent source
+ def download_dep_source(file_name)
+
+ file_url = @server_addr + "/source/#{file_name}"
+ if not FileDownLoader.download(file_url, @location, @log) then
+ @log.error "Failed download #{file_name}"
+ return nil
+ end
+ file_local_path = File.join(@location, file_name)
+ @log.info "Downloaded \"#{file_name}\" source file.. OK"
+ @log.info " [path: #{file_local_path}]"
+
+ return file_local_path
+ end
+
+ public
+ # upload package
+ def upload(ip, port, binary_path_list, ftp_addr=nil, ftp_port=nil, ftp_username=nil, ftp_passwd=nil)
+
+ # check ip and port
+ if ip.nil? or port.nil? then
+ @log.error "Ip and port should be set."
+ return nil
+ end
+
+ # check binary path list
+ if binary_path_list.nil? or binary_path_list.empty? then
+ @log.error "Binary package path should be set."
+ return nil
+ end
# create unique dock number
dock = Utils.create_uniq_name()
- # upload file
- binary_list = []
- binary_path_list.each do |bpath|
- filename = File.basename(bpath)
- client = BuildCommClient.create(ip, port, @log)
-
- if client.nil? then
- @log.error "Failed to create BuildCommClient instance.."
- return nil
- end
-
- @log.info "Send ready REQ.. [UPLOAD]"
- result = client.send("UPLOAD|#{dock}")
- if not result then
- @log.error "Failed to send ready REQ.."
- return nil
- end
-
- begin
+ # upload file
+ binary_list = []
+ binary_path_list.each do |bpath|
+ filename = File.basename(bpath)
+ client = BuildCommClient.create(ip, port, @log)
+
+ if client.nil? then
+ @log.error "Failed to create BuildCommClient instance.."
+ return nil
+ end
+
+ @log.info "Send ready REQ.. [UPLOAD]"
+ result = client.send("UPLOAD|#{dock}")
+ if not result then
+ @log.error "Failed to send ready REQ.."
+ return nil
+ end
+
+ begin
if not ftp_addr.nil? then
transporter=FileTransferFTP.new(@log, ftp_addr, ftp_port, ftp_username, ftp_passwd)
else
transporter=FileTransferDirect.new(@log)
end
- result = client.send_file(bpath, transporter)
- rescue => e
- @log.error "FTP failed to put file (exception)"
- @log.error "#{e.message}"
- @log.error e.backtrace.inspect
- return nil
- end
+ result = client.send_file(bpath, transporter)
+ rescue => e
+ @log.error "FTP failed to put file (exception)"
+ @log.error "#{e.message}"
+ @log.error e.backtrace.inspect
+ return nil
+ end
- if not result then
+ if not result then
@log.error "FTP failed to put file (result is false)"
- return nil
- end
+ return nil
+ end
client.terminate
- binary_list.push(filename)
- end
+ binary_list.push(filename)
+ end
- # register file
+ # register file
if not binary_list.empty? then
- client = BuildCommClient.create(ip, port, @log)
- dist = get_distribution
- if dist.empty? then
- @log.error "Distribution is empty.."
- return nil
- end
-
- @log.info "Send register message.. [REGISTER|#{dist}|DOCK|#{dock}|#{binary_list.join("|")}]"
- snapshot = nil
- if client.send "REGISTER|#{dist}|DOCK|#{dock}|#{binary_list.join("|")}" then
- output = client.read_lines do |l|
- line = l.split("|")
- if line[0].strip == "ERROR" then
- @log.error l.strip
- return nil
- elsif line[0].strip == "SUCC" then
- snapshot = line[1].strip
- end
- end
- if not output then
- @log.error "Failed to register"
- return nil
- end
- end
-
- client.terminate
- snapshot = @server_addr + "/snapshots/" + snapshot
- @log.info "Registered successfully! [#{binary_path_list.join("|")}]"
- if snapshot.empty? then
- @log.error "Failed to generate snapshot"
- end
- end
-
- return snapshot
- end
-
- private
- # verify package before uploading
- def verify_upload(pkg_name, pkg_path)
-
- manifest_file = "pkginfo.manifest"
- uniq_name = Utils.create_uniq_name
- path = Utils::HOME + "/tmp/#{uniq_name}"
- if not File.exist? path then FileUtils.mkdir_p "#{path}" end
- begin
- if not FileInstaller.extract_a_file(pkg_path, manifest_file, path, @log) then
- @log.error "The \"pkginfo.manifest\" file does not exist in \"#{pkg_path}\""
- return false
- end
- manifest_path = File.join(path, manifest_file)
- pkg = Parser.read_single_pkginfo_from manifest_path
+ client = BuildCommClient.create(ip, port, @log)
+ dist = get_distribution
+ if dist.empty? then
+ @log.error "Distribution is empty.."
+ return nil
+ end
+
+ @log.info "Send register message.. [REGISTER|#{dist}|DOCK|#{dock}|#{binary_list.join("|")}]"
+ snapshot = nil
+ if client.send "REGISTER|#{dist}|DOCK|#{dock}|#{binary_list.join("|")}" then
+ output = client.read_lines do |l|
+ line = l.split("|")
+ if line[0].strip == "ERROR" then
+ @log.error l.strip
+ return nil
+ elsif line[0].strip == "SUCC" then
+ snapshot = line[1].strip
+ end
+ end
+ if not output then
+ @log.error "Failed to register"
+ return nil
+ end
+ end
+
+ client.terminate
+ snapshot = @server_addr + "/snapshots/" + snapshot
+ @log.info "Registered successfully! [#{binary_path_list.join("|")}]"
+ if snapshot.empty? then
+ @log.error "Failed to generate snapshot"
+ end
+ end
+
+ return snapshot
+ end
+
+ private
+ # verify package before uploading
+ def verify_upload(pkg_name, pkg_path)
+
+ manifest_file = "pkginfo.manifest"
+ uniq_name = Utils.create_uniq_name
+ path = Utils::HOME + "/tmp/#{uniq_name}"
+ if not File.exist? path then FileUtils.mkdir_p "#{path}" end
+ begin
+ if not FileInstaller.extract_a_file(pkg_path, manifest_file, path, @log) then
+ @log.error "The \"pkginfo.manifest\" file does not exist in \"#{pkg_path}\""
+ return false
+ end
+ manifest_path = File.join(path, manifest_file)
+ pkg = Parser.read_single_pkginfo_from manifest_path
if File.exists? manifest_path then FileUtils.rm_f(manifest_path) end
- FileUtils.remove_dir(path, true)
- rescue Interrupt
- @log.error "Client: Interrupted.."
- FileUtils.remove_dir(path, true)
- @log.info "Removed #{path}"
- raise Interrupt
+ FileUtils.remove_dir(path, true)
+ rescue Interrupt
+ @log.error "Client: Interrupted.."
+ FileUtils.remove_dir(path, true)
+ @log.info "Removed #{path}"
+ raise Interrupt
rescue RuntimeError => e
@log.error( e.message, Log::LV_USER)
- FileUtils.remove_dir(path, true)
- @log.info "Removed #{path}"
+ FileUtils.remove_dir(path, true)
+ @log.info "Removed #{path}"
return false
- end
- new_pkg_ver = pkg.version
- new_pkg_install_dep_list = pkg.install_dep_list
- os = pkg.os
-
- list = get_all_reverse_install_dependent_packages_remote(pkg_name, os, true)
-
- if not list.nil? then
- list.each do |p|
- ilist = get_attr_from_pkg(p, os, "install_dep_list")
- if ilist.nil? then next end
- ilist.each do |l|
- if l.package_name.eql? pkg_name then
- if not l.match? new_pkg_ver then
- @log.error "\"#{p}\" package has following install dependency : #{l.package_name} (#{l.comp} #{l.base_version})"
- return false
- end
- end
- end
- end
- end
-
- if not new_pkg_install_dep_list.nil? then
- new_pkg_install_dep_list.each do |l|
- if not check_remote_pkg(l.package_name, os) then
- @log.error "\"#{pkg_name}\" package has following install dependency : #{l.package_name} (#{l.comp} #{l.base_version}), but \"#{l.package_name}\" is not exist on server"
- return false
- end
- rver = get_attr_from_pkg(l.package_name, os, "version")
- if not l.match? rver then
- @log.error "\"#{pkg_name}\" package has following install dependency : #{l.package_name} (#{l.comp} #{l.base_version})"
- return false
- end
- end
- end
-
- @log.info "Passed to verify packages for uploading.. OK"
- return true
- end
-
- private
- # get distribution
- def get_distribution()
- server = @server_addr
- if server.nil? or server.empty? then
- @log.error "Server addr is nil"
- return nil
- end
-
- dist = ""
+ end
+ new_pkg_ver = pkg.version
+ new_pkg_install_dep_list = pkg.install_dep_list
+ os = pkg.os
+
+ list = get_all_reverse_install_dependent_packages_remote(pkg_name, os, true)
+
+ if not list.nil? then
+ list.each do |p|
+ ilist = get_attr_from_pkg(p, os, "install_dep_list")
+ if ilist.nil? then next end
+ ilist.each do |l|
+ if l.package_name.eql? pkg_name then
+ if not l.match? new_pkg_ver then
+ @log.error "\"#{p}\" package has following install dependency : #{l.package_name} (#{l.comp} #{l.base_version})"
+ return false
+ end
+ end
+ end
+ end
+ end
+
+ if not new_pkg_install_dep_list.nil? then
+ new_pkg_install_dep_list.each do |l|
+ if not check_remote_pkg(l.package_name, os) then
+ @log.error "\"#{pkg_name}\" package has following install dependency : #{l.package_name} (#{l.comp} #{l.base_version}), but \"#{l.package_name}\" is not exist on server"
+ return false
+ end
+ rver = get_attr_from_pkg(l.package_name, os, "version")
+ if not l.match? rver then
+ @log.error "\"#{pkg_name}\" package has following install dependency : #{l.package_name} (#{l.comp} #{l.base_version})"
+ return false
+ end
+ end
+ end
+
+ @log.info "Passed to verify packages for uploading.. OK"
+ return true
+ end
+
+ private
+ # get distribution
+ def get_distribution()
+ server = @server_addr
+ if server.nil? or server.empty? then
+ @log.error "Server addr is nil"
+ return nil
+ end
+
+ dist = ""
dist = File.basename(server)
- return dist
+ return dist
end
private
def get_flat_serveraddr()
- server = @server_addr
- if server.nil? or server.empty? then
- @log.error "Server addr is nil"
- return nil
+ server = @server_addr
+ if server.nil? or server.empty? then
+ @log.error "Server addr is nil"
+ return nil
end
-
+
server = server.delete ".:/@"
return server
end
- public
+ public
# install package
- # install all install dependency packages
- def install(pkg_name, os, trace, force)
+ # install all install dependency packages
+ def install(pkg_name, os, trace, force)
ret = install_internal( pkg_name, os, trace, force )
return ret
end
- private
- def install_internal(pkg_name, os, trace, force)
-
- if trace.nil? then trace = true end
- if force.nil? then force = false end
-
- # check meta package
- is_meta_pkg = check_meta_pkg(pkg_name, os)
- if is_meta_pkg then trace = true end
-
- # compare package version with installed package's
- pkg_ver = get_attr_from_pkg(pkg_name, os, "version")
- if pkg_ver.nil? or pkg_ver.empty? then
- @log.error "#{pkg_name} package does not exist in remote package list"
- return false
- end
-
-
- compare_result = compare_version_with_installed_pkg(pkg_name, pkg_ver)
- if not force then
- case compare_result
- when -1 then
- @log.warn "Checked \"#{pkg_name}\" package version : it is bigger then remote package version"
- return true
- when 0 then
- @log.warn "Checked \"#{pkg_name}\" package version : it is same with remote package version"
- return true
- when 1, 2 then
- end
- end
-
- # if enable trace, create all dependent package list
- if trace then
- dependent_pkg_list = get_install_dependent_packages(pkg_name, os, true, force)
- if dependent_pkg_list.nil? then
- @log.error "Failed to get dependency for \"#{pkg_name}\" package"
- return false
- end
- else
- dependent_pkg_list = [pkg_name]
- end
-
- # TODO: need to compare dependent package version
- # install packages including dependent packages
- dependent_pkg_list.each do |pkg|
- if not install_pkg(pkg, os, force) then
- @log.error "#{pkg} does not exist"
- return false
- end
- add_pkg_info(pkg, os)
- end
-
- # write installed package information to file
- write_pkg_hash_to_file(nil)
-
- if trace then
- @log.info "Installed \"#{pkg_name} [#{pkg_ver}]\" package with all dependent packages.. OK"
- @log.info " [#{dependent_pkg_list.join(" -> ")}]"
- else
- @log.info "Install only \"#{pkg_name} [#{pkg_ver}]\" package.. OK"
- end
-
- return true
+ private
+ def install_internal(pkg_name, os, trace, force)
+
+ if trace.nil? then trace = true end
+ if force.nil? then force = false end
+
+ # check meta package
+ is_meta_pkg = check_meta_pkg(pkg_name, os)
+ if is_meta_pkg then trace = true end
+
+ # compare package version with installed package's
+ pkg_ver = get_attr_from_pkg(pkg_name, os, "version")
+ if pkg_ver.nil? or pkg_ver.empty? then
+ @log.error "#{pkg_name} package does not exist in remote package list"
+ return false
+ end
+
+
+ compare_result = compare_version_with_installed_pkg(pkg_name, pkg_ver)
+ if not force then
+ case compare_result
+ when -1 then
+ @log.warn "Checked \"#{pkg_name}\" package version : it is bigger then remote package version"
+ return true
+ when 0 then
+ @log.warn "Checked \"#{pkg_name}\" package version : it is same with remote package version"
+ return true
+ when 1, 2 then
+ end
+ end
+
+ # if enable trace, create all dependent package list
+ if trace then
+ dependent_pkg_list = get_install_dependent_packages(pkg_name, os, true, force)
+ if dependent_pkg_list.nil? then
+ @log.error "Failed to get dependency for \"#{pkg_name}\" package"
+ return false
+ end
+ else
+ dependent_pkg_list = [pkg_name]
+ end
+
+ # TODO: need to compare dependent package version
+ # install packages including dependent packages
+ dependent_pkg_list.each do |pkg|
+ if not install_pkg(pkg, os, force) then
+ @log.error "#{pkg} does not exist"
+ return false
+ end
+ add_pkg_info(pkg, os)
+ end
+
+ # write installed package information to file
+ write_pkg_hash_to_file(nil)
+
+ if trace then
+ @log.info "Installed \"#{pkg_name} [#{pkg_ver}]\" package with all dependent packages.. OK"
+ @log.info " [#{dependent_pkg_list.join(" -> ")}]"
+ else
+ @log.info "Install only \"#{pkg_name} [#{pkg_ver}]\" package.. OK"
+ end
+
+ return true
end
- public
- # install local package (ignore dependent packages)
- def install_local_pkg(pkg_path, trace, force, repos_paths = nil)
+ public
+ # install local package (ignore dependent packages)
+ def install_local_pkg(pkg_path, trace, force, repos_paths = nil)
ret = install_local_pkg_internal(pkg_path, trace, force, repos_paths)
return ret
end
- private
- def install_local_pkg_internal(pkg_path, trace, force, repos_paths)
+ private
+ def install_local_pkg_internal(pkg_path, trace, force, repos_paths)
- file_name = File.basename(pkg_path)
- pkg_name = file_name.split('_')[0]
+ file_name = File.basename(pkg_path)
+ pkg_name = file_name.split('_')[0]
- if not File.exist? pkg_path then
- @log.error "\"#{pkg_path}\" file does not exist"
- return false
- end
- filename = File.basename(pkg_path)
- ext = File.extname(filename)
- if not ext.eql? ".zip" then
- @log.error "\"#{file_name}\" is not zip file. binary package file should have .zip ext"
- return false
- end
- pkg_name = filename.split("_")[0]
- manifest_file = "pkginfo.manifest"
+ if not File.exist? pkg_path then
+ @log.error "\"#{pkg_path}\" file does not exist"
+ return false
+ end
+ filename = File.basename(pkg_path)
+ ext = File.extname(filename)
+ if not ext.eql? ".zip" then
+ @log.error "\"#{file_name}\" is not zip file. binary package file should have .zip ext"
+ return false
+ end
+ pkg_name = filename.split("_")[0]
+ manifest_file = "pkginfo.manifest"
- uniq_name = Utils.create_uniq_name
- path = Utils::HOME + "/tmp/#{uniq_name}"
+ uniq_name = Utils.create_uniq_name
+ path = Utils::HOME + "/tmp/#{uniq_name}"
if not File.exist? path then FileUtils.mkdir_p "#{path}" end
- begin
- if not FileInstaller.extract_a_file(pkg_path, manifest_file, path, @log) then
- @log.error "pkginfo.manifest file does not exist in #{pkg_path}"
- return false
- end
- manifest_path = File.join(path, manifest_file)
- pkg = Parser.read_single_pkginfo_from manifest_path
- new_pkg_ver = pkg.version
- FileUtils.remove_dir(path, true)
- rescue Interrupt
- @log.error "Client: Interrupted.."
- FileUtils.remove_dir(path, true)
- @log.info "Removed #{path}"
- raise Interrupt
+ begin
+ if not FileInstaller.extract_a_file(pkg_path, manifest_file, path, @log) then
+ @log.error "pkginfo.manifest file does not exist in #{pkg_path}"
+ return false
+ end
+ manifest_path = File.join(path, manifest_file)
+ pkg = Parser.read_single_pkginfo_from manifest_path
+ new_pkg_ver = pkg.version
+ FileUtils.remove_dir(path, true)
+ rescue Interrupt
+ @log.error "Client: Interrupted.."
+ FileUtils.remove_dir(path, true)
+ @log.info "Removed #{path}"
+ raise Interrupt
rescue RuntimeError => e
@log.error( e.message, Log::LV_USER)
FileUtils.remove_dir(path, true)
- @log.info "Removed #{path}"
+ @log.info "Removed #{path}"
return false
- end
+ end
compare_result = compare_version_with_installed_pkg(pkg_name, new_pkg_ver)
if not force then
end
end
- if check_installed_pkg(pkg_name) then
- uninstall(pkg_name, false)
+ if check_installed_pkg(pkg_name) then
+ uninstall(pkg_name, false)
end
if trace then
add_local_pkg_info(pkg_name)
write_pkg_hash_to_file(nil)
- @log.info "Installed \"#{pkg_path} [#{new_pkg_ver}]\" file.. OK"
- return true
- end
-
-
- public
- # upgrade package
- def upgrade(os, trace)
-
- if trace.nil? then trace = true end
- list = check_upgrade(os)
-
- if list.empty? or list.nil? then
- @log.info "There is no packages for upgrading.."
- return false
- end
-
- list.each do |p|
- if check_installed_pkg(p) then
- if not uninstall(p, trace) then
- @log.error "Failed to uninstall \"#{p}\" package.."
- return false
- end
- end
-
- if not install_internal(p, os, trace, false) then
- @log.error "Failed to install \"#{p}\" package.."
- return false
- end
- end
-
- @log.info "Upgraded packages from #{@server_addr}.. OK"
- return true
- end
-
- public
- # check package which will be upgraded
- def check_upgrade(os)
-
- update_pkgs = []
- installed_pkg_hash_key = get_installed_pkg_list_file_path()
- installed_pkg_hash = installed_pkg_hash_loc[installed_pkg_hash_key]
- remote_pkg_hash = pkg_hash_os[os]
-
- if remote_pkg_hash.nil? then
- @log.error "There is no remote package list for #{os}. please pkg-cli update"
- return nil
- end
-
- if installed_pkg_hash.nil? then
- @log.warn "There is no any installed package in \"#{@location}\""
- return remote_pkg_hash.keys
- end
-
- arr_keys = installed_pkg_hash.keys
- arr_keys.each do |k|
- installed_ver = get_attr_from_installed_pkg(k, "version")
- if not check_remote_pkg(k, os) then next end
- remote_ver = get_attr_from_pkg(k, os, "version")
- compare_result = compare_version_with_installed_pkg(k, remote_ver)
- case compare_result
- when -1 then next
- when 0 then next
- when 1 then
- @log.output "\"#{k}\" package : #{installed_ver} -> #{remote_ver}"
- update_pkgs.push(k)
- end
- end
-
- @log.info "Checked packages for upgrading.. OK"
- return update_pkgs
- end
-
- public
- def get_default_server_addr()
- filepath = "#{CONFIG_PATH}/config"
- server_addr = nil
-
- if not File.exist? filepath then create_default_config(nil) end
- if not File.exist? filepath then
- @log.error "There is no default server address in #{filepath}"
- return nil
- end
-
- File.open filepath, "r" do |f|
- f.each_line do |l|
- if l.strip.start_with? "DEFAULT_SERVER_ADDR :" then
- server_addr = l.split("DEFAULT_SERVER_ADDR :")[1].strip
- break
- else next end
- end
- end
-
- if server_addr.nil? then create_default_config(DEFAULT_SERVER_ADDR) end
- return server_addr
- end
-
- public
- # get default path for installing
- def get_default_inst_dir()
- return Dir.pwd
- end
-
- private
- # create default config file (Utils::HOME/.build_tools/client/config)
- def create_default_config(server_addr)
- filepath = "#{CONFIG_PATH}/config"
- if server_addr.nil? then server_addr = DEFAULT_SERVER_ADDR end
-
- if File.exist? filepath then
- FileUtils.rm_f(filepath)
- end
-
- if server_addr.strip.end_with? "/" then server_addr = server_addr.chop end
-
- File.open(filepath, "a+") do |file|
- file.puts "DEFAULT_SERVER_ADDR : #{server_addr}"
- end
- end
-
- public
- # uninstall package
- # trace : if true, uninstall all dependent packages
- def uninstall(pkg_name, trace)
-
- type = "binary"
- pkg_list = []
- pkg_hash = nil
-
- if not check_installed_pkg(pkg_name) then
- @log.error "\"#{pkg_name}\" package is not installed."
- return false
- end
-
- pkg_ver = get_attr_from_installed_pkg(pkg_name, "version")
-
- if trace then
- pkg_list = get_all_reverse_install_dependent_packages(pkg_name, true)
- if pkg_list.nil? then
- @log.error "Failed to get \"#{pkg_name}\" package dependency information."
- return false
- end
- else
- pkg_list.push(pkg_name)
- end
-
- pkg_list.each do |p|
- if not check_installed_pkg(p) then next end
- if not FileInstaller.uninstall(p, type, @location, @log) then
- @log.error "Failed uninstall \"#{pkg_name}\" package"
- return false
- end
- pkg_hash = remove_pkg_info(p)
- end
-
- if trace then
- @log.info "Uninstalled \"#{pkg_name} [#{pkg_ver}]\" package with all dependent packages.. OK"
- @log.info " [#{pkg_list.join(" -> ")}]"
- else
- @log.info "Uninstalled only \"#{pkg_name} [#{pkg_ver}]\" package.. OK"
- end
-
- write_pkg_hash_to_file(nil)
- return true
- end
-
- public
- # clean
- def clean(force)
- if not force then
- puts "Do you really want to remove \"#{@location}\" path? [yes]"
- input = $stdin.gets.strip
- if input.upcase.eql? "YES" then
- @log.info "Removed \"#{@location}\""
- else
- @log.info "Canceled"
- return
- end
- end
+ @log.info "Installed \"#{pkg_path} [#{new_pkg_ver}]\" file.. OK"
+ return true
+ end
+
+
+ public
+ # upgrade package
+ def upgrade(os, trace)
+
+ if trace.nil? then trace = true end
+ list = check_upgrade(os)
+
+ if list.empty? or list.nil? then
+ @log.info "There is no packages for upgrading.."
+ return false
+ end
+
+ list.each do |p|
+ if check_installed_pkg(p) then
+ if not uninstall(p, trace) then
+ @log.error "Failed to uninstall \"#{p}\" package.."
+ return false
+ end
+ end
+
+ if not install_internal(p, os, trace, false) then
+ @log.error "Failed to install \"#{p}\" package.."
+ return false
+ end
+ end
+
+ @log.info "Upgraded packages from #{@server_addr}.. OK"
+ return true
+ end
+
+ public
+ # check package which will be upgraded
+ def check_upgrade(os)
+
+ update_pkgs = []
+ installed_pkg_hash_key = get_installed_pkg_list_file_path()
+ installed_pkg_hash = installed_pkg_hash_loc[installed_pkg_hash_key]
+ remote_pkg_hash = pkg_hash_os[os]
+
+ if remote_pkg_hash.nil? then
+ @log.error "There is no remote package list for #{os}. please pkg-cli update"
+ return nil
+ end
+
+ if installed_pkg_hash.nil? then
+ @log.warn "There is no any installed package in \"#{@location}\""
+ return remote_pkg_hash.keys
+ end
+
+ arr_keys = installed_pkg_hash.keys
+ arr_keys.each do |k|
+ installed_ver = get_attr_from_installed_pkg(k, "version")
+ if not check_remote_pkg(k, os) then next end
+ remote_ver = get_attr_from_pkg(k, os, "version")
+ compare_result = compare_version_with_installed_pkg(k, remote_ver)
+ case compare_result
+ when -1 then next
+ when 0 then next
+ when 1 then
+ @log.output "\"#{k}\" package : #{installed_ver} -> #{remote_ver}"
+ update_pkgs.push(k)
+ end
+ end
+
+ @log.info "Checked packages for upgrading.. OK"
+ return update_pkgs
+ end
+
+ public
+ def get_default_server_addr()
+ filepath = "#{CONFIG_PATH}/config"
+ server_addr = nil
+
+ if not File.exist? filepath then create_default_config(nil) end
+ if not File.exist? filepath then
+ @log.error "There is no default server address in #{filepath}"
+ return nil
+ end
+
+ File.open filepath, "r" do |f|
+ f.each_line do |l|
+ if l.strip.start_with? "DEFAULT_SERVER_ADDR :" then
+ server_addr = l.split("DEFAULT_SERVER_ADDR :")[1].strip
+ break
+ else next end
+ end
+ end
+
+ if server_addr.nil? then create_default_config(DEFAULT_SERVER_ADDR) end
+ return server_addr
+ end
+
+ public
+ # get default path for installing
+ def get_default_inst_dir()
+ return Dir.pwd
+ end
+
+ private
+ # create default config file (Utils::HOME/.build_tools/client/config)
+ def create_default_config(server_addr)
+ filepath = "#{CONFIG_PATH}/config"
+ if server_addr.nil? then server_addr = DEFAULT_SERVER_ADDR end
+
+ if File.exist? filepath then
+ FileUtils.rm_f(filepath)
+ end
+
+ if server_addr.strip.end_with? "/" then server_addr = server_addr.chop end
+
+ File.open(filepath, "a+") do |file|
+ file.puts "DEFAULT_SERVER_ADDR : #{server_addr}"
+ end
+ end
+
+ public
+ # uninstall package
+ # trace : if true, uninstall all dependent packages
+ def uninstall(pkg_name, trace)
+
+ type = "binary"
+ pkg_list = []
+ pkg_hash = nil
+
+ if not check_installed_pkg(pkg_name) then
+ @log.error "\"#{pkg_name}\" package is not installed."
+ return false
+ end
+
+ pkg_ver = get_attr_from_installed_pkg(pkg_name, "version")
+
+ if trace then
+ pkg_list = get_all_reverse_install_dependent_packages(pkg_name, true)
+ if pkg_list.nil? then
+ @log.error "Failed to get \"#{pkg_name}\" package dependency information."
+ return false
+ end
+ else
+ pkg_list.push(pkg_name)
+ end
+
+ pkg_list.each do |p|
+ if not check_installed_pkg(p) then next end
+ if not FileInstaller.uninstall(p, type, @location, @log) then
+ @log.error "Failed uninstall \"#{pkg_name}\" package"
+ return false
+ end
+ pkg_hash = remove_pkg_info(p)
+ end
+
+ if trace then
+ @log.info "Uninstalled \"#{pkg_name} [#{pkg_ver}]\" package with all dependent packages.. OK"
+ @log.info " [#{pkg_list.join(" -> ")}]"
+ else
+ @log.info "Uninstalled only \"#{pkg_name} [#{pkg_ver}]\" package.. OK"
+ end
+
+ write_pkg_hash_to_file(nil)
+ return true
+ end
+
+ public
+ # clean
+ def clean(force)
+ if not force then
+ puts "Do you really want to remove \"#{@location}\" path? [yes]"
+ input = $stdin.gets.strip
+ if input.upcase.eql? "YES" then
+ @log.info "Removed \"#{@location}\""
+ else
+ @log.info "Canceled"
+ return
+ end
+ end
if File.exist? @location then FileUtils.rm_rf(@location) end
- FileUtils.mkdir_p(@location)
- #@pkg_hash_os.clear
- @installed_pkg_hash_loc.clear
- #@archive_pkg_list.clear
- @log.info "Cleaned \"#{@location}\" path.. OK"
- end
-
- public
+ FileUtils.mkdir_p(@location)
+ #@pkg_hash_os.clear
+ @installed_pkg_hash_loc.clear
+ #@archive_pkg_list.clear
+ @log.info "Cleaned \"#{@location}\" path.. OK"
+ end
+
+ public
# get reverse build dependent packages (just 1 depth)
- def get_reverse_build_dependent_packages(pkg_name, os)
+ def get_reverse_build_dependent_packages(pkg_name, os)
- result = []
- pkg_hash = @pkg_hash_os[os]
+ result = []
+ pkg_hash = @pkg_hash_os[os]
if pkg_hash.nil? then return [] end
- pkg_list = pkg_hash.values
- pkg_list.each do |pkg|
- pkg.build_dep_list.each do |dep|
- if dep.package_name.eql? pkg_name and
+ pkg_list = pkg_hash.values
+ pkg_list.each do |pkg|
+ pkg.build_dep_list.each do |dep|
+ if dep.package_name.eql? pkg_name and
not dep.target_os_list.nil? and
dep.target_os_list.include? os then
- result.push(pkg)
- end
- end
- end
+ result.push(pkg)
+ end
+ end
+ end
- return result
- end
+ return result
+ end
- public
+ public
# get reverse source dependent packages (just 1 depth)
- def get_reverse_source_dependent_packages(pkg_name)
+ def get_reverse_source_dependent_packages(pkg_name)
- result = []
- @support_os_list.each do |os|
- pkg_hash = @pkg_hash_os[os]
- pkg_list = pkg_hash.values
- pkg_list.each do |pkg|
- pkg.source_dep_list.each do |p|
- if p.package_name.eql? pkg_name then
- result.push(pkg)
- end
- end
- end
+ result = []
+ @support_os_list.each do |os|
+ pkg_hash = @pkg_hash_os[os]
+ pkg_list = pkg_hash.values
+ pkg_list.each do |pkg|
+ pkg.source_dep_list.each do |p|
+ if p.package_name.eql? pkg_name then
+ result.push(pkg)
+ end
+ end
+ end
end
- return result
- end
+ return result
+ end
- public
+ public
# get reverse install dependent packages (jush 1 depth)
- def get_reverse_install_dependent_packages(pkg_name, os)
-
- result = []
- pkg_hash = @pkg_hash_os[os]
- pkg_list = pkg_hash.values
- pkg_list.each do |pkg|
- pkg.install_dep_list.each do |p|
- if p.package_name.eql? pkg_name then
- result.push(pkg.package_name)
- end
- end
- end
-
- return result
- end
-
- public
+ def get_reverse_install_dependent_packages(pkg_name, os)
+
+ result = []
+ pkg_hash = @pkg_hash_os[os]
+ pkg_list = pkg_hash.values
+ pkg_list.each do |pkg|
+ pkg.install_dep_list.each do |p|
+ if p.package_name.eql? pkg_name then
+ result.push(pkg.package_name)
+ end
+ end
+ end
+
+ return result
+ end
+
+ public
# get all build dependent packages (considered build priority, and reverse)
- def get_build_dependent_packages(pkg_name, os, reverse)
-
- if not check_remote_pkg(pkg_name, os) then return nil end
- if reverse.nil? then reverse = true end
-
- @all_dep_list.clear
- begin
- get_build_dependency_arr(pkg_name, os, 0)
- # in case of cross build dependency
- rescue SystemStackError
- @log.error "Failed to get dependency relation because #{pkg_name} package has cross install dependency."
- return nil
- end
-
- max = 0
- @all_dep_list.each do |p|
- if p[0].to_i > max then
- max = p[0].to_i
- else next end
- end
-
- result = []
- i = 0
- while i <= max
- @all_dep_list.each do |p|
- if p[0].to_i.eql? i then
- d = p[1]
- remote_os = get_attr_from_pkg(d.package_name, os, "os")
- remote_ver = get_attr_from_pkg(d.package_name, os, "version")
- if not d.target_os_list.include? remote_os then
- @log.error "\"#{pkg_name}\" package needs \"#{d.package_name}\" #{d.target_os_list.to_s}, but \"#{d.package_name}\" (#{remote_os}) package is in server"
- return nil
- end
- if not d.match? remote_ver then
- @log.error "\"#{pkg_name}\" package needs \"#{d.package_name}\" #{d.comp} #{d.base_version}, but \"#{d.package_name}\" (#{remote_ver}) package is in server"
- return nil
- else result.push(d.package_name) end
- end
- end
- i = i + 1
- end
-
- @log.info "Get build dependent packages for #{pkg_name} package.. OK"
- if reverse then return result.reverse.uniq.push(pkg_name)
- else return result.uniq.insert(0, pkg_name) end
- end
-
- public
+ def get_build_dependent_packages(pkg_name, os, reverse)
+
+ if not check_remote_pkg(pkg_name, os) then return nil end
+ if reverse.nil? then reverse = true end
+
+ @all_dep_list.clear
+ begin
+ get_build_dependency_arr(pkg_name, os, 0)
+ # in case of cross build dependency
+ rescue SystemStackError
+ @log.error "Failed to get dependency relation because #{pkg_name} package has cross install dependency."
+ return nil
+ end
+
+ max = 0
+ @all_dep_list.each do |p|
+ if p[0].to_i > max then
+ max = p[0].to_i
+ else next end
+ end
+
+ result = []
+ i = 0
+ while i <= max
+ @all_dep_list.each do |p|
+ if p[0].to_i.eql? i then
+ d = p[1]
+ remote_os = get_attr_from_pkg(d.package_name, os, "os")
+ remote_ver = get_attr_from_pkg(d.package_name, os, "version")
+ if not d.target_os_list.include? remote_os then
+ @log.error "\"#{pkg_name}\" package needs \"#{d.package_name}\" #{d.target_os_list.to_s}, but \"#{d.package_name}\" (#{remote_os}) package is in server"
+ return nil
+ end
+ if not d.match? remote_ver then
+ @log.error "\"#{pkg_name}\" package needs \"#{d.package_name}\" #{d.comp} #{d.base_version}, but \"#{d.package_name}\" (#{remote_ver}) package is in server"
+ return nil
+ else result.push(d.package_name) end
+ end
+ end
+ i = i + 1
+ end
+
+ @log.info "Get build dependent packages for #{pkg_name} package.. OK"
+ if reverse then return result.reverse.uniq.push(pkg_name)
+ else return result.uniq.insert(0, pkg_name) end
+ end
+
+ public
# get all install dependent packages (considered install priority, reverse, and force)
- # reverse : return reverse result
- # force : install package force
- def get_install_dependent_packages(pkg_name, os, reverse, force)
-
- if not check_remote_pkg(pkg_name, os) then return nil end
- if reverse.nil? then reverse = true end
-
- @all_dep_list.clear
- begin
- get_install_dependency_arr(pkg_name, os, force, 0)
- # in case of cross build dependency
- rescue SystemStackError
- @log.error "Failed to get dependency relation because #{pkg_name} package has cross install dependency."
- return nil
- end
-
- max = 0
- @all_dep_list.each do |p|
- if p[0].to_i > max then
- max = p[0].to_i
- else next end
- end
-
- result = []
- i = 0
- while i <= max
- @all_dep_list.each do |p|
- if p[0].to_i.eql? i then
- d = p[1]
- remote_ver = get_attr_from_pkg(d.package_name, os, "version")
- if not d.match? remote_ver then
- @log.error "\"#{pkg_name}\" package needs \"#{d.package_name}\" #{d.comp} #{d.base_version}, but \"#{d.package_name}\" (#{remote_ver}) package is in server"
- return nil
- else result.push(d.package_name) end
- end
- end
- i = i + 1
- end
-
- @log.info "Get install dependent packages for \"#{pkg_name}\" package.. OK"
- if reverse then return result.reverse.uniq.push(pkg_name)
- else return result.uniq.insert(0, pkg_name) end
- end
-
- public
- # get all reverse install dependent packages (considered reverse install priority for tracing uninstall)
- def get_all_reverse_install_dependent_packages(pkg_name, reverse)
-
- if not check_installed_pkg(pkg_name) then return nil end
- if reverse.nil? then reverse = true end
-
- begin
- res = get_all_reverse_install_dependency_arr(pkg_name, 0)
- rescue SystemStackError
- @log.error "Failed to get dependency relation because #{pkg_name} package has cross install dependency."
- return nil
- end
- res2 = res.split("::")
- result = []
- res2.each do |r|
- result.push(r.split(':')[1])
- end
-
- @log.info "Get all reverse install dependent packages for #{pkg_name} package.. OK"
- if reverse then return result.reverse.uniq
- else return result end
- end
-
- public
- # get all reverse remote dependent packages (considered reverse install priority for tracing uninstall)
- def get_all_reverse_install_dependent_packages_remote(pkg_name, os, reverse)
- #if not check_remote_pkg(pkg_name, os) then return nil end
- if reverse.nil? then reverse = true end
-
- begin
- res = get_all_reverse_install_dependency_arr_remote(pkg_name, os, 0)
- rescue SystemStackError
- @log.error "Failed to get dependency relation because #{pkg_name} package has cross install dependency."
- return nil
- end
- res2 = res.split("::")
- result = []
- res2.each do |r|
- result.push(r.split(':')[1])
- end
-
- @log.info "Get all reverse install dependent packages for #{pkg_name} package.. OK"
- if reverse then return result.reverse
- else return result end
- end
-
- public
- # check package whether to exist in remote server
- def check_remote_pkg(pkg_name, os)
-
- pkg_hash = @pkg_hash_os[os]
- if pkg_hash.nil? then return false end
- pkg = pkg_hash[pkg_name]
- if pkg.nil? then
- #@log.warn "There is no \"#{pkg_name}\" remote package information in list"
- return false
- end
-
- return true
- end
-
- public
- # check package whether to exist in installed packages
- def check_installed_pkg(pkg_name)
-
- installed_pkg_hash_key = get_installed_pkg_list_file_path()
- pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
- if pkg_hash.nil? then return false end
- pkg = pkg_hash[pkg_name]
-
- if pkg.nil? then return false end
- return true
- end
-
- public
- # get attribute from installed package
- def get_attr_from_installed_pkg(pkg_name, attr)
-
- if not check_installed_pkg(pkg_name) then return nil end
- pkg = get_installed_pkg_from_list(pkg_name)
-
- if pkg.nil? then return nil end
-
- case attr
- when "version" then return pkg.version
- when "source" then return pkg.source
- when "src_path" then return pkg.src_path
- when "os" then return pkg.os
- when "build_dep_list" then return pkg.build_dep_list
- when "install_dep_list" then return pkg.install_dep_list
- when "attribute" then return pkg.attribute
- end
- end
-
- public
- # get attribute from remote package
- def get_attr_from_pkg(pkg_name, os, attr)
-
- if not check_remote_pkg(pkg_name, os) then return nil end
- pkg = get_pkg_from_list(pkg_name, os)
-
- if pkg.nil? then return nil end
-
- case attr
- when "name" then return pkg.package_name
- when "path" then return pkg.path
- when "source" then return pkg.source
- when "version" then return pkg.version
- when "src_path" then return pkg.src_path
- when "os" then return pkg.os
- when "build_dep_list" then return pkg.build_dep_list
- when "install_dep_list" then return pkg.install_dep_list
- when "attribute" then return pkg.attribute
+ # reverse : return reverse result
+ # force : install package force
+ def get_install_dependent_packages(pkg_name, os, reverse, force)
+
+ if not check_remote_pkg(pkg_name, os) then return nil end
+ if reverse.nil? then reverse = true end
+
+ @all_dep_list.clear
+ begin
+ get_install_dependency_arr(pkg_name, os, force, 0)
+ # in case of cross build dependency
+ rescue SystemStackError
+ @log.error "Failed to get dependency relation because #{pkg_name} package has cross install dependency."
+ return nil
+ end
+
+ max = 0
+ @all_dep_list.each do |p|
+ if p[0].to_i > max then
+ max = p[0].to_i
+ else next end
+ end
+
+ result = []
+ i = 0
+ while i <= max
+ @all_dep_list.each do |p|
+ if p[0].to_i.eql? i then
+ d = p[1]
+ remote_ver = get_attr_from_pkg(d.package_name, os, "version")
+ if not d.match? remote_ver then
+ @log.error "\"#{pkg_name}\" package needs \"#{d.package_name}\" #{d.comp} #{d.base_version}, but \"#{d.package_name}\" (#{remote_ver}) package is in server"
+ return nil
+ else result.push(d.package_name) end
+ end
+ end
+ i = i + 1
+ end
+
+ @log.info "Get install dependent packages for \"#{pkg_name}\" package.. OK"
+ if reverse then return result.reverse.uniq.push(pkg_name)
+ else return result.uniq.insert(0, pkg_name) end
+ end
+
+ public
+ # get all reverse install dependent packages (considered reverse install priority for tracing uninstall)
+ def get_all_reverse_install_dependent_packages(pkg_name, reverse)
+
+ if not check_installed_pkg(pkg_name) then return nil end
+ if reverse.nil? then reverse = true end
+
+ begin
+ res = get_all_reverse_install_dependency_arr(pkg_name, 0)
+ rescue SystemStackError
+ @log.error "Failed to get dependency relation because #{pkg_name} package has cross install dependency."
+ return nil
+ end
+ res2 = res.split("::")
+ result = []
+ res2.each do |r|
+ result.push(r.split(':')[1])
+ end
+
+ @log.info "Get all reverse install dependent packages for #{pkg_name} package.. OK"
+ if reverse then return result.reverse.uniq
+ else return result end
+ end
+
+ public
+ # get all reverse remote dependent packages (considered reverse install priority for tracing uninstall)
+ def get_all_reverse_install_dependent_packages_remote(pkg_name, os, reverse)
+ #if not check_remote_pkg(pkg_name, os) then return nil end
+ if reverse.nil? then reverse = true end
+
+ begin
+ res = get_all_reverse_install_dependency_arr_remote(pkg_name, os, 0)
+ rescue SystemStackError
+ @log.error "Failed to get dependency relation because #{pkg_name} package has cross install dependency."
+ return nil
+ end
+ res2 = res.split("::")
+ result = []
+ res2.each do |r|
+ result.push(r.split(':')[1])
+ end
+
+ @log.info "Get all reverse install dependent packages for #{pkg_name} package.. OK"
+ if reverse then return result.reverse
+ else return result end
+ end
+
+ public
+ # check package whether to exist in remote server
+ def check_remote_pkg(pkg_name, os)
+
+ pkg_hash = @pkg_hash_os[os]
+ if pkg_hash.nil? then return false end
+ pkg = pkg_hash[pkg_name]
+ if pkg.nil? then
+ #@log.warn "There is no \"#{pkg_name}\" remote package information in list"
+ return false
+ end
+
+ return true
+ end
+
+ public
+ # check package whether to exist in installed packages
+ def check_installed_pkg(pkg_name)
+
+ installed_pkg_hash_key = get_installed_pkg_list_file_path()
+ pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
+ if pkg_hash.nil? then return false end
+ pkg = pkg_hash[pkg_name]
+
+ if pkg.nil? then return false end
+ return true
+ end
+
+ public
+ # get attribute from installed package
+ def get_attr_from_installed_pkg(pkg_name, attr)
+
+ if not check_installed_pkg(pkg_name) then return nil end
+ pkg = get_installed_pkg_from_list(pkg_name)
+
+ if pkg.nil? then return nil end
+
+ case attr
+ when "version" then return pkg.version
+ when "source" then return pkg.source
+ when "src_path" then return pkg.src_path
+ when "os" then return pkg.os
+ when "build_dep_list" then return pkg.build_dep_list
+ when "install_dep_list" then return pkg.install_dep_list
+ when "attribute" then return pkg.attribute
+ end
+ end
+
+ public
+ # get attribute from remote package
+ def get_attr_from_pkg(pkg_name, os, attr)
+
+ if not check_remote_pkg(pkg_name, os) then return nil end
+ pkg = get_pkg_from_list(pkg_name, os)
+
+ if pkg.nil? then return nil end
+
+ case attr
+ when "name" then return pkg.package_name
+ when "path" then return pkg.path
+ when "source" then return pkg.source
+ when "version" then return pkg.version
+ when "src_path" then return pkg.src_path
+ when "os" then return pkg.os
+ when "build_dep_list" then return pkg.build_dep_list
+ when "install_dep_list" then return pkg.install_dep_list
+ when "attribute" then return pkg.attribute
when "checksum" then return pkg.checksum
when "size" then return pkg.size
- end
- end
-
- public
- # show a package information
- def show_pkg_info(pkg_name, os)
- if not check_remote_pkg(pkg_name, os) then
- @log.error "\"#{pkg_name}\" package does not exist"
- return ""
- end
-
- pkg = get_pkg_from_list(pkg_name, os)
- return pkg.to_s
- end
-
- public
- # show all packages information
- def show_pkg_list(os)
- pkg_hash = @pkg_hash_os[os]
- if pkg_hash.nil? then
- @log.error "\"#{os}\" package list does not exist"
- return ""
- end
-
- pkg_all_list = []
- pkg_list = pkg_hash.values
- pkg_list.each do |p|
- pkg_all_list.push([p.package_name, p.version, p.description])
- end
- return pkg_all_list.sort
- end
-
- public
- # show installed package information
- def show_installed_pkg_info(pkg_name)
-
- if not check_installed_pkg(pkg_name) then
- @log.error "\"#{pkg_name}\" package does not exist"
- return ""
- end
-
- pkg = get_installed_pkg_from_list(pkg_name)
- return pkg.to_s
- end
-
- public
- # show all installed packages information
- def show_installed_pkg_list()
-
- file_path = get_installed_pkg_list_file_path()
- pkg_hash = @installed_pkg_hash_loc[file_path]
- if pkg_hash.nil? then
- @log.error "Installed package list does not exist"
- return nil
- end
- pkg_all_list = []
- pkg_list = pkg_hash.values
- pkg_list.each do |p|
- pkg_all_list.push([p.package_name, p.version, p.description])
- end
- return pkg_all_list.sort
- end
-
- private
- def get_build_dependency_arr(pkg_name, os, n)
- pkg_hash = @pkg_hash_os[os]
- pkg = pkg_hash[pkg_name]
-
- if pkg.nil? then
- @log.error "\"#{pkg_name}\" package does not exist in server. please check it"
- return
- end
-
- # if package is already installed, skip tracing dependency
- if check_installed_pkg(pkg_name) then
- # compare version with installed package version
- new_pkg_ver = get_attr_from_pkg(pkg_name, os, "version")
- compare_result = compare_version_with_installed_pkg(pkg_name, new_pkg_ver)
- if compare_result == -1 or compare_result == 0 then return end
- end
-
- pkg.build_dep_list.each do |l|
- @all_dep_list.push([n, l])
- get_build_dependency_arr(l.package_name, os, n+1)
- end
-
- return
- end
-
- private
- def get_install_dependency_arr(pkg_name, os, force, n)
-
- pkg_hash = @pkg_hash_os[os]
- pkg = pkg_hash[pkg_name]
-
- if pkg.nil? then
- @log.error "\"#{pkg_name}\" package does not exist in server. please check it"
- return
- end
-
- # if package is already installed, skip tracing dependency
- if check_installed_pkg(pkg_name) then
- # compare version with installed package version
- new_pkg_ver = get_attr_from_pkg(pkg_name, os, "version")
- compare_result = compare_version_with_installed_pkg(pkg_name, new_pkg_ver)
- if not force then
- if compare_result == -1 or compare_result == 0 then return end
- end
- end
-
- pkg.install_dep_list.each do |l|
- @all_dep_list.push([n, l])
- get_install_dependency_arr(l.package_name, os, force, n+1)
- end
-
- return
- end
-
- private
- def get_all_reverse_install_dependency_arr(pkg_name, n)
-
- s = "#{n}:#{pkg_name}"
- installed_pkg_hash_key = get_installed_pkg_list_file_path()
- pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
- pkg_list = pkg_hash.values
- pkg_list.each do |pkg|
- pkg.install_dep_list.each do |l|
- if l.package_name.eql? pkg_name then
- s = s + "::" + get_all_reverse_install_dependency_arr(pkg.package_name, n+1)
- end
- end
- end
-
- return s
- end
-
- private
- def get_all_reverse_install_dependency_arr_remote(pkg_name, os, n)
-
- s = "#{n}:#{pkg_name}"
- pkg_hash = @pkg_hash_os[os]
- pkg_list = pkg_hash.values
- pkg_list.each do |pkg|
- pkg.install_dep_list.each do |l|
- if l.package_name.eql? pkg_name then
- s = s + "::" + get_all_reverse_install_dependency_arr_remote(pkg.package_name, os, n+1)
- end
- end
- end
-
- return s
- end
-
- public
- def get_pkg_from_list(pkg_name, os)
-
- pkg_hash = @pkg_hash_os[os]
- if pkg_hash.nil? then return nil end
-
- pkg = pkg_hash[pkg_name]
-
- return pkg
- end
-
- private
- def get_installed_pkg_from_list(pkg_name)
-
- installed_pkg_hash_key = get_installed_pkg_list_file_path()
- pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
- pkg = pkg_hash[pkg_name]
- if pkg.nil? then return nil end
-
- return pkg
- end
-
- private
- # install a package to @location after uninstalling and downloading
- def install_pkg(pkg_name, os, force)
-
- new_pkg_ver = ""
-
- # install remote server package file
- if not check_remote_pkg(pkg_name, os) then
- @log.error "\"#{pkg_name}\" package does not exist in remote server"
- return false
- end
- path = get_attr_from_pkg(pkg_name, os, "path")
- # type should be binary. type = "binary"
- # below code should be changed
- type = path.split('/')[-2]
- new_pkg_ver = get_attr_from_pkg(pkg_name, os, "version")
+ end
+ end
+
+ public
+ # show a package information
+ def show_pkg_info(pkg_name, os)
+ if not check_remote_pkg(pkg_name, os) then
+ @log.error "\"#{pkg_name}\" package does not exist"
+ return ""
+ end
+
+ pkg = get_pkg_from_list(pkg_name, os)
+ return pkg.to_s
+ end
+
+ public
+ # show all packages information
+ def show_pkg_list(os)
+ pkg_hash = @pkg_hash_os[os]
+ if pkg_hash.nil? then
+ @log.error "\"#{os}\" package list does not exist"
+ return ""
+ end
+
+ pkg_all_list = []
+ pkg_list = pkg_hash.values
+ pkg_list.each do |p|
+ pkg_all_list.push([p.package_name, p.version, p.description])
+ end
+ return pkg_all_list.sort
+ end
+
+ public
+ # show installed package information
+ def show_installed_pkg_info(pkg_name)
+
+ if not check_installed_pkg(pkg_name) then
+ @log.error "\"#{pkg_name}\" package does not exist"
+ return ""
+ end
+
+ pkg = get_installed_pkg_from_list(pkg_name)
+ return pkg.to_s
+ end
+
+ public
+ # show all installed packages information
+ def show_installed_pkg_list()
+
+ file_path = get_installed_pkg_list_file_path()
+ pkg_hash = @installed_pkg_hash_loc[file_path]
+ if pkg_hash.nil? then
+ @log.error "Installed package list does not exist"
+ return nil
+ end
+ pkg_all_list = []
+ pkg_list = pkg_hash.values
+ pkg_list.each do |p|
+ pkg_all_list.push([p.package_name, p.version, p.description])
+ end
+ return pkg_all_list.sort
+ end
+
+ private
+ def get_build_dependency_arr(pkg_name, os, n)
+ pkg_hash = @pkg_hash_os[os]
+ pkg = pkg_hash[pkg_name]
+
+ if pkg.nil? then
+ @log.error "\"#{pkg_name}\" package does not exist in server. please check it"
+ return
+ end
+
+ # if package is already installed, skip tracing dependency
+ if check_installed_pkg(pkg_name) then
+ # compare version with installed package version
+ new_pkg_ver = get_attr_from_pkg(pkg_name, os, "version")
+ compare_result = compare_version_with_installed_pkg(pkg_name, new_pkg_ver)
+ if compare_result == -1 or compare_result == 0 then return end
+ end
+
+ pkg.build_dep_list.each do |l|
+ @all_dep_list.push([n, l])
+ get_build_dependency_arr(l.package_name, os, n+1)
+ end
+
+ return
+ end
+
+ private
+ def get_install_dependency_arr(pkg_name, os, force, n)
+
+ pkg_hash = @pkg_hash_os[os]
+ pkg = pkg_hash[pkg_name]
+
+ if pkg.nil? then
+ @log.error "\"#{pkg_name}\" package does not exist in server. please check it"
+ return
+ end
+
+ # if package is already installed, skip tracing dependency
+ if check_installed_pkg(pkg_name) then
+ # compare version with installed package version
+ new_pkg_ver = get_attr_from_pkg(pkg_name, os, "version")
+ compare_result = compare_version_with_installed_pkg(pkg_name, new_pkg_ver)
+ if not force then
+ if compare_result == -1 or compare_result == 0 then return end
+ end
+ end
+
+ pkg.install_dep_list.each do |l|
+ @all_dep_list.push([n, l])
+ get_install_dependency_arr(l.package_name, os, force, n+1)
+ end
+
+ return
+ end
+
+ private
+ def get_all_reverse_install_dependency_arr(pkg_name, n)
+
+ s = "#{n}:#{pkg_name}"
+ installed_pkg_hash_key = get_installed_pkg_list_file_path()
+ pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
+ pkg_list = pkg_hash.values
+ pkg_list.each do |pkg|
+ pkg.install_dep_list.each do |l|
+ if l.package_name.eql? pkg_name then
+ s = s + "::" + get_all_reverse_install_dependency_arr(pkg.package_name, n+1)
+ end
+ end
+ end
+
+ return s
+ end
+
+ private
+ def get_all_reverse_install_dependency_arr_remote(pkg_name, os, n)
+
+ s = "#{n}:#{pkg_name}"
+ pkg_hash = @pkg_hash_os[os]
+ pkg_list = pkg_hash.values
+ pkg_list.each do |pkg|
+ pkg.install_dep_list.each do |l|
+ if l.package_name.eql? pkg_name then
+ s = s + "::" + get_all_reverse_install_dependency_arr_remote(pkg.package_name, os, n+1)
+ end
+ end
+ end
+
+ return s
+ end
+
+ public
+ def get_pkg_from_list(pkg_name, os)
+
+ pkg_hash = @pkg_hash_os[os]
+ if pkg_hash.nil? then return nil end
+
+ pkg = pkg_hash[pkg_name]
+
+ return pkg
+ end
+
+ private
+ def get_installed_pkg_from_list(pkg_name)
+
+ installed_pkg_hash_key = get_installed_pkg_list_file_path()
+ pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
+ pkg = pkg_hash[pkg_name]
+ if pkg.nil? then return nil end
+
+ return pkg
+ end
+
+ private
+ # install a package to @location after uninstalling and downloading
+ def install_pkg(pkg_name, os, force)
+
+ new_pkg_ver = ""
+
+ # install remote server package file
+ if not check_remote_pkg(pkg_name, os) then
+ @log.error "\"#{pkg_name}\" package does not exist in remote server"
+ return false
+ end
+ path = get_attr_from_pkg(pkg_name, os, "path")
+ # type should be binary. type = "binary"
+ # below code should be changed
+ type = path.split('/')[-2]
+ new_pkg_ver = get_attr_from_pkg(pkg_name, os, "version")
pkg_checksum = get_attr_from_pkg(pkg_name, os, "checksum")
pkg_size = get_attr_from_pkg(pkg_name, os, "size")
pkg_path = get_attr_from_pkg(pkg_name, os, "path")
filename = pkg_path.split('/')[-1]
-
- # compare version with installed package versiona
- compare_result = compare_version_with_installed_pkg(pkg_name, new_pkg_ver)
- if not force then
- case compare_result
- when -1 then
- @log.warn "Checked \"#{pkg_name}\" package version : it is bigger then remote package version"
- return true
- when 0 then
- @log.warn "Checked \"#{pkg_name}\" package version : it is same with remote package version"
- return true
- end
- end
-
- # if package is already installed, then uninstall it
- if check_installed_pkg(pkg_name) then
- if not uninstall(pkg_name, false) then
- @log.error "Failed to uninstall \"#{pkg_name}\""
- return false
- end
- end
-
- # install package
+
+ # compare version with installed package versiona
+ compare_result = compare_version_with_installed_pkg(pkg_name, new_pkg_ver)
+ if not force then
+ case compare_result
+ when -1 then
+ @log.warn "Checked \"#{pkg_name}\" package version : it is bigger then remote package version"
+ return true
+ when 0 then
+ @log.warn "Checked \"#{pkg_name}\" package version : it is same with remote package version"
+ return true
+ end
+ end
+
+ # if package is already installed, then uninstall it
+ if check_installed_pkg(pkg_name) then
+ if not uninstall(pkg_name, false) then
+ @log.error "Failed to uninstall \"#{pkg_name}\""
+ return false
+ end
+ end
+
+ # install package
cached_filepath = nil
if Utils.is_linux_like_os( Utils::HOST_OS ) then
cached_filepath = get_cached_filepath(filename, pkg_checksum, pkg_size)
end
if not cached_filepath.nil? then
@log.info "Cached #{pkg_name} package file.. OK"
- ret = FileInstaller.install(pkg_name, cached_filepath, type, @location, @log)
+ ret = FileInstaller.install(pkg_name, cached_filepath, type, @location, @log)
else
filepath = download(pkg_name, os, false, @tmp_path)
if filepath.nil? then
if filepath.nil? then
return false
end
- ret = FileInstaller.install(pkg_name, filepath, type, @location, @log)
+ ret = FileInstaller.install(pkg_name, filepath, type, @location, @log)
remove_downloaded_pkgs(pkg_name, os)
end
- return ret
+ return ret
end
- private
+ private
def compare_version_with_installed_pkg(pkg_name, new_pkg_ver)
- if check_installed_pkg_list_file() then
- read_installed_pkg_list()
- if check_installed_pkg(pkg_name) then
- installed_pkg_ver = get_attr_from_installed_pkg(pkg_name, "version")
- compare_result = Utils.compare_version(installed_pkg_ver, new_pkg_ver)
- return compare_result
- end
- end
-
- return 2
- end
-
- private
- def remove_pkg_info(pkg_name)
-
- pkg_hash = {}
- installed_pkg_hash_key = get_installed_pkg_list_file_path()
- if @installed_pkg_hash_loc.has_key? installed_pkg_hash_key then
- pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
- if pkg_hash.include? pkg_name then
- pkg_hash.delete(pkg_name)
- end
- @installed_pkg_hash_loc[installed_pkg_hash_key] = pkg_hash
- else return nil end
-
- @log.info "Removed information for \"#{pkg_name}\" package.. OK"
- return pkg_hash
- end
-
- private
- def add_pkg_info(pkg_name, os)
-
- pkg_hash = {}
- installed_pkg_hash_key = get_installed_pkg_list_file_path()
- if @installed_pkg_hash_loc.has_key? installed_pkg_hash_key then
- pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
- pkg_hash[pkg_name] = get_pkg_from_list(pkg_name, os)
- else pkg_hash[pkg_name] = get_pkg_from_list(pkg_name, os) end
- @installed_pkg_hash_loc[installed_pkg_hash_key] = pkg_hash
-
- #@log.info "Added information for \"#{pkg_name}\" package.. OK"
- return pkg_hash
- end
-
- private
- # add package manifest info
- def add_local_pkg_info(pkg_name)
-
- config_path = File.join(@location, PACKAGE_INFO_DIR, "#{pkg_name}")
- pkg = read_pkginfo_file(pkg_name, config_path)
-
- if pkg.nil? then
- @log.error "Failed to read pkginfo.manifest file"
- return nil
- end
-
- pkg_hash = {}
- installed_pkg_hash_key = get_installed_pkg_list_file_path()
- if @installed_pkg_hash_loc.has_key? installed_pkg_hash_key then
- pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
- pkg_hash[pkg_name] = pkg
- else pkg_hash[pkg_name] = pkg end
- @installed_pkg_hash_loc[installed_pkg_hash_key] = pkg_hash
-
- #@log.info "Added information for \"#{pkg_name}\" package.. OK"
- return pkg_hash
- end
-
- private
- # read package manifet info
- def read_pkginfo_file(pkg_name, path)
-
- file_path = File.join(path, "pkginfo.manifest")
+ if check_installed_pkg_list_file() then
+ read_installed_pkg_list()
+ if check_installed_pkg(pkg_name) then
+ installed_pkg_ver = get_attr_from_installed_pkg(pkg_name, "version")
+ compare_result = Utils.compare_version(installed_pkg_ver, new_pkg_ver)
+ return compare_result
+ end
+ end
+
+ return 2
+ end
+
+ private
+ def remove_pkg_info(pkg_name)
+
+ pkg_hash = {}
+ installed_pkg_hash_key = get_installed_pkg_list_file_path()
+ if @installed_pkg_hash_loc.has_key? installed_pkg_hash_key then
+ pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
+ if pkg_hash.include? pkg_name then
+ pkg_hash.delete(pkg_name)
+ end
+ @installed_pkg_hash_loc[installed_pkg_hash_key] = pkg_hash
+ else return nil end
+
+ @log.info "Removed information for \"#{pkg_name}\" package.. OK"
+ return pkg_hash
+ end
+
+ private
+ def add_pkg_info(pkg_name, os)
+
+ pkg_hash = {}
+ installed_pkg_hash_key = get_installed_pkg_list_file_path()
+ if @installed_pkg_hash_loc.has_key? installed_pkg_hash_key then
+ pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
+ pkg_hash[pkg_name] = get_pkg_from_list(pkg_name, os)
+ else pkg_hash[pkg_name] = get_pkg_from_list(pkg_name, os) end
+ @installed_pkg_hash_loc[installed_pkg_hash_key] = pkg_hash
+
+ #@log.info "Added information for \"#{pkg_name}\" package.. OK"
+ return pkg_hash
+ end
+
+ private
+ # add package manifest info
+ def add_local_pkg_info(pkg_name)
+
+ config_path = File.join(@location, PACKAGE_INFO_DIR, "#{pkg_name}")
+ pkg = read_pkginfo_file(pkg_name, config_path)
+
+ if pkg.nil? then
+ @log.error "Failed to read pkginfo.manifest file"
+ return nil
+ end
+
+ pkg_hash = {}
+ installed_pkg_hash_key = get_installed_pkg_list_file_path()
+ if @installed_pkg_hash_loc.has_key? installed_pkg_hash_key then
+ pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
+ pkg_hash[pkg_name] = pkg
+ else pkg_hash[pkg_name] = pkg end
+ @installed_pkg_hash_loc[installed_pkg_hash_key] = pkg_hash
+
+ #@log.info "Added information for \"#{pkg_name}\" package.. OK"
+ return pkg_hash
+ end
+
+ private
+ # read package manifet info
+ def read_pkginfo_file(pkg_name, path)
+
+ file_path = File.join(path, "pkginfo.manifest")
begin
pkg = Parser.read_single_pkginfo_from file_path
rescue => e
return nil
end
- if pkg.nil? then
- @log.error "Failed to read manifest file : #{file_path}"
- return nil
- end
+ if pkg.nil? then
+ @log.error "Failed to read manifest file : #{file_path}"
+ return nil
+ end
- @log.info "Read information for \"#{pkg_name}\" package.. OK"
- return pkg
- end
+ @log.info "Read information for \"#{pkg_name}\" package.. OK"
+ return pkg
+ end
- # get the lastest snapshot
- # from_server : if true, update from server
+ # get the lastest snapshot
+ # from_server : if true, update from server
def get_lastest_snapshot(from_server)
ssinfo_file = "snapshot.info"
file_url = File.join(@server_addr, ssinfo_file)
if from_server then
if not FileDownLoader.download(file_url, @config_dist_path, @log) then
- @log.warn "Server does not have \"#{ssinfo_file}\" file. This error can be ignored."
+ @log.warn "Server does not have \"#{ssinfo_file}\" file. This error can be ignored."
end
else
if File.exist? file_url then FileUtils.cp(file_url, @config_dist_path)
else @log.warn "Server does not have \"#{ssinfo_file}\" file. This error can be ignored." end
end
-
+
file_path = File.join(@config_dist_path, ssinfo_file)
if not File.exist? file_path then return nil end
# if url includes snapshot infomation, retuen true
def is_snapshot_url(addr = nil)
if addr.nil? then addr = @server_addr end
- addr_arr = addr.split('/')
- if addr_arr[-2].eql? "snapshots" then
+ addr_arr = addr.split('/')
+ if addr_arr[-2].eql? "snapshots" then
return true
- else
+ else
return false
- end
+ end
end
def split_addr_and_snapshot(addr = nil)
if addr.nil? then addr = @server_addr end
- addr_arr = addr.split('/')
- if addr_arr[-2].eql? "snapshots" then
+ addr_arr = addr.split('/')
+ if addr_arr[-2].eql? "snapshots" then
return addr_arr[0..-3].join("/"), addr_arr[-2..-1].join("/")
- else
+ else
return nil
- end
+ end
end
def is_snapshot_exist(ss_path = nil)
end
def read_remote_pkg_list(list_path)
- @support_os_list.each do |os|
+ @support_os_list.each do |os|
filename = PKG_LIST_FILE_PREFIX + os
local_file_path = File.join(list_path, filename)
- if File.exist? local_file_path then
+ if File.exist? local_file_path then
begin
pkg_hash = Parser.read_repo_pkg_list_from local_file_path
@pkg_hash_os[os] = pkg_hash
def read_supported_os_list(list_path)
local_file_path = File.join(list_path, OS_INFO_FILE)
if File.exist? local_file_path then
- File.open(local_file_path, "r") do |f|
- f.each_line do |l|
+ File.open(local_file_path, "r") do |f|
+ f.each_line do |l|
os = l.strip
if @support_os_list.index(os).nil? then @support_os_list.push(os) end
- end
+ end
end
@log.info "Get supported os infomation.. OK"
else
@log.warn "Failed to get supported os infomation"
- end
+ end
end
def download_os_list(from_server, dist = nil)
if dist.nil? then dist = get_pkglist_path end
- file_url = File.join(@server_addr, OS_INFO_FILE)
- if from_server then
- if not FileDownLoader.download(file_url, dist, @log) then return false end
+ file_url = File.join(@server_addr, OS_INFO_FILE)
+ if from_server then
+ if not FileDownLoader.download(file_url, dist, @log) then return false end
else
if File.exist? file_url then FileUtils.cp(file_url, dist)
else return false end
end
def read_archive_pkg_list(list_path)
- local_file_path = File.join(list_path, ARCHIVE_PKG_LIST_FILE)
- if File.exist? local_file_path then
- File.open(local_file_path, "r") do |f|
- f.each_line do |l|
+ local_file_path = File.join(list_path, ARCHIVE_PKG_LIST_FILE)
+ if File.exist? local_file_path then
+ File.open(local_file_path, "r") do |f|
+ f.each_line do |l|
pkg = l.strip
if @archive_pkg_list.index(pkg).nil? then @archive_pkg_list.push(pkg) end
- end
+ end
end
@log.info "Get archive package infomation.. OK"
else
@log.warn "Failed to get archive package infomation"
- end
+ end
end
def download_archive_pkg_list(from_server, dist = nil)
if dist.nil? then dist = get_pkglist_path end
- file_url = File.join(@server_addr, @snapshot_path, ARCHIVE_PKG_LIST_FILE)
- if from_server then
+ file_url = File.join(@server_addr, @snapshot_path, ARCHIVE_PKG_LIST_FILE)
+ if from_server then
if not FileDownLoader.download(file_url, dist, @log) then return false end
else
if File.exist? file_url then FileUtils.cp(file_url, dist)
# create installed package hash
def read_installed_pkg_list()
- config_path = File.join(@location, PACKAGE_INFO_DIR)
- if not File.directory? config_path then return end
-
- installed_pkg_hash_key = get_installed_pkg_list_file_path()
- if @installed_pkg_hash_loc.has_key? installed_pkg_hash_key then return
- else
- file_path = installed_pkg_hash_key
- if not File.exist? file_path then
- #raise RuntimeError, "#{file_path} file does not exist"
- return
- end
+ config_path = File.join(@location, PACKAGE_INFO_DIR)
+ if not File.directory? config_path then return end
+
+ installed_pkg_hash_key = get_installed_pkg_list_file_path()
+ if @installed_pkg_hash_loc.has_key? installed_pkg_hash_key then return
+ else
+ file_path = installed_pkg_hash_key
+ if not File.exist? file_path then
+ #raise RuntimeError, "#{file_path} file does not exist"
+ return
+ end
begin
pkg_hash = Parser.read_repo_pkg_list_from file_path
rescue => e
end
end
- private
- # check to exist installed package list file
- def check_installed_pkg_list_file()
-
- if @location.nil? then raise RuntimeError, "#{@location} path does not exist" end
- file_path = get_installed_pkg_list_file_path()
- if File.exist? file_path then return true
- else return false end
- end
-
- private
- # get installed package list file path
- def get_installed_pkg_list_file_path()
-
- file_full_path = File.join(@location, PACKAGE_INFO_DIR, INSTALLED_PKG_LIST_FILE)
- return file_full_path
- end
-
- private
- # write package hash to file
- def write_pkg_hash_to_file(pkg_hash)
-
- file_path = get_installed_pkg_list_file_path()
- if pkg_hash.nil? then
- pkg_hash = @installed_pkg_hash_loc[file_path]
- end
- if not pkg_hash.nil? then
- config_path = File.join(@location, PACKAGE_INFO_DIR)
- if not File.exist? config_path then FileUtils.mkdir_p "#{config_path}" end
- if File.exist? file_path then File.delete(file_path) end
- File.open(file_path, "a+") do |file|
- pkg_list = pkg_hash.values
- pkg_list.each do |pkg|
- pkg.print_to_file(file)
- file.puts "\n"
- end
- end
- end
- @log.info "Write package informations to \"#{file_path}\".. OK"
- end
-
- private
- def check_meta_pkg(pkg_name, os)
- if not check_remote_pkg(pkg_name, os) then return false end
-
- attr = get_attr_from_pkg(pkg_name, os, "attribute")
- if attr.nil? or attr.empty? then return false end
- if attr[0].strip.upcase.eql? "META" then return true
- else return false end
- end
+ private
+ # check to exist installed package list file
+ def check_installed_pkg_list_file()
+
+ if @location.nil? then raise RuntimeError, "#{@location} path does not exist" end
+ file_path = get_installed_pkg_list_file_path()
+ if File.exist? file_path then return true
+ else return false end
+ end
+
+ private
+ # get installed package list file path
+ def get_installed_pkg_list_file_path()
+
+ file_full_path = File.join(@location, PACKAGE_INFO_DIR, INSTALLED_PKG_LIST_FILE)
+ return file_full_path
+ end
+
+ private
+ # write package hash to file
+ def write_pkg_hash_to_file(pkg_hash)
+
+ file_path = get_installed_pkg_list_file_path()
+ if pkg_hash.nil? then
+ pkg_hash = @installed_pkg_hash_loc[file_path]
+ end
+ if not pkg_hash.nil? then
+ config_path = File.join(@location, PACKAGE_INFO_DIR)
+ if not File.exist? config_path then FileUtils.mkdir_p "#{config_path}" end
+ if File.exist? file_path then File.delete(file_path) end
+ File.open(file_path, "a+") do |file|
+ pkg_list = pkg_hash.values
+ pkg_list.each do |pkg|
+ pkg.print_to_file(file)
+ file.puts "\n"
+ end
+ end
+ end
+ @log.info "Write package informations to \"#{file_path}\".. OK"
+ end
+
+ private
+ def check_meta_pkg(pkg_name, os)
+ if not check_remote_pkg(pkg_name, os) then return false end
+
+ attr = get_attr_from_pkg(pkg_name, os, "attribute")
+ if attr.nil? or attr.empty? then return false end
+ if attr[0].strip.upcase.eql? "META" then return true
+ else return false end
+ end
end
=begin
-
+
clientOptParser.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
case options[:cmd]
- when "update" then
+ when "update" then
- when "clean" then
+ when "clean" then
- when "upgrade" then
+ when "upgrade" then
- when "check-upgrade" then
+ when "check-upgrade" then
- when "download" then
- if options[:pkg].nil? or options[:pkg].empty? then
- raise ArgumentError, "Usage: pkg-cli download -P <package name> [-o <os>] [-l <location>] [-u <package server url>] [--trace]"
- end
+ when "download" then
+ if options[:pkg].nil? or options[:pkg].empty? then
+ raise ArgumentError, "Usage: pkg-cli download -P <package name> [-o <os>] [-l <location>] [-u <package server url>] [--trace]"
+ end
- when "install" then
- if options[:pkg].nil? or options[:pkg].empty? then
- raise ArgumentError, "Usage: pkg-cli install -P <package name> [-o <os>] [-l <location>] [-u <package server url>] [--trace] [--force]"
- end
+ when "install" then
+ if options[:pkg].nil? or options[:pkg].empty? then
+ raise ArgumentError, "Usage: pkg-cli install -P <package name> [-o <os>] [-l <location>] [-u <package server url>] [--trace] [--force]"
+ end
- when "install-file" then
- if options[:pkg].nil? or options[:pkg].empty? then
- raise ArgumentError, "Usage: pkg-cli install-lpkg -P <package file> [-l <location>] [-u <package server url>] [--trace] [--force]"
- end
+ when "install-file" then
+ if options[:pkg].nil? or options[:pkg].empty? then
+ raise ArgumentError, "Usage: pkg-cli install-lpkg -P <package file> [-l <location>] [-u <package server url>] [--trace] [--force]"
+ end
- when "uninstall" then
- if options[:pkg].nil? or options[:pkg].empty? then
- raise ArgumentError, "Usage: pkg-cli uninstall -P <package name> [-l <location>] [--trace]"
- end
+ when "uninstall" then
+ if options[:pkg].nil? or options[:pkg].empty? then
+ raise ArgumentError, "Usage: pkg-cli uninstall -P <package name> [-l <location>] [--trace]"
+ end
- when "show-rpkg" then
- if options[:pkg].nil? or options[:pkg].empty? then
- raise ArgumentError, "Usage: pkg-cli show-rpkg -P <package name> [-o <os>] [-u <package server url>]"
- end
+ when "show-rpkg" then
+ if options[:pkg].nil? or options[:pkg].empty? then
+ raise ArgumentError, "Usage: pkg-cli show-rpkg -P <package name> [-o <os>] [-u <package server url>]"
+ end
- when "list-rpkg" then
+ when "list-rpkg" then
- when "show-lpkg" then
- if options[:pkg].nil? or options[:pkg].empty? then
- raise ArgumentError, "Usage: pkg-cli show-lpkg -P <package name> [-l <location>]"
- end
+ when "show-lpkg" then
+ if options[:pkg].nil? or options[:pkg].empty? then
+ raise ArgumentError, "Usage: pkg-cli show-lpkg -P <package name> [-l <location>]"
+ end
- when "list-lpkg" then
+ when "list-lpkg" then
- when "build-dep" then
- if options[:pkg].nil? or options[:pkg].empty? then
- raise ArgumentError, "Usage: pkg-cli build-dep -P <package name> [-o <os>]"
- end
+ when "build-dep" then
+ if options[:pkg].nil? or options[:pkg].empty? then
+ raise ArgumentError, "Usage: pkg-cli build-dep -P <package name> [-o <os>]"
+ end
- when "install-dep" then
- if options[:pkg].nil? or options[:pkg].empty? then
- raise ArgumentError, "Usage: pkg-cli install-dep -P <package name> [-o <os>]"
- end
+ when "install-dep" then
+ if options[:pkg].nil? or options[:pkg].empty? then
+ raise ArgumentError, "Usage: pkg-cli install-dep -P <package name> [-o <os>]"
+ end
else
raise ArgumentError, "Input is incorrect : #{options[:cmd]}"
end
def option_parse
- options = {}
- banner = "Requiest service to package-server and control packages service command-line tool." + "\n" \
- + "\n" + "Usage: pkg-cli <SUBCOMMAND> [OPTS] or pkg-cli (-h|-v)" + "\n" \
- + "\n" + "Subcommands:" + "\n" \
- + "\t" + "update Update to the latest package in your SDK environment." + "\n" \
- + "\t" + "clean Delete the package in your SDK environment." + "\n" \
- + "\t" + "download Download the package in your SDK environment." + "\n" \
- + "\t" + "install Download the package from package-server and install the package in your SDK environment." + "\n" \
- + "\t" + "install-file Install the package in your SDK environment." + "\n" \
- + "\t" + "uninstall Uninstall the package in your SDK environment." + "\n" \
- + "\t" + "upgrade Upgrade your SDK environment." + "\n" \
- + "\t" + "check-upgrade Check packages to upgrade." + "\n" \
- + "\t" + "show-rpkg Show the package in the package-server." + "\n" \
- + "\t" + "list-rpkg Show the all packages in the package-server." + "\n" \
- + "\t" + "show-lpkg Show the package in your SDK environment." + "\n" \
- + "\t" + "list-lpkg Show the all packages in your SDK environment." + "\n" \
- + "\t" + "build-dep Show build-dependency packages" + "\n" \
- + "\t" + "install-dep Show install-dependency packages" + "\n" \
- + "\n" + "Subcommand usage:" + "\n" \
- + "\t" + "pkg-cli update [-u <remote server url>]" + "\n" \
- + "\t" + "pkg-cli clean [-l <location>] [--force]" + "\n" \
- + "\t" + "pkg-cli download -P <package name> [-o <os>] [-l <location>] [-u <package server url>] [--trace]" + "\n" \
- + "\t" + "pkg-cli install -P <package name> [-o <os>] [-l <location>] [-u <package server url>] [--trace] [--force]" + "\n" \
- + "\t" + "pkg-cli install-file -P <package file> [-l <location>] [-u <package server url>] [--trace] [--force]" + "\n" \
- + "\t" + "pkg-cli uninstall -P <package name> [-l <location>] [--trace]" + "\n" \
- + "\t" + "pkg-cli upgrade [-l <location>] [-o <os>] [-u <package server url>] [--trace]" + "\n" \
- + "\t" + "pkg-cli check-upgrade [-l <location>] [-o <os>] [-u <package server url>]" + "\n" \
- + "\t" + "pkg-cli show-rpkg -P <package name> [-o <os>] [-u <package server url>]" + "\n" \
- + "\t" + "pkg-cli list-rpkg [-o <os>] [-u <package server url>]" + "\n" \
- + "\t" + "pkg-cli show-lpkg -P <package name> [-l <location>]" + "\n" \
- + "\t" + "pkg-cli list-lpkg [-l <location>]" + "\n" \
- + "\t" + "pkg-cli build-dep -P <package name> [-o <os>]" + "\n" \
- + "\t" + "pkg-cli install-dep -P <package name> [-o <os>]" + "\n" \
- + "\n" + "Options:" + "\n"
-
- optparse = OptionParser.new(nil, 32, ' '*8) do|opts|
- # Set a banner, displayed at the top
- # of the help screen.
-
- opts.banner = banner
-
- opts.on( '-P', '--pkg <package name/file>', 'package name or package file name' ) do |name|
- options[:pkg] = name
- end
-
- opts.on( '-o', '--os <operating system>', 'target operating system: ubuntu-32/ubuntu-64/windows-32/windows-64/macos-64' ) do |os|
- options[:os] = os
- end
-
- opts.on( '-u', '--url <server url>', 'package server url: http://127.0.0.1/dibs/unstable' ) do |url|
- options[:url] = url
- end
-
- opts.on( '-l', '--loc <location>', 'install/download location' ) do |loc|
- options[:loc] = loc
- end
-
- opts.on( '--trace', 'enable trace dependent packages' ) do
- options[:t] = true
- end
-
- opts.on( '--force', 'enable force' ) do
- options[:f] = true
- end
-
- opts.on( '-h', '--help', 'display help' ) do
- puts opts
- exit
- end
+ options = {}
+ banner = "Requiest service to package-server and control packages service command-line tool." + "\n" \
+ + "\n" + "Usage: pkg-cli <SUBCOMMAND> [OPTS] or pkg-cli (-h|-v)" + "\n" \
+ + "\n" + "Subcommands:" + "\n" \
+ + "\t" + "update Update to the latest package in your SDK environment." + "\n" \
+ + "\t" + "clean Delete the package in your SDK environment." + "\n" \
+ + "\t" + "download Download the package in your SDK environment." + "\n" \
+ + "\t" + "install Download the package from package-server and install the package in your SDK environment." + "\n" \
+ + "\t" + "install-file Install the package in your SDK environment." + "\n" \
+ + "\t" + "uninstall Uninstall the package in your SDK environment." + "\n" \
+ + "\t" + "upgrade Upgrade your SDK environment." + "\n" \
+ + "\t" + "check-upgrade Check packages to upgrade." + "\n" \
+ + "\t" + "show-rpkg Show the package in the package-server." + "\n" \
+ + "\t" + "list-rpkg Show the all packages in the package-server." + "\n" \
+ + "\t" + "show-lpkg Show the package in your SDK environment." + "\n" \
+ + "\t" + "list-lpkg Show the all packages in your SDK environment." + "\n" \
+ + "\t" + "build-dep Show build-dependency packages" + "\n" \
+ + "\t" + "install-dep Show install-dependency packages" + "\n" \
+ + "\n" + "Subcommand usage:" + "\n" \
+ + "\t" + "pkg-cli update [-u <remote server url>]" + "\n" \
+ + "\t" + "pkg-cli clean [-l <location>] [--force]" + "\n" \
+ + "\t" + "pkg-cli download -P <package name> [-o <os>] [-l <location>] [-u <package server url>] [--trace]" + "\n" \
+ + "\t" + "pkg-cli install -P <package name> [-o <os>] [-l <location>] [-u <package server url>] [--trace] [--force]" + "\n" \
+ + "\t" + "pkg-cli install-file -P <package file> [-l <location>] [-u <package server url>] [--trace] [--force]" + "\n" \
+ + "\t" + "pkg-cli uninstall -P <package name> [-l <location>] [--trace]" + "\n" \
+ + "\t" + "pkg-cli upgrade [-l <location>] [-o <os>] [-u <package server url>] [--trace]" + "\n" \
+ + "\t" + "pkg-cli check-upgrade [-l <location>] [-o <os>] [-u <package server url>]" + "\n" \
+ + "\t" + "pkg-cli show-rpkg -P <package name> [-o <os>] [-u <package server url>]" + "\n" \
+ + "\t" + "pkg-cli list-rpkg [-o <os>] [-u <package server url>]" + "\n" \
+ + "\t" + "pkg-cli show-lpkg -P <package name> [-l <location>]" + "\n" \
+ + "\t" + "pkg-cli list-lpkg [-l <location>]" + "\n" \
+ + "\t" + "pkg-cli build-dep -P <package name> [-o <os>]" + "\n" \
+ + "\t" + "pkg-cli install-dep -P <package name> [-o <os>]" + "\n" \
+ + "\n" + "Options:" + "\n"
+
+ optparse = OptionParser.new(nil, 32, ' '*8) do|opts|
+ # Set a banner, displayed at the top
+ # of the help screen.
+
+ opts.banner = banner
+
+ opts.on( '-P', '--pkg <package name/file>', 'package name or package file name' ) do |name|
+ options[:pkg] = name
+ end
+
+ opts.on( '-o', '--os <operating system>', 'target operating system: ubuntu-32/ubuntu-64/windows-32/windows-64/macos-64' ) do |os|
+ options[:os] = os
+ end
+
+ opts.on( '-u', '--url <server url>', 'package server url: http://127.0.0.1/dibs/unstable' ) do |url|
+ options[:url] = url
+ end
+
+ opts.on( '-l', '--loc <location>', 'install/download location' ) do |loc|
+ options[:loc] = loc
+ end
+
+ opts.on( '--trace', 'enable trace dependent packages' ) do
+ options[:t] = true
+ end
+
+ opts.on( '--force', 'enable force' ) do
+ options[:f] = true
+ end
+
+ opts.on( '-h', '--help', 'display help' ) do
+ puts opts
+ exit
+ end
opts.on( '-v', '--version', 'display version' ) do
- puts "DIBS(Distributed Intelligent Build System) version " + Utils.get_version()
+ puts "DIBS(Distributed Intelligent Build System) version " + Utils.get_version()
exit
- end
- end
-
- cmd = ARGV[0]
- if cmd.eql? "update" or cmd.eql? "download" or
- cmd.eql? "install" or cmd.eql? "show-rpkg" or
- cmd.eql? "list-rpkg" or
- cmd.eql? "uninstall" or cmd.eql? "show-lpkg" or
- cmd.eql? "list-lpkg" or
- cmd.eql? "install-file" or cmd.eql? "clean" or
- cmd.eql? "upgrade" or cmd.eql? "check-upgrade" or
- cmd.eql? "build-dep" or cmd.eql? "install-dep" or
- cmd =~ /(-v)|(--version)/ or
- cmd =~ /(help)|(-h)|(--help)/ then
-
- if cmd.eql? "help" then
- V[0] = "-h"
- end
- options[:cmd] = ARGV[0]
- else
- raise ArgumentError, "Usage: pkg-cli <SUBCOMMAND> [OPTS] or pkg-cli -h"
- end
-
- optparse.parse!
+ end
+ end
+
+ cmd = ARGV[0]
+ if cmd.eql? "update" or cmd.eql? "download" or
+ cmd.eql? "install" or cmd.eql? "show-rpkg" or
+ cmd.eql? "list-rpkg" or
+ cmd.eql? "uninstall" or cmd.eql? "show-lpkg" or
+ cmd.eql? "list-lpkg" or
+ cmd.eql? "install-file" or cmd.eql? "clean" or
+ cmd.eql? "upgrade" or cmd.eql? "check-upgrade" or
+ cmd.eql? "build-dep" or cmd.eql? "install-dep" or
+ cmd =~ /(-v)|(--version)/ or
+ cmd =~ /(help)|(-h)|(--help)/ then
+
+ if cmd.eql? "help" then
+ V[0] = "-h"
+ end
+ options[:cmd] = ARGV[0]
+ else
+ raise ArgumentError, "Usage: pkg-cli <SUBCOMMAND> [OPTS] or pkg-cli -h"
+ end
+
+ optparse.parse!
set_default options
# option error check
option_error_check options
- return options
+ return options
end
class Distribution
attr_accessor :name, :location, :server_url, :lock_file_path, :last_sync_changes
- # constant
- PKG_LIST_FILE_PREFIX = "pkg_list_"
+ # constant
+ PKG_LIST_FILE_PREFIX = "pkg_list_"
ARCHIVE_PKG_FILE = "archive_pkg_list"
OS_INFO_FILE = "os_info"
SNAPSHOT_INFO_FILE = "snapshot.info"
end
exist_pkg = @pkg_hash_os[pkg.os][pkg.package_name]
-
+
# version check and if existing version is higher then upload version?
if (not exist_pkg.nil?) and (not internal_flag) then
if not ( Utils.compare_version( exist_pkg.version, pkg.version ) == 1 ) then
# modified pkg class
pkg.origin = "local"
- pkg.source = ""
+ pkg.source = ""
pkg.path = "/binary/" + File.basename( file_path )
if pkg.checksum.empty? then
# TODO: windows and mac : sha256sum
end
@pkg_hash_os[pkg.os][pkg.package_name] = pkg
-
+
return pkg
end
# modified pkg class
pkg.origin = "local"
- pkg.source = ""
+ pkg.source = ""
pkg.path = "/temp/" + File.basename( file_path )
# TODO: windows and mac : sha256sum
if Utils.is_unix_like_os( Utils::HOST_OS ) then
end
# copy package list
- @support_os_list.each do |os|
+ @support_os_list.each do |os|
FileUtils.copy_file( "#{snapshot_path}/#{PKG_LIST_FILE_PREFIX}#{os}",
- "#{@location}/snapshots/#{name}/#{PKG_LIST_FILE_PREFIX}#{os}" )
+ "#{@location}/snapshots/#{name}/#{PKG_LIST_FILE_PREFIX}#{os}" )
end
-
+
# copy archive package list
FileUtils.copy_file( "#{snapshot_path}/#{ARCHIVE_PKG_FILE}",
- "#{@location}/snapshots/#{name}/#{ARCHIVE_PKG_FILE}" )
-
- # copy os info file
- FileUtils.copy_file( "#{snapshot_path}/#{OS_INFO_FILE}",
- "#{@location}/snapshots/#{name}/#{OS_INFO_FILE}" )
-
- # generate temp file
- tmp_file_name = ""
- while ( tmp_file_name.empty? )
- tmp_file_name = @location + "/temp/." + Utils.create_uniq_name
-
- if File.exist? tmp_file_name then
- tmp_file_name = ""
- end
- end
-
- FileUtils.copy_file( "#{@location}/#{SNAPSHOT_INFO_FILE}", tmp_file_name )
- File.open( tmp_file_name, "a" ) do |f|
- f.puts "name : #{name}"
- f.puts "time : #{Time.now.strftime("%Y%m%d%H%M%S")}"
- if from_cmd then
- f.puts "type : manual"
- else
- f.puts "type : auto"
- end
- f.puts "path : /snapshots/#{name}"
- f.puts
- end
- FileUtils.mv( tmp_file_name, "#{@location}/#{SNAPSHOT_INFO_FILE}", :force => true )
-
- # snapshot is generated
- @log.output( "snapshot is generated : #{@location}/snapshots/#{name}", Log::LV_USER)
- return name
+ "#{@location}/snapshots/#{name}/#{ARCHIVE_PKG_FILE}" )
+
+ # copy os info file
+ FileUtils.copy_file( "#{snapshot_path}/#{OS_INFO_FILE}",
+ "#{@location}/snapshots/#{name}/#{OS_INFO_FILE}" )
+
+ # generate temp file
+ tmp_file_name = ""
+ while ( tmp_file_name.empty? )
+ tmp_file_name = @location + "/temp/." + Utils.create_uniq_name
+
+ if File.exist? tmp_file_name then
+ tmp_file_name = ""
+ end
+ end
+
+ FileUtils.copy_file( "#{@location}/#{SNAPSHOT_INFO_FILE}", tmp_file_name )
+ File.open( tmp_file_name, "a" ) do |f|
+ f.puts "name : #{name}"
+ f.puts "time : #{Time.now.strftime("%Y%m%d%H%M%S")}"
+ if from_cmd then
+ f.puts "type : manual"
+ else
+ f.puts "type : auto"
+ end
+ f.puts "path : /snapshots/#{name}"
+ f.puts
+ end
+ FileUtils.mv( tmp_file_name, "#{@location}/#{SNAPSHOT_INFO_FILE}", :force => true )
+
+ # snapshot is generated
+ @log.output( "snapshot is generated : #{@location}/snapshots/#{name}", Log::LV_USER)
+ return name
end
def sync(force, snapshot = "")
end
end
end
-
+
# sync archive package
update_archive_list = sync_archive_pkg()
used_archive_list = []
# collect remaining file's name from current package server version
- @support_os_list.each do |os|
+ @support_os_list.each do |os|
@pkg_hash_os[os].each_value{ |pkg|
file_list.push(pkg.path.sub("/binary/",""))
os_list.push l.strip
end
end
- # if snapshot does not have os_info file then using package server os_info list
+ # if snapshot does not have os_info file then using package server os_info list
else
os_list = @support_os_list
end
end
pkg_list = Parser.read_repo_pkg_list_from(info_file)
-
+
pkg_list.each_value{ |pkg|
file_list.push(pkg.path.sub("/binary/",""))
}
FileUtils.rm "#{@location}/source/#{file}"
end
end
-
+
# remove unused snapshot
Dir.new( @location + "/snapshots" ).each do |snapshot|
if snapshot.start_with? "." then next end
pkg_name_list.each do |package_name|
removed_flag = false
- os_list.each do |os|
+ os_list.each do |os|
if not @support_os_list.include? os then
@log.error( "package server does not support input os : #{os}")
next
end
end
end
-
+
# check install dependency integrity
if @integrity.eql? "YES" then
@log.info "integrity check"
if not removed_snapshot.empty? then
@log.output( "snapshot removed: #{removed_snapshot.join(",")}", Log::LV_USER )
end
-
+
update_snapshot_info_file(remain_snapshot)
end
else
raise RuntimeError,(error_msg + dep.to_s)
end
-
+
# check package's version
if not dep.match? target_pkg.version then
raise RuntimeError,(error_msg + dep.to_s)
else
raise RuntimeError,(error_msg + dep.to_s)
end
-
+
# check package's version
if not dep.match? target_pkg.version then
raise RuntimeError,(error_msg + dep.to_s)
end
end
-
+
error_msg = "[[#{pkg.package_name}] in #{pkg.os}]'s source dependency not matched in "
pkg.source_dep_list.each do |dep|
if not @archive_pkg_list.include? dep.package_name then
end
end
- def read_archive_pkg_list( snapshot_name )
- pkg_list = []
+ def read_archive_pkg_list( snapshot_name )
+ pkg_list = []
- if snapshot_name.empty?
- file_name = @location + "/" + ARCHIVE_PKG_FILE
- else
- file_name = @location + "/snapshots/" + snapshot_name + "/" + ARCHIVE_PKG_FILE
- end
+ if snapshot_name.empty?
+ file_name = @location + "/" + ARCHIVE_PKG_FILE
+ else
+ file_name = @location + "/snapshots/" + snapshot_name + "/" + ARCHIVE_PKG_FILE
+ end
- if File.exist? file_name
- File.open(file_name, "r") do |f|
- f.each_line do |l|
- pkg_list.push(l.strip)
- end
- end
- end
+ if File.exist? file_name
+ File.open(file_name, "r") do |f|
+ f.each_line do |l|
+ pkg_list.push(l.strip)
+ end
+ end
+ end
- return pkg_list
- end
+ return pkg_list
+ end
def write_archive_pkg_list()
- File.open( "#{@location}/#{ARCHIVE_PKG_FILE}", "w" ) do |f|
- @archive_pkg_list.each do |pkg|
- f.puts(pkg)
- end
- end
+ File.open( "#{@location}/#{ARCHIVE_PKG_FILE}", "w" ) do |f|
+ @archive_pkg_list.each do |pkg|
+ f.puts(pkg)
+ end
+ end
end
def initialize_pkg_list
@support_os_list = []
File.open( "#{@location}/#{OS_INFO_FILE}", "r" ) do |f|
f.each_line do |l|
- @support_os_list.push l.strip
- end
+ @support_os_list.push l.strip
+ end
end
# read package_list file
- @support_os_list.each do |os|
+ @support_os_list.each do |os|
@pkg_hash_os[os] = {}
pkg_list_file = "#{@location}/#{PKG_LIST_FILE_PREFIX}#{os}"
if pkg_os.eql? os then next end
# skip in unsupported os
if not @support_os_list.include? os then next end
-
+
exist_pkg = @pkg_hash_os[os][pkg.package_name]
if exist_pkg.nil? then next end
# local_pkg is generated from local and not force mode then skip update
return nil
end
-
+
pkg = sync_package2( server_pkg, client, os )
return ["ADD", os, pkg]
- # if package exist only server
+ # if package exist only server
elsif ( not server_pkg.nil? ) then
pkg = sync_package2( server_pkg, client, os )
return ["ADD", os, pkg]
- # if package exist only local
+ # if package exist only local
elsif ( not local_pkg.nil? ) then
# if local pkg is generated from local then skip
if local_pkg.origin.eql? "local" and (not force) then
return nil
end
-
+
# package remove
return ["REMOVE", os, local_pkg]
else
# package update
file_path_list = client.download( pkg_name, os, false )
-
+
# file download error check
if file_path_list.nil? or file_path_list.empty? then
@log.error("Can't download package file [#{pkg_name}]", Log::LV_USER)
else
file_path = file_path_list[0]
end
-
+
# update pkg class
pkg.path = "/binary/#{File.basename(file_path)}"
pkg.origin = client.server_addr
def get_all_reverse_depends_pkgs(pkg, checked_list)
depends_list = []
- @support_os_list.each do |os|
+ @support_os_list.each do |os|
@pkg_hash_os[os].each_value{ |dpkg|
if dpkg.install_dep_list.include? pkg or \
- dpkg.build_dep_list.include? pkg then
+ dpkg.build_dep_list.include? pkg then
depends_list.push opkg
end
@support_os_list = []
File.open( "#{@location}/#{OS_INFO_FILE}", "r" ) do |f|
f.each_line do |l|
- @support_os_list.push l.strip
- end
+ @support_os_list.push l.strip
+ end
end
# read binary package_list file
- @support_os_list.each do |os|
+ @support_os_list.each do |os|
@pkg_hash_os[os] = {}
pkg_list_file = "#{@location}/#{PKG_LIST_FILE_PREFIX}#{os}"
File.delete( "#{@location}/#{PKG_LIST_FILE_PREFIX}#{os}" )
end
- def sync_archive_pkg
- client = Client.new( @server_url, "#{@location}/source", @log )
+ def sync_archive_pkg
+ client = Client.new( @server_url, "#{@location}/source", @log )
- download_list = client.archive_pkg_list - @archive_pkg_list
+ download_list = client.archive_pkg_list - @archive_pkg_list
updated_file_list = []
# if update list is empty then return empty array
if download_list.empty? then return updated_file_list end
- download_list.each do |pkg|
+ download_list.each do |pkg|
file = client.download_dep_source(pkg)
- if file.nil?
- @log.error("Can't download archive package [#{pkg}]", Log::LV_USER)
+ if file.nil?
+ @log.error("Can't download archive package [#{pkg}]", Log::LV_USER)
else
updated_file_list.push pkg
- end
- end
+ end
+ end
return updated_file_list
- end
+ end
end
=begin
-
+
downloader.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
class FileDownLoader
- def FileDownLoader.download(url, path, logger)
- ret = false
+ def FileDownLoader.download(url, path, logger)
+ ret = false
- if not File.directory? path then
- logger.error "\"#{path}\" does not exist"
- return ret
+ if not File.directory? path then
+ logger.error "\"#{path}\" does not exist"
+ return ret
end
- is_remote = Utils.is_url_remote(url)
- filename = url.split('/')[-1]
- fullpath = File.join(path, filename)
+ is_remote = Utils.is_url_remote(url)
+ filename = url.split('/')[-1]
+ fullpath = File.join(path, filename)
logger.info "Downloading #{url}"
- if is_remote then
- pid,status = Utils.execute_shell_with_log( "wget #{url} -O #{fullpath} -nv --tries=3", logger.path )
+ if is_remote then
+ pid,status = Utils.execute_shell_with_log( "wget #{url} -O #{fullpath} -nv --tries=3", logger.path )
ret = (not status.nil? and status.exitstatus) != 0 ? false : true
- #ret = Utils.execute_shell( "wget #{url} -O #{fullpath} -q")
- else
- if not File.exist? url then
- logger.error "\"#{url}\" file does not exist"
- return false
- else
- ret = system "cp #{url} #{fullpath}"
- end
- end
+ #ret = Utils.execute_shell( "wget #{url} -O #{fullpath} -q")
+ else
+ if not File.exist? url then
+ logger.error "\"#{url}\" file does not exist"
+ return false
+ else
+ ret = system "cp #{url} #{fullpath}"
+ end
+ end
- # need verify
+ # need verify
if ret then
logger.info "Downloaded #{filename}.. OK"
else
logger.info "Failed to download #{filename}"
logger.info " [dist: #{path}]"
end
- return ret
- end
+ return ret
+ end
end
=begin
-
+
installer.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
require "log"
require "utils"
if Utils.is_windows_like_os( Utils::HOST_OS ) then
- require "rubygems"
- require "zip/zip"
+ require "rubygems"
+ require "zip/zip"
end
class FileInstaller
- CONFIG_PATH = "#{PackageServerConfig::CONFIG_ROOT}/client"
- PACKAGE_INFO_DIR = ".info"
+ CONFIG_PATH = "#{PackageServerConfig::CONFIG_ROOT}/client"
+ PACKAGE_INFO_DIR = ".info"
PACKAGE_MANIFEST = "pkginfo.manifest"
- def FileInstaller.install(package_name, package_file_path, type, target_path, logger)
-
- if not File.exist? package_file_path then
- logger.error "\"#{package_file_path}\" file does not exist."
- return false
- end
-
- case type
- # install script when binary package
- when "binary" then
- uniq_name = Utils.create_uniq_name
- path = Utils::HOME + "/tmp/#{uniq_name}"
- # windows has limitation for file path length
- if Utils.is_windows_like_os( Utils::HOST_OS ) then
- drive = Utils::HOME.split("/")[0]
- path = "#{drive}/#{uniq_name}"
- end
- if not File.exist? path then FileUtils.mkdir_p "#{path}" end
+ def FileInstaller.install(package_name, package_file_path, type, target_path, logger)
+
+ if not File.exist? package_file_path then
+ logger.error "\"#{package_file_path}\" file does not exist."
+ return false
+ end
+
+ case type
+ # install script when binary package
+ when "binary" then
+ uniq_name = Utils.create_uniq_name
+ path = Utils::HOME + "/tmp/#{uniq_name}"
+ # windows has limitation for file path length
+ if Utils.is_windows_like_os( Utils::HOST_OS ) then
+ drive = Utils::HOME.split("/")[0]
+ path = "#{drive}/#{uniq_name}"
+ end
+ if not File.exist? path then FileUtils.mkdir_p "#{path}" end
if File.directory? path then
log = "## create temporary dir : #{path}\n"
return false
end
- begin
+ begin
logger.info "Installing \"#{package_name}\" package.."
logger.info " [file: #{package_file_path}]"
- log = log + "## Extract file : #{package_file_path}\n"
+ log = log + "## Extract file : #{package_file_path}\n"
result = extract_file(package_name, package_file_path, path, target_path, logger)
if result == "" or result.nil? then
write_log(target_path, package_name, log)
return false
else log = log + result end
- log = log + "## Move files : \"#{path}\" to \"#{target_path}\"\n"
+ log = log + "## Move files : \"#{path}\" to \"#{target_path}\"\n"
result = move_dir(package_name, path, target_path, logger)
if result.nil? then
write_log(target_path, package_name, log)
return false
else log = log + result end
- log = log + "## Execute install script\n"
- result = execute_install_script(package_name, path, target_path, logger)
+ log = log + "## Execute install script\n"
+ result = execute_install_script(package_name, path, target_path, logger)
if result.nil? then
write_log(target_path, package_name, log)
return false
else log = log + result end
-
- log = log + "## Move remove script\n"
- result = move_remove_script(package_name, path, target_path, logger)
+
+ log = log + "## Move remove script\n"
+ result = move_remove_script(package_name, path, target_path, logger)
if result.nil? then
write_log(target_path, package_name, log)
return false
else log = log + result end
- log = log + "## Remove temporary dir : #{path} #####\n"
- result = Utils.execute_shell_return("rm -rf #{path}")
+ log = log + "## Remove temporary dir : #{path} #####\n"
+ result = Utils.execute_shell_return("rm -rf #{path}")
if result.nil? then
logger.warn "Failed to remove temporary path"
logger.info " [path: #{path}]"
end
- rescue Interrupt
- logger.error "FileInstaller: Interrupted.."
- Utils.execute_shell("rm -rf #{path}")
- logger.info "Removed #{path}"
- raise Interrupt
- end
+ rescue Interrupt
+ logger.error "FileInstaller: Interrupted.."
+ Utils.execute_shell("rm -rf #{path}")
+ logger.info "Removed #{path}"
+ raise Interrupt
+ end
write_log(target_path, package_name, log)
=begin
- target_config_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}"
- if not File.exist? target_config_path then FileUtils.mkdir_p(target_config_path) end
- pkg_inst_log = "#{package_name}_inst.log"
- pkg_inst_log_path = File.join(target_config_path, pkg_inst_log)
-
- File.open(pkg_inst_log_path, "a+") do |f|
- f.puts log
- end
+ target_config_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}"
+ if not File.exist? target_config_path then FileUtils.mkdir_p(target_config_path) end
+ pkg_inst_log = "#{package_name}_inst.log"
+ pkg_inst_log_path = File.join(target_config_path, pkg_inst_log)
+
+ File.open(pkg_inst_log_path, "a+") do |f|
+ f.puts log
+ end
=end
- when "source" then
- end
+ when "source" then
+ end
- # need verify
+ # need verify
logger.info "Installed \"#{package_name}\" package.. OK"
logger.info " [path: #{target_path}]"
- return true;
+ return true;
end
def FileInstaller.write_log(target_path, package_name, log)
end
end
- def FileInstaller.move_remove_script(package_name, path, target_path, logger)
- target_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}"
- if not File.exist? target_path then FileUtils.mkdir_p(target_path) end
- script_file_prefix = "#{path}/remove.*"
- script_file = Dir.glob(script_file_prefix)[0]
+ def FileInstaller.move_remove_script(package_name, path, target_path, logger)
+ target_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}"
+ if not File.exist? target_path then FileUtils.mkdir_p(target_path) end
+ script_file_prefix = "#{path}/remove.*"
+ script_file = Dir.glob(script_file_prefix)[0]
log = ""
- if not script_file.nil? then
+ if not script_file.nil? then
result = Utils.execute_shell_return("mv #{script_file} #{target_path}")
if result.nil? then
logger.error "Failed to move a remove script"
end
return log
- end
+ end
# Does not verify that the script execution is successful.
# Register shortcut should be failed.
- def FileInstaller.execute_install_script(package_name, path, target_path, logger)
- script_file_prefix = "#{path}/install.*"
- script_file = Dir.glob(script_file_prefix)[0]
- log = ""
-
- if not script_file.nil? then
- logger.info "Execute \"#{script_file}\" file"
- if Utils.is_windows_like_os( Utils::HOST_OS ) then
+ def FileInstaller.execute_install_script(package_name, path, target_path, logger)
+ script_file_prefix = "#{path}/install.*"
+ script_file = Dir.glob(script_file_prefix)[0]
+ log = ""
+
+ if not script_file.nil? then
+ logger.info "Execute \"#{script_file}\" file"
+ if Utils.is_windows_like_os( Utils::HOST_OS ) then
target_path = target_path.gsub("/","\\")
- cmd = "set INSTALLED_PATH=\"#{target_path}\"& #{script_file}"
- else
- cmd = "INSTALLED_PATH=\"#{target_path}\" #{script_file}"
+ cmd = "set INSTALLED_PATH=\"#{target_path}\"& #{script_file}"
+ else
+ cmd = "INSTALLED_PATH=\"#{target_path}\" #{script_file}"
end
logger.info " [cmd: #{cmd}]"
- log = `#{cmd}`
+ log = `#{cmd}`
logger.info "Executed install script file.. OK"
log = log + "[file: #{script_file}]\n"
log = log + "[cmd: #{cmd}]\n"
end
- return log
- end
+ return log
+ end
# Does not verify that the script execution is successful.
# Removing shortcut should be failed.
- def FileInstaller.execute_remove_script(package_name, target_path, logger)
- info_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}"
- if not File.directory? info_path then
+ def FileInstaller.execute_remove_script(package_name, target_path, logger)
+ info_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}"
+ if not File.directory? info_path then
logger.error "\"#{info_path}\" does not exist."
- return nil
- end
-
- script_file_prefix = "#{info_path}/remove.*"
- script_file = Dir.glob(script_file_prefix)[0]
- log = ""
-
- if not script_file.nil? then
- logger.info "Execute \"#{script_file}\" file"
- if Utils.is_windows_like_os( Utils::HOST_OS ) then
- cmd = "set INSTALLED_PATH=\"#{target_path}\"& #{script_file}"
- else
- cmd = "INSTALLED_PATH=\"#{target_path}\" #{script_file}"
- end
+ return nil
+ end
+
+ script_file_prefix = "#{info_path}/remove.*"
+ script_file = Dir.glob(script_file_prefix)[0]
+ log = ""
+
+ if not script_file.nil? then
+ logger.info "Execute \"#{script_file}\" file"
+ if Utils.is_windows_like_os( Utils::HOST_OS ) then
+ cmd = "set INSTALLED_PATH=\"#{target_path}\"& #{script_file}"
+ else
+ cmd = "INSTALLED_PATH=\"#{target_path}\" #{script_file}"
+ end
logger.info " [cmd: #{cmd}]"
- log = `#{cmd}`
+ log = `#{cmd}`
logger.info "Executed remote script file.. OK"
log = log + "[file: #{script_file}]\n"
log = log + "[cmd: #{cmd}]\n"
end
return log
- end
+ end
- def FileInstaller.remove_pkg_files(package_name, target_path, logger)
- list_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}"
+ def FileInstaller.remove_pkg_files(package_name, target_path, logger)
+ list_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}"
- if not File.directory? list_path then
+ if not File.directory? list_path then
logger.error "\"#{list_path}\" does not exist."
- return false
- end
-
- list_file_name = "#{list_path}/#{package_name}.list"
- list_file = Dir.glob(list_file_name)[0]
- directories = []
-
- if not list_file.nil? then
- File.open(list_file, "r") do |file|
- file.each_line do |f|
- f = f.strip
- if f.nil? or f.empty? then next end
- file_path = File.join(target_path, f)
- if File.directory? file_path then
- if File.symlink? file_path then
- File.unlink file_path
- next
- end
- entries = Dir.entries(file_path)
- if entries.include? "." then entries.delete(".") end
- if entries.include? ".." then entries.delete("..") end
- if entries.empty? or entries.nil? then
- begin
- Dir.rmdir(file_path)
- rescue SystemCallError
- logger.warn "\"#{file_path}\" directory is not empty"
- end
- else directories.push(file_path) end
- elsif File.file? file_path then FileUtils.rm_f(file_path)
- elsif File.symlink? file_path then File.unlink file_path
- # if files are already removed by remove script,
- else logger.warn "\"#{file_path}\" does not exist" end
- end
- end
-
- directories.reverse.each do |path|
+ return false
+ end
+
+ list_file_name = "#{list_path}/#{package_name}.list"
+ list_file = Dir.glob(list_file_name)[0]
+ directories = []
+
+ if not list_file.nil? then
+ File.open(list_file, "r") do |file|
+ file.each_line do |f|
+ f = f.strip
+ if f.nil? or f.empty? then next end
+ file_path = File.join(target_path, f)
+ if File.directory? file_path then
+ if File.symlink? file_path then
+ File.unlink file_path
+ next
+ end
+ entries = Dir.entries(file_path)
+ if entries.include? "." then entries.delete(".") end
+ if entries.include? ".." then entries.delete("..") end
+ if entries.empty? or entries.nil? then
+ begin
+ Dir.rmdir(file_path)
+ rescue SystemCallError
+ logger.warn "\"#{file_path}\" directory is not empty"
+ end
+ else directories.push(file_path) end
+ elsif File.file? file_path then FileUtils.rm_f(file_path)
+ elsif File.symlink? file_path then File.unlink file_path
+ # if files are already removed by remove script,
+ else logger.warn "\"#{file_path}\" does not exist" end
+ end
+ end
+
+ directories.reverse.each do |path|
if not File.directory? path then next end
- entries = Dir.entries(path)
- if entries.include? "." then entries.delete(".") end
- if entries.include? ".." then entries.delete("..") end
- if entries.empty? or entries.nil? then
- begin
- Dir.rmdir(path)
- rescue SystemCallError
- logger.warn "\"#{file_path}\" directory is not empty"
- end
- else next end
- end
- end
- Utils.execute_shell("rm -rf #{list_path}")
- return true
- end
-
- def FileInstaller.uninstall(package_name, type, target_path, logger)
- case type
- when "binary" then
- result = execute_remove_script(package_name, target_path, logger)
+ entries = Dir.entries(path)
+ if entries.include? "." then entries.delete(".") end
+ if entries.include? ".." then entries.delete("..") end
+ if entries.empty? or entries.nil? then
+ begin
+ Dir.rmdir(path)
+ rescue SystemCallError
+ logger.warn "\"#{file_path}\" directory is not empty"
+ end
+ else next end
+ end
+ end
+ Utils.execute_shell("rm -rf #{list_path}")
+ return true
+ end
+
+ def FileInstaller.uninstall(package_name, type, target_path, logger)
+ case type
+ when "binary" then
+ result = execute_remove_script(package_name, target_path, logger)
if result.nil? then return false end
if not remove_pkg_files(package_name, target_path, logger) then return false end
- when "source" then
- end
+ when "source" then
+ end
- return true
- end
+ return true
+ end
- def FileInstaller.move_dir(package_name, source_path, target_path, logger)
- config_path = File.join(target_path, PACKAGE_INFO_DIR, package_name)
+ def FileInstaller.move_dir(package_name, source_path, target_path, logger)
+ config_path = File.join(target_path, PACKAGE_INFO_DIR, package_name)
pkginfo_path = File.join(source_path, PACKAGE_MANIFEST)
data_path = File.join(source_path, "data")
log = ""
if File.exist? data_path then
# if os is linux, use cpio. it is faster than cp
- if Utils.is_linux_like_os( Utils::HOST_OS ) then
+ if Utils.is_linux_like_os( Utils::HOST_OS ) then
absolute_path = `readlink -f #{target_path}`
- result = Utils.execute_shell_return("cd #{data_path}; find . -depth | cpio -pldm #{absolute_path}")
+ result = Utils.execute_shell_return("cd #{data_path}; find . -depth | cpio -pldm #{absolute_path}")
else
- result = Utils.execute_shell_return("cp -r #{data_path}/* #{target_path}")
+ result = Utils.execute_shell_return("cp -r #{data_path}/* #{target_path}")
end
if result.nil? then
logger.error "Failed to move files"
else logger.warn "\"data\" directory does not exist." end
return log
- end
-
- def FileInstaller.extract_file(package_name, package_file_path, path, target_path, logger)
- dirname = File.dirname(package_file_path)
- filename = File.basename(package_file_path)
- ext = File.extname(filename)
-
- target_config_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}"
- if not File.exist? target_config_path then FileUtils.mkdir_p(target_config_path) end
- pkg_file_list = "#{package_name}.list"
- pkg_file_list_path = File.join(target_config_path, pkg_file_list)
- temp_pkg_file_list = "temp_file_list"
- temp_pkg_file_list_path = File.join(target_config_path, "temp_file_list")
-
- show_file_list_command = nil
- extrach_file_list_command = nil
+ end
+
+ def FileInstaller.extract_file(package_name, package_file_path, path, target_path, logger)
+ dirname = File.dirname(package_file_path)
+ filename = File.basename(package_file_path)
+ ext = File.extname(filename)
+
+ target_config_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}"
+ if not File.exist? target_config_path then FileUtils.mkdir_p(target_config_path) end
+ pkg_file_list = "#{package_name}.list"
+ pkg_file_list_path = File.join(target_config_path, pkg_file_list)
+ temp_pkg_file_list = "temp_file_list"
+ temp_pkg_file_list_path = File.join(target_config_path, "temp_file_list")
+
+ show_file_list_command = nil
+ extrach_file_list_command = nil
log = ""
- case ext
- when ".zip" then
- show_file_list_command = "zip -sf #{package_file_path}"
- extract_file_list_command = "unzip -o \"#{package_file_path}\" -d \"#{path}\""
- when ".tar" then
- # path should be unix path if it is used in tar command
- _package_file_path = Utils.get_unix_path(package_file_path)
- _path = Utils.get_unix_path(path)
- show_file_list_command = "tar -tf #{_package_file_path}"
- extract_file_list_command = "tar xf \"#{_package_file_path}\" -C \"#{_path}\""
- else
- logger.error "\"#{filename}\" is not supported."
- return nil
- end
-
- system "#{show_file_list_command} > #{temp_pkg_file_list_path}"
- File.open(pkg_file_list_path, "a+") do |targetfile|
- File.open(temp_pkg_file_list_path, "r") do |sourcefile|
- sourcefile.each_line do |l|
- if l.strip.start_with? "data/" then
- ml = l.strip[5..-1]
- targetfile.puts ml
- else next end
- end
- end
- end
- File.delete(temp_pkg_file_list_path)
-
- case ext
- when ".zip" then
- if Utils.is_windows_like_os( Utils::HOST_OS ) then
- log = unzip_file(package_file_path, path)
- else
+ case ext
+ when ".zip" then
+ show_file_list_command = "zip -sf #{package_file_path}"
+ extract_file_list_command = "unzip -o \"#{package_file_path}\" -d \"#{path}\""
+ when ".tar" then
+ # path should be unix path if it is used in tar command
+ _package_file_path = Utils.get_unix_path(package_file_path)
+ _path = Utils.get_unix_path(path)
+ show_file_list_command = "tar -tf #{_package_file_path}"
+ extract_file_list_command = "tar xf \"#{_package_file_path}\" -C \"#{_path}\""
+ else
+ logger.error "\"#{filename}\" is not supported."
+ return nil
+ end
+
+ system "#{show_file_list_command} > #{temp_pkg_file_list_path}"
+ File.open(pkg_file_list_path, "a+") do |targetfile|
+ File.open(temp_pkg_file_list_path, "r") do |sourcefile|
+ sourcefile.each_line do |l|
+ if l.strip.start_with? "data/" then
+ ml = l.strip[5..-1]
+ targetfile.puts ml
+ else next end
+ end
+ end
+ end
+ File.delete(temp_pkg_file_list_path)
+
+ case ext
+ when ".zip" then
+ if Utils.is_windows_like_os( Utils::HOST_OS ) then
+ log = unzip_file(package_file_path, path)
+ else
#result = Utils.execute_shell_return(extract_file_list_command)
#if result.nil? then log = nil
#else log = result.join("") end
log = `#{extract_file_list_command}`
- end
- when ".tar" then
- #result = Utils.execute_shell_return(extract_file_list_command)
+ end
+ when ".tar" then
+ #result = Utils.execute_shell_return(extract_file_list_command)
#if result.nil? then log = nil
#else log = result.join("") end
log = `#{extract_file_list_command}`
return nil
end
- logger.info "Extracted \"#{filename}\" file.. OK"
+ logger.info "Extracted \"#{filename}\" file.. OK"
log = log + "[file: #{package_file_path}]\n"
log = log + "[from: #{path}]\n"
log = log + "[to: #{target_path}]\n"
log = log + "[cmd: #{extract_file_list_command}]\n"
- return log
- end
-
- def FileInstaller.extract_a_file(package_file_path, target_file, path, logger)
- dirname = File.dirname(package_file_path)
- filename = File.basename(package_file_path)
- ext = File.extname(filename)
-
- case ext
- when ".zip" then
- if not path.nil? then
- extract_file_command = "unzip -x #{package_file_path} #{target_file} -d #{path}"
- else
- extract_file_command = "unzip -x #{package_file_path} #{target_file}"
- end
- when ".tar" then
- # path should be unix path if it is used in tar command
- _package_file_path = Utils.get_unix_path(package_file_path)
- _path = Utils.get_unix_path(path)
- if not path.nil? then
- extract_file_command = "tar xf #{_package_file_path} -C #{_path} #{target_file}"
- else
- extract_file_command = "tar xf #{_package_file_path} #{target_file}"
- end
- end
-
- system "#{extract_file_command}"
-
- if not path.nil? then
- target_file_path = File.join(path, target_file)
- else
- target_file_path = target_file
- end
-
- if File.exist? target_file_path then
- logger.info "Extracted \"#{target_file}\" file.."
- return true
- else
- logger.warn "Failed to extracted \"#{target_file}\" file.."
+ return log
+ end
+
+ def FileInstaller.extract_a_file(package_file_path, target_file, path, logger)
+ dirname = File.dirname(package_file_path)
+ filename = File.basename(package_file_path)
+ ext = File.extname(filename)
+
+ case ext
+ when ".zip" then
+ if not path.nil? then
+ extract_file_command = "unzip -x #{package_file_path} #{target_file} -d #{path}"
+ else
+ extract_file_command = "unzip -x #{package_file_path} #{target_file}"
+ end
+ when ".tar" then
+ # path should be unix path if it is used in tar command
+ _package_file_path = Utils.get_unix_path(package_file_path)
+ _path = Utils.get_unix_path(path)
+ if not path.nil? then
+ extract_file_command = "tar xf #{_package_file_path} -C #{_path} #{target_file}"
+ else
+ extract_file_command = "tar xf #{_package_file_path} #{target_file}"
+ end
+ end
+
+ system "#{extract_file_command}"
+
+ if not path.nil? then
+ target_file_path = File.join(path, target_file)
+ else
+ target_file_path = target_file
+ end
+
+ if File.exist? target_file_path then
+ logger.info "Extracted \"#{target_file}\" file.."
+ return true
+ else
+ logger.warn "Failed to extracted \"#{target_file}\" file.."
logger.info " [file: #{package_file_path}]"
logger.info " [path: #{path}]"
logger.info " [cmd: #{extract_file_command}]"
- return false
- end
- end
-
- def FileInstaller.unzip_file(zipfile, dest)
- log = ""
- Zip::ZipFile.open(zipfile) do |zip_file|
- zip_file.each do |f|
- f_path = File.join(dest, f.name)
- FileUtils.mkdir_p(File.dirname(f_path))
- if File.exist?(f_path) then
- log = log + "[Warn] Exist file : #{f_path}\n" unless f_path.end_with? "/"
- else
- zip_file.extract(f, f_path)
- if not f_path.end_with? "/" then
- log = log + "[info] Extracted file : #{f_path}\n"
- end
- end
- end
- end
- return log
- end
-
- def FileInstaller.unzip_a_file(zipfile, file, dest)
- Zip::ZipFile.open(zipfile) do |zip_file|
- zip_file.each do |f|
- if f.name.strip == file then
- f_path = File.join(dest, f.name)
- FileUtils.mkdir_p(File.dirname(f_path))
- zip_file.extract(f, f_path) unless File.exist?(f_path)
- break
- end
- end
- end
- end
+ return false
+ end
+ end
+
+ def FileInstaller.unzip_file(zipfile, dest)
+ log = ""
+ Zip::ZipFile.open(zipfile) do |zip_file|
+ zip_file.each do |f|
+ f_path = File.join(dest, f.name)
+ FileUtils.mkdir_p(File.dirname(f_path))
+ if File.exist?(f_path) then
+ log = log + "[Warn] Exist file : #{f_path}\n" unless f_path.end_with? "/"
+ else
+ zip_file.extract(f, f_path)
+ if not f_path.end_with? "/" then
+ log = log + "[info] Extracted file : #{f_path}\n"
+ end
+ end
+ end
+ end
+ return log
+ end
+
+ def FileInstaller.unzip_a_file(zipfile, file, dest)
+ Zip::ZipFile.open(zipfile) do |zip_file|
+ zip_file.each do |f|
+ if f.name.strip == file then
+ f_path = File.join(dest, f.name)
+ FileUtils.mkdir_p(File.dirname(f_path))
+ zip_file.extract(f, f_path) unless File.exist?(f_path)
+ break
+ end
+ end
+ end
+ end
end
=begin
-
+
packageServer.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
attr_accessor :incoming_path
attr_accessor :distribution_list
attr_accessor :sync_interval, :passwd
-
- # constant
+
+ # constant
SERVER_ROOT = "#{PackageServerConfig::CONFIG_ROOT}/pkg_server"
DIBS_LOCK_FILE_PATH = "#{SERVER_ROOT}/.server_loc"
@lock_file= nil
@sync_interval = 3600
@passwd = ""
-
+
update_config_information(id)
if not File.exist?( SERVER_ROOT )
if File.exist? @config_dir
raise RuntimeError, "Server create fail. server id [#{@id}] is already exist"
end
-
+
# name check
if dist_name.strip.eql? "distribution.info" then
raise RuntimeError, "id \"distribution.info\" is not available"
FileUtils.mkdir_p @incoming_path
if (not server_url.empty?) and \
- (not Utils.is_url_remote(server_url)) and \
- (not Utils.is_absolute_path(server_url)) then
- # if server_url is local server address then generate absoulte path
+ (not Utils.is_url_remote(server_url)) and \
+ (not Utils.is_absolute_path(server_url)) then
+ # if server_url is local server address then generate absoulte path
server_url = File.join(Utils::WORKING_DIR, server_url)
end
f.puts "sync interval : #{@sync_interval}"
f.puts "server_url : #{dist_name} -> #{server_url}"
end
-
+
# create location's directory
FileUtils.mkdir_p "#{@location}"
-
+
create_distribution_struct( dist_name, server_url )
Utils.file_unlock(lock_file)
# distribution lock
@lock_file = Utils.file_lock(distribution.lock_file_path)
-
+
updated_os_list = []
registed_package_list = []
binary_pkg_file_path_list = []
file_path_list.each do |f|
# error check for file exist
- if not File.exist? f
+ if not File.exist? f
raise RuntimeError, "package file does not exist [#{f}]"
end
end
updated_pkg = register_package(distribution, pkg, f, test_flag, internal_flag)
-
+
updated_os_list.push updated_pkg.os
registed_package_list.push updated_pkg
- # archive package
+ # archive package
else
if test_flag then
@log.error("archive package does not using test mode", Log::LV_USER)
end
# move file to package server
- binary_pkg_file_path_list.each do |l|
- if test_flag then
- FileUtils.copy_file( l, "#{distribution.location}/temp/#{File.basename(l)}" )
- else
- FileUtils.copy_file( l, "#{distribution.location}/binary/#{File.basename(l)}" )
- end
- end
+ binary_pkg_file_path_list.each do |l|
+ if test_flag then
+ FileUtils.copy_file( l, "#{distribution.location}/temp/#{File.basename(l)}" )
+ else
+ FileUtils.copy_file( l, "#{distribution.location}/binary/#{File.basename(l)}" )
+ end
+ end
# link to package server
link_pkg_file_path_list.each do |l|
end
end
- archive_pkg_file_path_list.each do |l|
- FileUtils.mv( l, "#{distribution.location}/source/" )
- end
+ archive_pkg_file_path_list.each do |l|
+ FileUtils.mv( l, "#{distribution.location}/source/" )
+ end
# write package list for updated os
updated_os_list.uniq!
updated_os_list.each do |os|
- distribution.write_pkg_list(os)
+ distribution.write_pkg_list(os)
end
# register archive pakcage list.
msg_list = []
registed_package_list.each { |p|
- msg_list.push("%-30s: %08s" % [ p.package_name.strip, p.version.strip ] )
+ msg_list.push("%-30s: %08s" % [ p.package_name.strip, p.version.strip ] )
}
# email just remote package server
# Mail.send_package_registe_mail( msg_list, @id )
end
- # if snapshot mode is true then generate snapshot
- if snapshot or test_flag then
+ # if snapshot mode is true then generate snapshot
+ if snapshot or test_flag then
@log.info "generaging snapshot"
snapshot_name = distribution.generate_snapshot("", "", false, get_changelog_string(registed_package_list) )
end
@log.output( "package registed successfully", Log::LV_USER)
return snapshot_name
- end
+ end
def get_changelog_string( package_list )
log_list = []
snapshot_name = distribution.generate_snapshot( snpashot_name, base_snapshot, true, "SYSTEM:")
Utils.file_unlock(@lock_file)
-
+
return snapshot_name
end
def sync( dist_name, mode, snapshot = "" )
@log.info "sync from server"
distribution = get_distribution( dist_name )
-
+
if distribution.server_url.empty? then
@log.error( "This distribution has not remote server", Log::LV_USER)
return
def add_distribution( dist_name, server_url, clone )
lock_file = Utils.file_lock(@server_lock_file_path)
-
+
# error check : check for already exist in server directory
if @dist_to_server_url.keys.include? dist_name.strip then
Utils.file_unlock(@lock_file)
raise RuntimeError, "distribution already exist : #{dist_name}"
end
-
+
# name check
if dist_name.strip.eql? "distribution.info" then
Utils.file_unlock(@lock_file)
raise RuntimeError, "id \"distribution.info\" is not available"
end
-
+
# modify server url
if (not server_url.empty?) and (not Utils.is_url_remote(server_url))
# if server_url is local server address then generate absoulte path
def add_os(dist_name, os)
dist = get_distribution(dist_name)
-
+
# distribution lock
@lock_file = Utils.file_lock(dist.lock_file_path)
-
+
dist.add_os(os)
@log.info "generaging snapshot"
def remove_server()
@log.info( "Package server [#{@id}] will be removed and all server information delete", Log::LV_USER)
-
+
lock_file = Utils.file_lock(DIBS_LOCK_FILE_PATH)
if File.exist? @config_file_path then
File.open @config_file_path do |f|
else
@log.error( "Can't find server information : #{@id}", Log::LV_USER)
end
-
+
FileUtils.rm_rf @config_dir
FileUtils.rm_rf @log_file_path
-
+
Utils.file_unlock(lock_file)
@log.output( "package server [#{@id}] removed successfully", Log::LV_USER )
end
distribution = get_distribution( dist_name )
lock_file = Utils.file_lock(@server_lock_file_path)
-
+
# modify config file
config_file = File.readlines(@config_file_path)
File.open(@config_file_path, 'w') do |f|
# remove distribution directory
FileUtils.rm_rf distribution.location
-
+
# remove distribution struct
@distribution_list.delete distribution
distribution = get_distribution( dist_name )
lock_file = Utils.file_lock(@server_lock_file_path)
-
+
distribution.remove_pkg(pkg_name_list, os)
-
+
# generate snapshot
@log.info "generaging snapshot"
distribution.generate_snapshot("", "", false, "SYSTEM: Package \"#{pkg_name_list.join(", ")}\" is(are) removed in #{os} server")
Utils.file_unlock(lock_file)
@log.output( "package removed successfully", Log::LV_USER )
end
-
+
def remove_snapshot( dist_name, snapshot_list )
@log.info "remove snapshot in server"
distribution = get_distribution( dist_name )
lock_file = Utils.file_lock(@server_lock_file_path)
-
+
distribution.remove_snapshot(snapshot_list)
-
+
Utils.file_unlock(lock_file)
end
distribution = get_distribution( dist_name )
lock_file = Utils.file_lock(@server_lock_file_path)
-
+
distribution.clean( snapshot_list )
# remove incoming dir
FileUtils.rm_rf incoming_path
FileUtils.mkdir incoming_path
-
+
Utils.file_unlock(lock_file)
end
# start server daemon
def start( port, passwd )
- @log.info "Package server Start..."
+ @log.info "Package server Start..."
# set port number. default port is 3333
@port = port
# set job request listener
- @log.info "Setting listener..."
+ @log.info "Setting listener..."
listener = SocketRegisterListener.new(self)
listener.start
- # set auto sync
+ # set auto sync
if @auto_sync_flag.eql? "YES" then
- @log.info "Setting auto sync..."
- autosync = DistSync.new(self)
- autosync.start
+ @log.info "Setting auto sync..."
+ autosync = DistSync.new(self)
+ autosync.start
end
-
+
# set password
@passwd = passwd
# set port number. default port is 3333
@port = port
@finish = false
-
+
client = BuildCommClient.create("127.0.0.1", @port, @log)
if client.nil? then
raise RuntimeError, "Server does not listen in #{@port} port"
@log.output( "Package server return error message : #{ret}", Log::LV_USER)
end
client.terminate
-
+
end
def self.list_id
s = d.select {|f| not f.start_with?(".") }
s.sort!
server_list = []
-
+
@@log.output( "=== server ID list ===", Log::LV_USER)
s.each do |id|
if File.extname(id).eql?(".log") then next end
def self.list_dist( id )
@@log = PackageServerLog.new( "#{SERVER_ROOT}/.log" )
-
+
@@log.output( "=== ID [#{id}]'s distribution list ===", Log::LV_USER)
dist_list = []
if not File.exist? config_file_path
raise RuntimeError, "[#{id}] is not server ID"
end
-
+
File.open config_file_path do |f|
f.each_line do |l|
if l.start_with?( "server_url : ") and l.include?( "->" ) then
end
end
end
-
+
@dist_to_server_url.each do |dist_name, server_url|
@distribution_list.push Distribution.new( dist_name, "#{@location}/#{dist_name}", server_url, self )
end
if File.exist? "#{@location}/#{dist_name}"
raise RuntimeError, "distribution directory already exist [#{@location}/#{dist_name}]"
end
-
+
FileUtils.mkdir "#{@location}/#{dist_name}"
FileUtils.mkdir "#{@location}/#{dist_name}/binary"
FileUtils.mkdir "#{@location}/#{dist_name}/source"
# add dist
@distribution_list.push distribution
-
+
if not server_url.empty? then
@log.info "generate package server using remote package server [#{server_url}]"
else
@log.info "[#{dist_name}] distribution creation. using local server [#{server_url}]"
end
-
+
distribution.sync(false)
distribution.generate_snapshot("", "", false, distribution.last_sync_changes)
else
@log.info "generate package server do not using remote package server"
-
+
# write_pkg_list for empty file
distribution.write_pkg_list(nil)
distribution.write_archive_pkg_list()
if pkg.nil? or pkg.package_name.empty? then
raise "[#{file_path}]'s pkginfo.manifest file is incomplete."
end
-
+
if not test_flag then
# error check
if pkg.package_name.empty? or pkg.version.empty? \
- or pkg.os.empty? or pkg.maintainer.empty? then
+ or pkg.os.empty? or pkg.maintainer.empty? then
raise "[#{file_path}]'s pkginfo.manifest file is incomplete."
end
=begin
-
+
serverConfig.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
=begin
-
+
packageServerLog.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
=begin
-
+
serverOptParser.rb
Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
end
def option_error_check( options )
-
+
case options[:cmd]
when "create"
- if options[:id].empty? or options[:dist].empty? then
+ if options[:id].empty? or options[:dist].empty? then
raise ArgumentError, "Usage: pkg-svr create -n <server name> -d <distribution> [-u <remote server url>] [-l <location>] "
end
when "remove"
if options[:id].empty? then
- raise ArgumentError, "Usage: pkg-svr remove -n <server name> "
+ raise ArgumentError, "Usage: pkg-svr remove -n <server name> "
end
when "remove-pkg"
if options[:pkgs].empty? then
- raise ArgumentError, "Usage: pkg-svr remove-pkg -n <server name> -d <distribution> -P <package file list> [-o <os>]" + "\n" \
+ raise ArgumentError, "Usage: pkg-svr remove-pkg -n <server name> -d <distribution> -P <package file list> [-o <os>]" + "\n" \
end
when "remove-snapshot"
if options[:snaps].empty? then
- raise ArgumentError, "Usage: pkg-svr remove-snapshot -n <server name> -d <distribution> -s <snapshot list>"
+ raise ArgumentError, "Usage: pkg-svr remove-snapshot -n <server name> -d <distribution> -s <snapshot list>"
end
when "add-dist"
- if options[:id].empty? or options[:dist].empty? then
+ if options[:id].empty? or options[:dist].empty? then
raise ArgumentError, "Usage: pkg-svr add-dist -n <server name> -d <distribution> [-u <remote server url>] [--clone] "
end
when "add-os"
- if options[:os].empty? then
+ if options[:os].empty? then
raise ArgumentError, "Usage: pkg-svr add-os -n <server name> -d <distribution> -o <os>] "
end
when "remove-dist"
- if options[:id].empty? or options[:dist].empty? then
+ if options[:id].empty? or options[:dist].empty? then
raise ArgumentError, "Usage: pkg-svr remove-dist -n <server name> -d <distribution> "
end
when "register"
- if options[:pkgs].empty? then
+ if options[:pkgs].empty? then
raise ArgumentError, "Usage: pkg-svr register -n <server name> -d <distribution> -P <package file list> [--gen] [--test] "
end
when "gen-snapshot"
end
def option_parse
- options = {}
- banner = "Package-server administer service command-line tool." + "\n" \
- + "\n" + "Usage: pkg-svr <SUBCOMMAND> [OPTS] or pkg-svr (-h|-v)" + "\n" \
- + "\n" + "Subcommands:" + "\n" \
- + "\t" + "create Create a package-server." + "\n" \
- + "\t" + "add-dist Add a distribution to package-server." + "\n" \
- + "\t" + "add-os Add supported os." + "\n" \
- + "\t" + "register Register a package in package-server." + "\n" \
- + "\t" + "remove Remove a package-server." + "\n" \
- + "\t" + "remove-dist Remove a distribution to package-server." + "\n" \
- + "\t" + "remove-pkg Remove a package in package-server." + "\n" \
- + "\t" + "remove-snapshot Remove a snapshot in package-server." + "\n" \
- + "\t" + "gen-snapshot Generate a snapshot in package-server." + "\n" \
- + "\t" + "sync Synchronize the package-server from parent package server." + "\n" \
- + "\t" + "start Start the package-server." + "\n" \
- + "\t" + "stop Stop the package-server." + "\n" \
- + "\t" + "clean Delete unneeded package files in package-server." + "\n" \
- + "\t" + "list Show all pack" + "\n" \
- + "\n" + "Subcommand usage:" + "\n" \
- + "\t" + "pkg-svr create -n <server name> -d <distribution> [-u <remote server url>] [-l <location>] " + "\n" \
- + "\t" + "pkg-svr add-dist -n <server name> -d <distribution> [-u <remote server url>] [--clone] " + "\n" \
- + "\t" + "pkg-svr add-os -n <server name> -d <distribution> -o <os> " + "\n" \
- + "\t" + "pkg-svr register -n <server name> -d <distribution> -P <package file list> [--gen] [--test] " + "\n" \
- + "\t" + "pkg-svr remove -n <server name> " + "\n" \
- + "\t" + "pkg-svr remove-dist -n <server name> -d <distribution>" + "\n" \
- + "\t" + "pkg-svr remove-pkg -n <server name> -d <distribution> -P <package name list> [-o <os>] " + "\n" \
- + "\t" + "pkg-svr remove-snapshot -n <server name> -d <distribution> -s <snapshot list>" + "\n" \
- + "\t" + "pkg-svr gen-snapshot -n <server name> -d <distribution> -s <snapshot name> [-b <base snapshot name>] " + "\n" \
- + "\t" + "pkg-svr sync -n <server name> -d <distribution> -s <snapshot_name> [--force] " + "\n" \
- + "\t" + "pkg-svr clean -n <server name> -d <distribution> [-s <snapshot list>] " + "\n" \
- + "\t" + "pkg-svr start -n <server name> -p <port> [-w <password>]" + "\n" \
- + "\t" + "pkg-svr stop -n <server name> -p <port> [-w <password>]" + "\n" \
- + "\t" + "pkg-svr list [-n <server name>] " + "\n" \
- + "\n" + "Options:" + "\n"
-
- optparse = OptionParser.new(nil, 32, ' '*8) do|opts|
- # Set a banner, displayed at the top
- # of the help screen.
+ options = {}
+ banner = "Package-server administer service command-line tool." + "\n" \
+ + "\n" + "Usage: pkg-svr <SUBCOMMAND> [OPTS] or pkg-svr (-h|-v)" + "\n" \
+ + "\n" + "Subcommands:" + "\n" \
+ + "\t" + "create Create a package-server." + "\n" \
+ + "\t" + "add-dist Add a distribution to package-server." + "\n" \
+ + "\t" + "add-os Add supported os." + "\n" \
+ + "\t" + "register Register a package in package-server." + "\n" \
+ + "\t" + "remove Remove a package-server." + "\n" \
+ + "\t" + "remove-dist Remove a distribution to package-server." + "\n" \
+ + "\t" + "remove-pkg Remove a package in package-server." + "\n" \
+ + "\t" + "remove-snapshot Remove a snapshot in package-server." + "\n" \
+ + "\t" + "gen-snapshot Generate a snapshot in package-server." + "\n" \
+ + "\t" + "sync Synchronize the package-server from parent package server." + "\n" \
+ + "\t" + "start Start the package-server." + "\n" \
+ + "\t" + "stop Stop the package-server." + "\n" \
+ + "\t" + "clean Delete unneeded package files in package-server." + "\n" \
+ + "\t" + "list Show all pack" + "\n" \
+ + "\n" + "Subcommand usage:" + "\n" \
+ + "\t" + "pkg-svr create -n <server name> -d <distribution> [-u <remote server url>] [-l <location>] " + "\n" \
+ + "\t" + "pkg-svr add-dist -n <server name> -d <distribution> [-u <remote server url>] [--clone] " + "\n" \
+ + "\t" + "pkg-svr add-os -n <server name> -d <distribution> -o <os> " + "\n" \
+ + "\t" + "pkg-svr register -n <server name> -d <distribution> -P <package file list> [--gen] [--test] " + "\n" \
+ + "\t" + "pkg-svr remove -n <server name> " + "\n" \
+ + "\t" + "pkg-svr remove-dist -n <server name> -d <distribution>" + "\n" \
+ + "\t" + "pkg-svr remove-pkg -n <server name> -d <distribution> -P <package name list> [-o <os>] " + "\n" \
+ + "\t" + "pkg-svr remove-snapshot -n <server name> -d <distribution> -s <snapshot list>" + "\n" \
+ + "\t" + "pkg-svr gen-snapshot -n <server name> -d <distribution> -s <snapshot name> [-b <base snapshot name>] " + "\n" \
+ + "\t" + "pkg-svr sync -n <server name> -d <distribution> -s <snapshot_name> [--force] " + "\n" \
+ + "\t" + "pkg-svr clean -n <server name> -d <distribution> [-s <snapshot list>] " + "\n" \
+ + "\t" + "pkg-svr start -n <server name> -p <port> [-w <password>]" + "\n" \
+ + "\t" + "pkg-svr stop -n <server name> -p <port> [-w <password>]" + "\n" \
+ + "\t" + "pkg-svr list [-n <server name>] " + "\n" \
+ + "\n" + "Options:" + "\n"
+
+ optparse = OptionParser.new(nil, 32, ' '*8) do|opts|
+ # Set a banner, displayed at the top
+ # of the help screen.
opts.banner = banner
- opts.on( '-n', '--name <server name>', 'package server name' ) do|name|
- options[:id] = name
- end
-
+ opts.on( '-n', '--name <server name>', 'package server name' ) do|name|
+ options[:id] = name
+ end
+
opts.on( '-d', '--dist <distribution>', 'package server distribution' ) do|dist|
- options[:dist] = dist
- end
-
+ options[:dist] = dist
+ end
+
opts.on( '-u', '--url <server url>', 'remote server url: http://127.0.0.1/dibs/unstable' ) do|url|
- options[:url] = url
- end
-
+ options[:url] = url
+ end
+
opts.on( '-o', '--os <operating system>', 'target operating system' ) do|os|
- options[:os] = os
- end
-
+ options[:os] = os
+ end
+
opts.on( '-P', '--pkgs <package file list>', 'package file path list' ) do|pkgs|
if not Utils.multi_argument_test( pkgs, "," ) then
raise ArgumentError, "Package variable parsing error : #{pkgs}"
end
- list = pkgs.tr(" \t","").split(",")
- list.each do |l|
+ list = pkgs.tr(" \t","").split(",")
+ list.each do |l|
if l.start_with? "~" then l = Utils::HOME + l.delete("~") end
options[:pkgs].push l
- end
- end
-
+ end
+ end
+
opts.on( '-s', '--snapshot <snapshot>', 'a snapshot name or snapshot list' ) do|snaplist|
if not Utils.multi_argument_test( snaplist, "," ) then
raise ArgumentError, "Snapshot variable parsing error : #{snaplist}"
end
- options[:snaps] = snaplist.split(",")
- end
+ options[:snaps] = snaplist.split(",")
+ end
opts.on( '-b', '--base <base snapshot>', 'base snapshot name' ) do|bsnap|
- options[:bsnap] = bsnap
- end
-
+ options[:bsnap] = bsnap
+ end
+
opts.on( '-l', '--loc <location>', 'server location' ) do|loc|
- options[:loc] = loc
- end
-
+ options[:loc] = loc
+ end
+
opts.on( '-p', '--port <port>', 'port number' ) do|port|
- options[:port] = port
- end
-
+ options[:port] = port
+ end
+
opts.on( '-w', '--passwd <password>', 'password for package server' ) do|passwd|
- options[:passwd] = passwd
- end
+ options[:passwd] = passwd
+ end
opts.on( '--clone', 'clone mode' ) do
- options[:clone] = true
- end
+ options[:clone] = true
+ end
opts.on( '--force', 'force update pkg file' ) do
- options[:force] = true
- end
-
+ options[:force] = true
+ end
+
opts.on( '--test', 'upload for test' ) do
- options[:test] = true
- end
+ options[:test] = true
+ end
opts.on( '--gen', 'generate snapshot' ) do
- options[:gensnap] = true
+ options[:gensnap] = true
end
-
+
opts.on( '-h', '--help', 'display help' ) do
- puts opts
+ puts opts
exit
- end
+ end
opts.on( '-v', '--version', 'display version' ) do
- puts "DIBS(Distributed Intelligent Build System) version " + Utils.get_version()
+ puts "DIBS(Distributed Intelligent Build System) version " + Utils.get_version()
exit
- end
- end
-
+ end
+ end
+
cmd = ARGV[0]
- if cmd.eql? "create" or cmd.eql? "sync" \
- or cmd.eql? "register" \
- or cmd.eql? "gen-snapshot" \
- or cmd.eql? "add-dist" or cmd.eql? "add-os" \
- or cmd.eql? "remove" or cmd.eql? "remove-dist" \
- or cmd.eql? "remove-pkg" or cmd.eql? "remove-snapshot" \
- or cmd.eql? "start" or cmd.eql? "stop" or cmd.eql? "clean" \
- or cmd.eql? "list" \
- or cmd =~ /(-v)|(--version)/ \
- or cmd =~ /(help)|(-h)|(--help)/ then
- if cmd.eql? "help" then ARGV[0] = "-h" end
- options[:cmd] = ARGV[0]
- else
- raise ArgumentError, "Usage: pkg-svr <SUBCOMMAND> [OPTS] or pkg-svr -h"
- end
+ if cmd.eql? "create" or cmd.eql? "sync" \
+ or cmd.eql? "register" \
+ or cmd.eql? "gen-snapshot" \
+ or cmd.eql? "add-dist" or cmd.eql? "add-os" \
+ or cmd.eql? "remove" or cmd.eql? "remove-dist" \
+ or cmd.eql? "remove-pkg" or cmd.eql? "remove-snapshot" \
+ or cmd.eql? "start" or cmd.eql? "stop" or cmd.eql? "clean" \
+ or cmd.eql? "list" \
+ or cmd =~ /(-v)|(--version)/ \
+ or cmd =~ /(help)|(-h)|(--help)/ then
+ if cmd.eql? "help" then ARGV[0] = "-h" end
+ options[:cmd] = ARGV[0]
+ else
+ raise ArgumentError, "Usage: pkg-svr <SUBCOMMAND> [OPTS] or pkg-svr -h"
+ end
# default value setting
set_default options
-
+
optparse.parse!
# option error check
option_error_check options
- return options
+ return options
end