Update Tizen 2.0 SDK source code
[sdk/tools/sdk-build.git] / pkg-cli
1 #!/usr/bin/ruby 
2
3 =begin
4  
5  pkg-cli
6
7 Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
8
9 Contact:
10 Taejun Ha <taejun.ha@samsung.com>
11 Jiil Hyoun <jiil.hyoun@samsung.com>
12 Donghyuk Yang <donghyuk.yang@samsung.com>
13 DongHee Yang <donghee.yang@samsung.com>
14
15 Licensed under the Apache License, Version 2.0 (the "License");
16 you may not use this file except in compliance with the License.
17 You may obtain a copy of the License at
18
19 http://www.apache.org/licenses/LICENSE-2.0
20
21 Unless required by applicable law or agreed to in writing, software
22 distributed under the License is distributed on an "AS IS" BASIS,
23 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 See the License for the specific language governing permissions and
25 limitations under the License.
26
27 Contributors:
28 - S-Core Co., Ltd
29 =end
30
31 require 'fileutils'
32 require 'logger'
33 $LOAD_PATH.unshift File.dirname(__FILE__)+"/src/common"
34 $LOAD_PATH.unshift File.dirname(__FILE__)+"/src/pkg_server"
35
36 #library
37 require "utils"
38 require "clientOptParser"
39 require "client"
40 require "packageServer"
41
42 #set global variable
43 @WORKING_DIR = nil
44
45 #option parsing 
46 begin
47         option = option_parse
48 rescue => e
49         # if option parse error print help message
50     puts e.message
51         exit 0
52 end
53
54 # check HOST OS
55 if not Utils.check_host_OS() then
56         puts "Error: Your host OS is not supported!"
57         exit 1
58 end
59 #if "--os" is not specfied, use host os type
60 if option[:os].nil? then
61         option[:os] = Utils::HOST_OS
62 end
63
64 case option[:cmd] 
65 when "update" then
66     client = Client.new( option[:url], nil, nil )
67     #client.update()
68 when "clean" then
69     client = Client.new( nil, option[:loc], nil )
70     client.clean(option[:f])
71 when "download" then
72     client = Client.new( option[:url], option[:loc], nil )
73     #if not option[:url].nil? then
74     #    client.update()
75     #end
76         file_loc = client.download( option[:pkg], option[:os], option[:t] )
77 when "install" then
78     client = Client.new( option[:url], option[:loc], nil )
79     #if not option[:url].nil? then
80     #    client.update()
81     #end
82     client.install( option[:pkg], option[:os], option[:t], option[:f] ) 
83 when "install-file" then
84     client = Client.new( option[:url], option[:loc], nil )
85         client.install_local_pkg( option[:pkg], option[:t], option[:f] ) 
86 when "uninstall" then
87     client = Client.new( nil, option[:loc], nil )
88     client.uninstall( option[:pkg], option[:t] )
89 when "upgrade" then
90     client = Client.new( option[:url], option[:loc], nil )
91     #if not option[:url].nil? then
92     #    client.update()
93     #end
94     client.upgrade( option[:os], option[:t] )
95 when "check-upgrade" then
96     client = Client.new( option[:url], option[:loc], nil )
97     #if not option[:url].nil? then
98     #   client.update()
99         #end
100     client.check_upgrade( option[:os] )
101 when "show-rpkg" then
102     client = Client.new( option[:url], nil, nil )
103     #if not option[:url].nil? then
104     #    client.update()
105     #end
106         puts client.show_pkg_info( option[:pkg], option[:os] ) 
107 when "list-rpkg" then
108     client = Client.new( option[:url], nil, nil )
109     #if not option[:url].nil? then
110     #    client.update()
111     #end
112         result = client.show_pkg_list( option[:os] )
113     if not result.nil? and not result.empty? then
114         result.each do |i|
115             name = i[0].strip
116             version = i[1].strip
117             desc = i[2].strip
118             puts name + "  (" + version + ")"
119         end
120     end
121 when "show-lpkg" then
122     client = Client.new( nil, option[:loc], nil )
123     puts client.show_installed_pkg_info( option[:pkg] )
124 when "list-lpkg" then
125     client = Client.new( nil, option[:loc], nil )
126         result = client.show_installed_pkg_list()
127     if not result.nil? and not result.empty? then
128         result.each do |i|
129             name = i[0].strip
130             version = i[1].strip
131             desc = i[2].strip
132             puts name + "  (" + version + ")"
133         end
134     else 
135         puts "Info: There is no any package."
136     end
137 when "build-dep" then
138     client = Client.new( nil, nil, nil )
139         result = client.get_build_dependent_packages( option[:pkg], option[:os], true )
140     ret = ""
141     result.each do |i|
142         ret = ret + i + " --> "
143     end
144     ret = ret.strip
145     ret[-3..-1] = ""
146     puts ret
147 when "install-dep" then
148     client = Client.new( nil, nil, nil )
149         result = client.get_install_dependent_packages( option[:pkg], option[:os], true, false )
150     ret = ""
151     result.each do |i|
152         ret = ret + i + " --> "
153     end
154     ret = ret.strip
155     ret[-3..-1] = ""
156     puts ret
157 else
158     raise RuntimeError, "Input is incorrect : #{option[:cmd]}"
159 end
160