From: shihyun.kim Date: Tue, 2 Apr 2013 07:26:06 +0000 (+0900) Subject: [Title]Add changeLog option X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=33138d0b8592465cb58f81ee9df15db611392d13;p=sdk%2Ftools%2Fsdk-build.git [Title]Add changeLog option [Desc.] * ./pkg-cli changeLog -u url [-s snapshotName1,snapshotName2] [Issue] Change-Id: I8ab79ad2a3df1b1440d9fb9be9f6cb410be7c458 --- diff --git a/pkg-cli b/pkg-cli index ee0739a..12f3b72 100755 --- a/pkg-cli +++ b/pkg-cli @@ -154,7 +154,11 @@ when "snapshotlist" then client.printSnapshotList(option[:all]); when "changelog" then client = Client.new(option[:url], nil, nil); - client.printChangeLog(); + if option[:snapshot].nil?() then + client.printChangeLog(); + else + client.printChangeLog(option[:snapshot][0], option[:snapshot][1]); + end else raise RuntimeError, "Input is incorrect : #{option[:cmd]}" end diff --git a/src/common/FileUtil.rb b/src/common/FileUtil.rb new file mode 100644 index 0000000..ab1c4a5 --- /dev/null +++ b/src/common/FileUtil.rb @@ -0,0 +1,16 @@ +class FileUtil + public + def FileUtil.getFileNameFromURL(url) + fileName = url.split('/')[-1] + return fileName + end + + public + def FileUtil.getFlatURL(url) + if url.nil? or url.empty? then + return "" + end + + return url.delete(".:/@") + end +end \ No newline at end of file diff --git a/src/pkg_server/ChangeLogController.rb b/src/pkg_server/ChangeLogController.rb index 31a28c5..2c362c5 100644 --- a/src/pkg_server/ChangeLogController.rb +++ b/src/pkg_server/ChangeLogController.rb @@ -1,2 +1,100 @@ +require "SnapshotController" +require "PackageServerConstants" +require "ftools" + +$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common" +require "FileUtil" + class ChangeLogController + def initialize(serverURL, ssController) + @serverUrl = serverURL + @ssController = ssController + end + + ##Get + public + def getLatestChangeLog() + recentSnapshotName = @ssController.getLatestSnapshot().getName(); + return getChangeLog(recentSnapshotName) + end + + public + def getChangeLog(snapshotName) + logPath = downloadChangeLog(snapshotName) + + if (logPath.nil?() || !File.exist?(logPath)) then + return; + end + + + return loadChangeLog(logPath); + end + + public + def getTotalChangeLog(startSnapshotName, endSnapshotName) + if (endSnapshotName.nil?()) + return; + elsif (endSnapshotName.nil?()) + return getChangeLog(startSnapshot); + else + changeLog = String.new + + totalSnapshotList = @ssController.getTotalSnapshotName(startSnapshotName,endSnapshotName) + totalSnapshotList.each() do |snapshotName| + changeLog = changeLog + getChangeLog(snapshotName) + "\n" + end + + return changeLog + end + end + + private + def downloadChangeLog(snapshotName) + changeLogURLPath = getChangeLogURLPath(snapshotName) + + localPath = getChangeLogPath() + + File.makedirs(localPath) + + logger = DummyLog.new() + + if (FileDownLoader.download(changeLogURLPath,localPath,logger)) then + return File.join(localPath, getChangeLogFile(snapshotName)) + else + return nil + end + end + + private + def getChangeLogPath() + flatServerName = FileUtil.getFlatURL(@serverUrl) + return File.join(PackageServerConfig::CONFIG_PATH, flatServerName, PackageServerConstants::CHANGE_LOG_DIRECTORY_NAME) + end + + private + def getChangeLogURLPath(snapshotName) + changeLogURLPath = File.join(@serverUrl, PackageServerConstants::CHANGE_LOG_DIRECTORY_NAME, getChangeLogFile(snapshotName)); + + return changeLogURLPath + end + + private + def getChangeLogFile(snapshotName) + if (snapshotName.nil?() || snapshotName.empty?()) + return "" + end + return snapshotName + PackageServerConstants::CHANGE_LOG_FILE_EXTENSION + end + + private + def loadChangeLog(logPath) + changeLog = String.new + + file = File.open(logPath,"r") + file.each_line do |line| + changeLog = changeLog + line + end + + return changeLog + end end \ No newline at end of file diff --git a/src/pkg_server/PackageServerConstants.rb b/src/pkg_server/PackageServerConstants.rb index 0bca44e..30a8b49 100644 --- a/src/pkg_server/PackageServerConstants.rb +++ b/src/pkg_server/PackageServerConstants.rb @@ -1,5 +1,9 @@ class PackageServerConstants - CHANGE_LOG_PATH_FROM_DISTRIBUTION = "changes" + #changelog information + CHANGE_LOG_DIRECTORY_NAME = "changes" + CHANGE_LOG_FILE_EXTENSION = ".log" + + #distribution information DISTRIBUTION_INFO_FILE_NAME = "distribution.info" #snapshot information diff --git a/src/pkg_server/SnapshotController.rb b/src/pkg_server/SnapshotController.rb index 05c3bb0..cc9eb81 100644 --- a/src/pkg_server/SnapshotController.rb +++ b/src/pkg_server/SnapshotController.rb @@ -7,6 +7,10 @@ class SnapshotController attr_accessor :snapshotList def initialize(snapshotFilePath) @snapshotList = Array.new + + if (File.directory? snapshotFilePath) then + snapshotFilePath = File.join(snapshotFilePath, PackageServerConstants::SNAPSHOT_INFO_FILE_NAME) + end loadSnapshot(snapshotFilePath) end @@ -21,7 +25,7 @@ class SnapshotController manualSnapshotList = Array.new @snapshotList.each() do |snapshot| - if (snapshot.getValue(PackageServerConstants::SNAPSHOT_TYPE_FIELD).eql?(PackageServerConstants::SNAPSHOT_MANUAL_TYPE_VALUE)) then + if (snapshot.getType().eql?(PackageServerConstants::SNAPSHOT_MANUAL_TYPE_VALUE)) then manualSnapshotList.push(snapshot[name]) end end @@ -29,8 +33,39 @@ class SnapshotController return manualSnapshotList end + public + def getLatestSnapshot + return @snapshotList.pop() + end + + public + def getTotalSnapshotName(startSnapshotName, endSnapshotName) + totalSnapshotList = Array.new + + @snapshotList.each() do |snapshot| + snapshotName = snapshot.getName() + if (snapshotName.eql?(startSnapshotName) || snapshotName.eql?(endSnapshotName)) then + if (totalSnapshotList.empty?) then + totalSnapshotList.push(snapshotName) + else + break + end + end + + if (not totalSnapshotList.empty?) then + totalSnapshotList.push(snapshotName) + end + end + + return totalSnapshotList + end + private def loadSnapshot(snapshotPath) + if not File.exist?(snapshotPath) then + return; + end + parser = PropertyParser.new(nil) propertySection = parser.parseFile(snapshotPath); diff --git a/src/pkg_server/client.rb b/src/pkg_server/client.rb index 1958333..e0593c8 100644 --- a/src/pkg_server/client.rb +++ b/src/pkg_server/client.rb @@ -45,9 +45,11 @@ require "FileTransferViaFTP" require "FileTransferViaDirect" require 'digest' require "SnapshotController" +require "ChangeLogController" require 'PackageServerConstants' + $update_mutex = Mutex.new $get_snapshot_mutex = Mutex.new $cache_mutex = Mutex.new @@ -1878,15 +1880,21 @@ class Client ##Print change log to console. public def printChangeLog(snapshot1 = nil, snapshot2 = nil) - changeLogController = ChangeLogController.new() + snapshotPath = File.join(@config_dist_path, PackageServerConstants::SNAPSHOT_INFO_FILE_NAME) + @log.info("Read information of snapshot from " + snapshotPath); + + ssController = SnapshotController.new(snapshotPath); + changeLogController = ChangeLogController.new(@server_addr, ssController) + if (snapshot1.nil?()) then - changeLogController.getRecentLog(); + changeLog = changeLogController.getLatestChangeLog(); elsif snapshot2.nil?() then - changeLogController.getLog(snapshot1); + changeLog = changeLogController.getChangeLog(snapshot1); else - changeLogController.getLog(snapshot1, snapshot2); + changeLog = changeLogController.getTotalChangeLog(snapshot1, snapshot2); end + puts changeLog end ##Print snapshot list to console. @@ -1903,8 +1911,8 @@ class Client end result.each() do |snapshot| - puts PackageServerConstants::SNAPSHOT_NAME_FIELD + ": " + snapshot.getValue(PackageServerConstants::SNAPSHOT_NAME_FIELD) - puts PackageServerConstants::SNAPSHOT_TIME_FIELD + ": " + snapshot.getValue(PackageServerConstants::SNAPSHOT_TIME_FIELD) + puts PackageServerConstants::SNAPSHOT_NAME_FIELD + ": " + snapshot.getName() + puts PackageServerConstants::SNAPSHOT_TIME_FIELD + ": " + snapshot.getTime() puts end diff --git a/src/pkg_server/clientOptParser.rb b/src/pkg_server/clientOptParser.rb index 804ea9a..10c2cc3 100644 --- a/src/pkg_server/clientOptParser.rb +++ b/src/pkg_server/clientOptParser.rb @@ -137,6 +137,8 @@ def option_parse + "\t" + "list-rpkg Show the all packages in the package-server." + "\n" \ + "\t" + "show-lpkg Show the package in your SDK environment." + "\n" \ + "\t" + "list-lpkg Show the all packages in your SDK environment." + "\n" \ + + "\t" + "snapshotlist Show the snapshot list in your SDK environment." + "\n" \ + + "\t" + "changelog Show the change log in your SDK environment." + "\n" \ + "\t" + "build-dep Show build-dependency packages" + "\n" \ + "\t" + "install-dep Show install-dependency packages" + "\n" \ + "\n" + "Subcommand usage:" + "\n" \ @@ -151,6 +153,8 @@ def option_parse + "\t" + "pkg-cli list-rpkg -u [-o ]" + "\n" \ + "\t" + "pkg-cli show-lpkg -P [-l ]" + "\n" \ + "\t" + "pkg-cli list-lpkg [-l ]" + "\n" \ + + "\t" + "pkg-cli snapshotlist -u [--all]" + "\n" \ + + "\t" + "pkg-cli changelog -u [-snapshot ]" + "\n" \ + "\t" + "pkg-cli build-dep -P -u [-o ]" + "\n" \ + "\t" + "pkg-cli install-dep -P -u [-o ]" + "\n" \ + "\t" + "pkg-cli register -P -a -d -w " + "\n" \ @@ -159,6 +163,7 @@ def option_parse optparse = OptionParser.new(nil, 32, ' '*8) do|opts| # Set a banner, displayed at the top # of the help screen. + opts.banner = banner @@ -211,6 +216,11 @@ def option_parse opts.on('--all', 'show all information') do options[:all] = true end + + opts.on('-s', '--snapshot snapshotName1,snapshotName2', Array, 'snapshot name') do |snapshotName| + puts snapshotName[0], snapshotName[1] + options[:snapshot] = snapshotName + end end diff --git a/src/pkg_server/model/snapshot.rb b/src/pkg_server/model/snapshot.rb index 6d6a41f..baf92f6 100644 --- a/src/pkg_server/model/snapshot.rb +++ b/src/pkg_server/model/snapshot.rb @@ -7,7 +7,7 @@ class Snapshot @properties = properties; end - public + private def getValue(key) properties.each() do |property| if property.key().eql?(key) then @@ -17,4 +17,24 @@ class Snapshot return nil; end + + public + def getName + return getValue(PackageServerConstants::SNAPSHOT_NAME_FIELD) + end + + public + def getTime + return getValue(PackageServerConstants::SNAPSHOT_TIME_FIELD) + end + + public + def getType + return getValue(PackageServerConstants::SNAPSHOT_TYPE_FIELD) + end + + public + def getPath + return getValue(PackageServerConstants::SNAPSHOT_PATH_FIELD) + end end \ No newline at end of file diff --git a/src/pkg_server/packageServerConfig.rb b/src/pkg_server/packageServerConfig.rb index 3c782a6..eaef35a 100644 --- a/src/pkg_server/packageServerConfig.rb +++ b/src/pkg_server/packageServerConfig.rb @@ -30,5 +30,8 @@ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common" require "utils" class PackageServerConfig + CONFIG_ROOT = "#{Utils::HOME}/.build_tools" + CONFIG_PATH = "#{PackageServerConfig::CONFIG_ROOT}/client" + end