[Title] Do not access remote server when working on local
authordonghyuk.yang <donghyuk.yang@samsung.com>
Tue, 12 Feb 2013 07:00:34 +0000 (16:00 +0900)
committerdonghyuk.yang <donghyuk.yang@samsung.com>
Tue, 12 Feb 2013 07:00:34 +0000 (16:00 +0900)
pkg-cli
src/pkg_server/client.rb
src/pkg_server/downloader.rb

diff --git a/pkg-cli b/pkg-cli
index f2d2e8b36f7788c75754010cfa6254ca230dc345..eff2d9d16bbc10b30605fa960e7ccc8e9b659953 100755 (executable)
--- a/pkg-cli
+++ b/pkg-cli
@@ -66,49 +66,36 @@ when "update" then
        client = Client.new( option[:url], nil, nil )
        #client.update()
 when "clean" then
-       client = Client.new( nil, option[:loc], nil )
+       client = Client.new( nil, option[:loc], nil, false )
        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 "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( option[:url], option[:loc], nil )
-       client.install_local_pkg( option[:pkg], option[:t], option[:f] )
+       if option[:t] then
+               client = Client.new( option[:url], option[:loc], nil )
+               client.install_local_pkg( option[:pkg], option[:t], option[:f] )
+       else
+               client = Client.new( nil, option[:loc], nil, false )
+               client.install_local_pkg( option[:pkg], option[:t], option[:f] )
+       end                     
 when "uninstall" then
-       client = Client.new( nil, option[:loc], nil )
+       client = Client.new( nil, option[:loc], nil, false )
        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|
@@ -119,10 +106,10 @@ when "list-rpkg" then
                end
        end
 when "show-lpkg" then
-       client = Client.new( nil, option[:loc], nil )
+       client = Client.new( nil, option[:loc], nil, false )
        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, false )
        result = client.show_installed_pkg_list()
        if not result.nil? and not result.empty? then
                result.each do |i|
index 87d7ca67d1a68d6990e14d8fa009b6edb3bcfa59..c30e0cc35fbcfa3a191a77097c930c6e5d2aa7ae 100644 (file)
@@ -56,7 +56,7 @@ class Client
        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"
+       #DEFAULT_SERVER_ADDR = "http://172.21.17.55/dibs/unstable"
        OS_INFO_FILE = "os_info"
        ARCHIVE_PKG_LIST_FILE = "archive_pkg_list"
 
@@ -67,7 +67,7 @@ class Client
        # 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)
+       def initialize(server_addr, location, logger, access_svr = true)
 
                # set log
                if logger.nil? or logger.class.to_s.eql? "String" then
@@ -78,56 +78,77 @@ class Client
 
                # 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 location
                if location.nil? then location = get_default_inst_dir() end
 
-               # chop server address, if end with "/"
-               if server_addr.strip.end_with? "/" then server_addr = server_addr.chop end
-
+               @location = location
                @snapshot_path = nil
                @snapshot_url = false
-
-               if is_snapshot_url(server_addr) then
-                       @snapshot_url = true
-                       @server_addr, @snapshot_path = split_addr_and_snapshot(server_addr)
-               else
-                       @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)
                @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"
+               @server_addr = nil
 
-               # 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
+
+               # if client should access remote server, set server information
+               if access_svr then
+                       # if server address is nil, get a previous server address                               
+                       if server_addr.nil? then 
+                               server_addr = get_default_server_addr()
+                               if not server_addr.nil? then
+                                       @log.info "Get default server address from config file [#{server_addr}]"
+                               end                                     
+                       end
+
+                       if not server_addr.nil? then
+                               # chop server address, if end with "/"
+                               if server_addr.strip.end_with? "/" then server_addr = server_addr.chop end
+
+                               if is_snapshot_url(server_addr) then
+                                       @snapshot_url = true
+                                       @server_addr, @snapshot_path = split_addr_and_snapshot(server_addr)
+                               else
+                                       @server_addr = server_addr
+                               end
+                               @is_server_remote = Utils.is_url_remote(server_addr)
+                               @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
+                               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
+                       end             
+
+                       # read remote pkg list, and hash list
+                       @log.info "Update remote package list and supported os list.."
+                       if update() then 
+                               @log.info "Initialize - #{server_addr}, #{location}" 
+                       else 
+                               @log.error "Failed to update remote package list."                                      
+                       end
+               end
 
                # 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()
