#!/usr/bin/ruby =begin pkg-cli Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. Contact: Taejun Ha Jiil Hyoun Donghyuk Yang DongHee Yang 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 'fileutils' require 'logger' $LOAD_PATH.unshift File.dirname(__FILE__)+"/src/common" $LOAD_PATH.unshift File.dirname(__FILE__)+"/src/pkg_server" #library require "utils" require "clientOptParser" require "client" require "packageServer" #set global variable @WORKING_DIR = nil $log = Logger.new('.log', 'monthly') #option parsing begin option = option_parse rescue => e # if option parse error print help message $log.error "option parsing error" system "#{__FILE__} help" exit 0 end #if "--os" is not specfied, use host os type if option[:os].nil? then system_type = `uname -s` case system_type.strip when "Linux" then option[:os] = "linux" when /MINGW32.*/ then option[:os] = "windows" when "Darwin" then option[:os] = "darwin" else raise RuntimeError, "Unknown OS type : #{system_type}" end end case option[:cmd] when "update" then client = Client.new( option[:url], nil, nil ) client.update() when "clean" then 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 file_loc = client.download( option[:pkg], option[:os], option[:t] ) when "upload" then client = Client.new( nil, nil, nil ) result = client.upload( option[:alias], option[:id], option[:binpkg], option[:srcpkg], false ) if not result.nil? then puts result end when "source" then client = Client.new( option[:url], option[:loc], nil ) if not option[:url].nil? then client.update() end client.download_source( option[:pkg], option[:os] ) 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] ) when "install-file" then client = Client.new( nil, option[:loc], nil ) client.install_local_pkg( option[:pkg], option[:f] ) when "uninstall" then 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] ) when "check-upgrade" then client = Client.new( option[:url], option[:loc], nil ) if not option[:url].nil? then client.update() end 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 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 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 when "show-lpkg" then 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 ) 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 when "build-dep" then 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 when "install-dep" then 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 else raise RuntimeError, "input option incorrect : #{option[:cmd]}" end