[Title]Add changeLog option
authorshihyun.kim <shihyun.kim@samsung.com>
Tue, 2 Apr 2013 07:26:06 +0000 (16:26 +0900)
committershihyun.kim <shihyun.kim@samsung.com>
Tue, 2 Apr 2013 07:26:06 +0000 (16:26 +0900)
[Desc.]
* ./pkg-cli changeLog -u url [-s snapshotName1,snapshotName2]
[Issue]

Change-Id: I8ab79ad2a3df1b1440d9fb9be9f6cb410be7c458

pkg-cli
src/common/FileUtil.rb [new file with mode: 0644]
src/pkg_server/ChangeLogController.rb
src/pkg_server/PackageServerConstants.rb
src/pkg_server/SnapshotController.rb
src/pkg_server/client.rb
src/pkg_server/clientOptParser.rb
src/pkg_server/model/snapshot.rb
src/pkg_server/packageServerConfig.rb

diff --git a/pkg-cli b/pkg-cli
index ee0739a817ad4f735c0991f0087cf42cbf4f1022..12f3b72131967ddcd723ade00321eb8e9e16056e 100755 (executable)
--- 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 (file)
index 0000000..ab1c4a5
--- /dev/null
@@ -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
index 31a28c5c33b4088870b2d5343c36eb1462a46d48..2c362c57886636d57c318c6c4ce91629d14392e2 100644 (file)
@@ -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
index 0bca44eaf3acaf34477d71dfa983c732b072dfae..30a8b495d964c756eb70318c62c659bae716c24e 100644 (file)
@@ -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
index 05c3bb07254d7111ff22952ac2c15902181f0d40..cc9eb8136250d18e6b52710aad3d10b071d449c7 100644 (file)
@@ -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);
     
index 195833319e7bd400191c1e3bd66981f19d42b4ee..e0593c818cee944de30cf7c537bdf695fef914b5 100644 (file)
@@ -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
            
index 804ea9af0a73b44307b608edb6245b29c241e8df..10c2cc3bf27752c2331c1c5be57267da13f5905f 100644 (file)
@@ -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 <package server url> [-o <os>]" + "\n" \
                + "\t" + "pkg-cli show-lpkg -P <package name> [-l <location>]" + "\n"  \
                + "\t" + "pkg-cli list-lpkg [-l <location>]" + "\n" \
+  + "\t" + "pkg-cli snapshotlist -u <package server url> [--all]" + "\n"  \
+  + "\t" + "pkg-cli changelog -u <package server url> [-snapshot <snapshot name,snapshot name>]" + "\n"  \
                + "\t" + "pkg-cli build-dep -P <package name> -u <package server url> [-o <os>]" + "\n" \
                + "\t" + "pkg-cli install-dep -P <package name> -u <package server url> [-o <os>]" + "\n" \
                + "\t" + "pkg-cli register -P <package file path> -a <server address> -d <distribution name> -w <password>" + "\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
 
index 6d6a41fba0b05498b76116d3f32854c8b1245bce..baf92f62890ff2bad2959c9d40091ab9cd3b93ac 100644 (file)
@@ -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
index 3c782a6172413c0e89f1368ac0d46fcd756af002..eaef35a4cb01d9a3fe5b1bd6d979ab77ab13a9bf 100644 (file)
@@ -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