upload tizen1.0 source
[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 $log = Logger.new('.log', 'monthly')
46
47 #option parsing 
48 begin
49         option = option_parse
50 rescue => e
51         # if option parse error print help message
52     $log.error "option parsing error"
53         system "#{__FILE__} help"
54         exit 0
55 end
56
57 #if "--os" is not specfied, use host os type
58 if option[:os].nil? then
59         system_type = `uname -s`
60         case system_type.strip
61     when "Linux" then
62                 option[:os] = "linux"
63         when /MINGW32.*/ then
64                 option[:os] = "windows"
65         when "Darwin" then
66                 option[:os] = "darwin"
67         else
68                 raise RuntimeError, "Unknown OS type : #{system_type}"
69         end
70 end
71
72 case option[:cmd] 
73 when "update" then
74     client = Client.new( option[:url], nil, nil )
75     client.update()
76 when "clean" then
77     client = Client.new( nil, option[:loc], nil )
78     client.clean(option[:f])
79 when "download" then
80     client = Client.new( option[:url], option[:loc], nil )
81     if not option[:url].nil? then
82         client.update()
83     end
84         file_loc = client.download( option[:pkg], option[:os], option[:t] )
85 when "upload" then
86     client = Client.new( nil, nil, nil )
87         result = client.upload( option[:alias], option[:id], option[:binpkg], option[:srcpkg], false )
88     if not result.nil? then
89         puts result
90     end
91 when "source" then    
92     client = Client.new( option[:url], option[:loc], nil )
93     if not option[:url].nil? then
94         client.update()
95     end
96     client.download_source( option[:pkg], option[:os] )
97 when "install" then
98     client = Client.new( option[:url], option[:loc], nil )
99     if not option[:url].nil? then
100         client.update()
101     end
102         client.install( option[:pkg], option[:os], option[:t], option[:f] ) 
103 when "install-file" then
104     client = Client.new( nil, option[:loc], nil )
105         client.install_local_pkg( option[:pkg], option[:f] ) 
106 when "uninstall" then
107     client = Client.new( nil, option[:loc], nil )
108     client.uninstall( option[:pkg], option[:t] )
109 when "upgrade" then
110     client = Client.new( option[:url], option[:loc], nil )
111     if not option[:url].nil? then
112         client.update()
113     end
114     client.upgrade( option[:os], option[:t] )
115 when "check-upgrade" then
116     client = Client.new( option[:url], option[:loc], nil )
117     if not option[:url].nil? then
118         client.update()
119     end
120     client.check_upgrade( option[:os] )
121 when "show-rpkg" then
122     client = Client.new( option[:url], nil, nil )
123     if not option[:url].nil? then
124         client.update()
125     end
126         puts client.show_pkg_info( option[:pkg], option[:os] ) 
127 when "list-rpkg" then
128     client = Client.new( option[:url], nil, nil )
129     if not option[:url].nil? then
130         client.update()
131     end
132         result = client.show_pkg_list( option[:os] )
133     if not result.nil? and not result.empty? then
134         result.each do |i|
135             name = i[0].strip
136             version = i[1].strip
137             desc = i[2].strip
138             puts name + "  (" + version + ")"
139         end
140     end
141 when "show-lpkg" then
142     client = Client.new( nil, option[:loc], nil )
143     puts client.show_installed_pkg_info( option[:pkg] )
144 when "list-lpkg" then
145     client = Client.new( nil, option[:loc], nil )
146         result = client.show_installed_pkg_list()
147     if not result.nil? and not result.empty? then
148         result.each do |i|
149             name = i[0].strip
150             version = i[1].strip
151             desc = i[2].strip
152             puts name + "  (" + version + ")"
153         end
154     else 
155         puts "Info: There is no any package."
156     end
157 when "build-dep" then
158     client = Client.new( nil, nil, nil )
159         result = client.get_build_dependent_packages( option[:pkg], option[:os], true )
160     ret = ""
161     result.each do |i|
162         ret = ret + i + " --> "
163     end
164     ret = ret.strip
165     ret[-3..-1] = ""
166     puts ret
167 when "install-dep" then
168     client = Client.new( nil, nil, nil )
169         result = client.get_install_dependent_packages( option[:pkg], option[:os], true, false )
170     ret = ""
171     result.each do |i|
172         ret = ret + i + " --> "
173     end
174     ret = ret.strip
175     ret[-3..-1] = ""
176     puts ret
177 else
178         raise RuntimeError, "input option incorrect : #{option[:cmd]}"
179 end
180