From: hataejun Date: Fri, 24 Aug 2012 02:39:51 +0000 (+0900) Subject: [Title] update packageserver sync and generate empty file X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c5736f29bb7a4443793c640e76f73e6cac5a2038;p=sdk%2Ftools%2Fsdk-build.git [Title] update packageserver sync and generate empty file [Type] [Module] [Priority] [Jira#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] --- diff --git a/src/pkg_server/packageServer.rb b/src/pkg_server/packageServer.rb index ba7d8b9..48dd649 100644 --- a/src/pkg_server/packageServer.rb +++ b/src/pkg_server/packageServer.rb @@ -49,8 +49,7 @@ class PackageServer # constant SERVER_ROOT = "#{PackageServerConfig::CONFIG_ROOT}/pkg_server" - LOCK_FILE = "#{SERVER_ROOT}/.server_loc" - AUTO_SYNC_CHK_FILE = "#{SERVER_ROOT}/auto_sync" + DIBS_LOCK_FILE_PATH = "#{SERVER_ROOT}/.server_loc" # initialize def initialize (id) @@ -78,7 +77,7 @@ class PackageServer end # create - def create (id, dist_name, server_url, loc = nil ) + def create( id, dist_name, server_url, loc = nil ) update_config_information(id) if loc.nil? or loc.empty? then @@ -102,7 +101,7 @@ class PackageServer end # create locking file - @lock_file = Utils.file_lock(LOCK_FILE) + lock_file = Utils.file_lock(DIBS_LOCK_FILE_PATH) # create server config directory FileUtils.mkdir_p @config_dir @@ -128,7 +127,7 @@ class PackageServer FileUtils.mkdir_p "#{@location}" create_distribution_struct( dist_name, server_url ) - Utils.file_unlock(@lock_file) + Utils.file_unlock(lock_file) @log.output( "package server [#{@id}] created successfully", Log::LV_USER ) end @@ -290,7 +289,7 @@ class PackageServer end def add_distribution( dist_name, server_url, clone ) - @lock_file = Utils.file_lock(LOCK_FILE) + 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 @@ -319,7 +318,7 @@ class PackageServer add_dist_for_config_file(dist_name, server_url, clone) create_distribution_struct( dist_name, server_url ) - Utils.file_unlock(@lock_file) + Utils.file_unlock(lock_file) @log.output( "distribution [#{dist_name}] added successfully", Log::LV_USER ) end @@ -341,7 +340,7 @@ class PackageServer def remove_server() @log.info( "Package server [#{@id}] will be removed and all server information delete", Log::LV_USER) - @lock_file = Utils.file_lock(LOCK_FILE) + lock_file = Utils.file_lock(DIBS_LOCK_FILE_PATH) if File.exist? @config_file_path then File.open @config_file_path do |f| f.each_line do |l| @@ -359,7 +358,7 @@ class PackageServer FileUtils.rm_rf @config_dir FileUtils.rm_rf @log_file_path - Utils.file_unlock(@lock_file) + Utils.file_unlock(lock_file) @log.output( "package server [#{@id}] removed successfully", Log::LV_USER ) end @@ -367,7 +366,7 @@ class PackageServer @log.info "remove distribution in server" distribution = get_distribution( dist_name ) - @lock_file = Utils.file_lock(LOCK_FILE) + lock_file = Utils.file_lock(@server_lock_file_path) # modify config file config_file = File.readlines(@config_file_path) @@ -404,14 +403,14 @@ class PackageServer # remove distribution struct @distribution_list.delete distribution - Utils.file_unlock(@lock_file) + Utils.file_unlock(lock_file) end def remove_pkg( dist_name, pkg_name_list, os ) @log.info "package remove in server" distribution = get_distribution( dist_name ) - @lock_file = Utils.file_lock(LOCK_FILE) + lock_file = Utils.file_lock(@server_lock_file_path) distribution.remove_pkg(pkg_name_list, os) @@ -419,7 +418,7 @@ class PackageServer @log.info "generaging snapshot" distribution.generate_snapshot("", "", false) - Utils.file_unlock(@lock_file) + Utils.file_unlock(lock_file) @log.output( "package removed successfully", Log::LV_USER ) end @@ -427,18 +426,18 @@ class PackageServer @log.info "remove snapshot in server" distribution = get_distribution( dist_name ) - @lock_file = Utils.file_lock(LOCK_FILE) + lock_file = Utils.file_lock(@server_lock_file_path) distribution.remove_snapshot(snapshot_list) - Utils.file_unlock(@lock_file) + Utils.file_unlock(lock_file) end def clean( dist_name, snapshot_list ) @log.info "pakcage server clean" distribution = get_distribution( dist_name ) - @lock_file = Utils.file_lock(LOCK_FILE) + lock_file = Utils.file_lock(@server_lock_file_path) distribution.clean( snapshot_list ) @@ -446,7 +445,7 @@ class PackageServer FileUtils.rm_rf incoming_path FileUtils.mkdir incoming_path - Utils.file_unlock(@lock_file) + Utils.file_unlock(lock_file) end # start server daemon @@ -511,30 +510,33 @@ class PackageServer end def self.list_id - lock_file = Utils.file_lock(LOCK_FILE) @@log = PackageServerLog.new("#{SERVER_ROOT}/.log") d = Dir.new( SERVER_ROOT ) 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 + server_list.push id @@log.output( id, Log::LV_USER) end @@log.close FileUtils.rm_rf("#{SERVER_ROOT}/.log") - Utils.file_unlock(lock_file) + + return server_list end def self.list_dist( id ) - lock_file = Utils.file_lock(LOCK_FILE) @@log = PackageServerLog.new( "#{SERVER_ROOT}/.log" ) @@log.output( "=== ID [#{id}]'s distribution list ===", Log::LV_USER) + dist_list = [] + # read package id information config_file_path = "#{SERVER_ROOT}/#{id}/config" if not File.exist? config_file_path @@ -544,13 +546,17 @@ class PackageServer File.open config_file_path do |f| f.each_line do |l| if l.start_with?( "server_url : ") and l.include?( "->" ) then - @@log.output( l.split(" : ")[1].split("->")[0], Log::LV_USER) + dist_name = l.split(" : ")[1].split("->")[0] + + dist_list.push dist_name + @@log.output( dist_name, Log::LV_USER) end end end @@log.close FileUtils.rm_rf("#{SERVER_ROOT}/.log") - Utils.file_unlock(lock_file) + + return dist_list end def get_default_dist_name() @@ -562,11 +568,11 @@ class PackageServer def reload_dist_package() # create locking file - @lock_file = Utils.file_lock(LOCK_FILE) + lock_file = Utils.file_lock(@server_lock_file_path) @distribution_list.each do |dist| dist.initialize_pkg_list end - Utils.file_unlock(@lock_file) + Utils.file_unlock(lock_file) end def release_lock_file @@ -645,8 +651,10 @@ class PackageServer FileUtils.mkdir "#{@location}/#{dist_name}/source" FileUtils.mkdir "#{@location}/#{dist_name}/temp" FileUtils.mkdir "#{@location}/#{dist_name}/snapshots" - File.open("#{@location}/#{dist_name}/snapshot.info", "w") do |f| end - + File.open("#{@location}/#{dist_name}/#{Distribution::SNAPSHOT_INFO_FILE}", "w") {} + File.open("#{@location}/#{dist_name}/#{Distribution::OS_INFO_FILE}", "w") {} + File.open("#{@location}/#{dist_name}/#{Distribution::ARCHIVE_PKG_FILE}", "w") {} + # generate distribution distribution = Distribution.new( dist_name, "#{@location}/#{dist_name}", server_url, self ) @@ -661,11 +669,9 @@ class PackageServer else @log.info "[#{dist_name}] distribution creation. using local server [#{server_url}]" end - - ret = distribution.sync(false) - if ret then - distribution.generate_snapshot("", "", false) - end + + distribution.sync(false) + distribution.generate_snapshot("", "", false) else @log.info "generate package server do not using remote package server" @@ -721,5 +727,6 @@ class PackageServer @log_file_path = "#{SERVER_ROOT}/#{@id}.log" @config_file_path = "#{@config_dir}/config" @incoming_path = "#{@config_dir}/incoming" + @server_lock_file_path = "#{@config_dir}/.server_lock" end end