-
-               # read remote pkg list, and hash list
-               @log.info "Update remote package list and supported os list.."
-               update()
-               @log.info "Initialize - #{server_addr}, #{location}"
        end
 
        public
        # update package list from server
        def update()
+
+               if @server_addr.nil? then
+                       @log.warn "Server address is null"
+                       return false
+               end                             
+
                if not @snapshot_url then
                        $get_snapshot_mutex.synchronize do
                                @snapshot_path = get_lastest_snapshot(@is_server_remote)
@@ -135,7 +156,7 @@ class Client
                end
                @log.info "The lastest snapshot : #{@snapshot_path}"
                if @snapshot_path.nil? then
-                       @log.warn "Failed to get the lastest package list"
+                       @log.warn "Failed to get the lastest package list."
                        @snapshot_path = ""
                end
 
@@ -144,12 +165,12 @@ class Client
                        @log.info "Snapshot information is already cached [#{get_pkglist_path()}]"
                        exists_snapshot = true
                else
-                       @log.info "Snapshot information is not cached"
+                       @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"
+                       @log.error "Failed to get package list path."
                        return false
                end
 
@@ -189,7 +210,11 @@ class Client
                end
 
                $update_mutex.synchronize do
-                       create_default_config(@server_addr)
+                       if not create_default_config(@server_addr) then
+                               @log.warn "Config file can not be created."
+                       else
+                               @log.info "Config file is created."                                     
+                       end
                        @log.info "Update package list from \"#{@server_addr}\".. OK"
                end
 
@@ -793,11 +818,13 @@ class Client
                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
+               if not File.exist? filepath then return nil end
+
+               #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|
@@ -808,7 +835,7 @@ class Client
                        end
                end
 
-               if server_addr.nil? then create_default_config(DEFAULT_SERVER_ADDR) end
+               #if server_addr.nil? then create_default_config(DEFAULT_SERVER_ADDR) end
                return server_addr
        end
 
@@ -821,8 +848,12 @@ class Client
        private
        # create default config file (Utils::HOME/.build_tools/client/config)
        def create_default_config(server_addr)
+               if server_addr.nil? then
+                       return false                            
+               end                             
+
                filepath = "#{CONFIG_PATH}/config"
-               if server_addr.nil? then server_addr = DEFAULT_SERVER_ADDR end
+               #if server_addr.nil? then server_addr = DEFAULT_SERVER_ADDR end
 
                if File.exist? filepath then
                        FileUtils.rm_f(filepath)
@@ -833,6 +864,8 @@ class Client
                File.open(filepath, "a+") do |file|
                        file.puts "DEFAULT_SERVER_ADDR : #{server_addr}"
                end
+
+               return true
        end
 
        public
index b5dd1ec9ce01f57ccc52a0a4552b43a57bf73fe0..fafefc40212937b25e6248557204fd91ab766988 100644 (file)
@@ -45,9 +45,15 @@ class FileDownLoader
 
                logger.info "Downloading #{url}"
                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")
+                       if logger.path.nil? or logger.path.empty? then
+                               ret = system "wget #{url} -O #{fullpath} -nv --tries=3"
+                               puts ret                                
+                       else                            
+                               pid,status = Utils.execute_shell_with_log( "wget #{url} -O #{fullpath} -nv --tries=3", logger.path )
+                               if not status.nil? then
+                                       ret = (status.exitstatus != 0) ? false : true
+                               end
+                       end                             
                else
                        if not File.exist? url then
                                logger.error "\"#{url}\" file does not exist"