[Title]Add option
authorshihyun.kim <shihyun.kim@samsung.com>
Fri, 29 Mar 2013 06:30:48 +0000 (15:30 +0900)
committershihyun.kim <shihyun.kim@samsung.com>
Fri, 29 Mar 2013 06:30:48 +0000 (15:30 +0900)
[Desc.]
* Add snapshotlist option
** ./pkg-cli snapshotlist -u <url> [--all]
[Issue] #8870

Change-Id: I83d708bb629e7250c8fea6f6fd44eadcfa24f725

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

diff --git a/pkg-cli b/pkg-cli
index 9cbb4c8ac84bca6825b73663fc7578e2d6bd635e..ee0739a817ad4f735c0991f0087cf42cbf4f1022 100755 (executable)
--- a/pkg-cli
+++ b/pkg-cli
@@ -149,6 +149,12 @@ when "install-dep" then
 when "register" then
        client = Client.new( nil, nil, nil )
        client.register(option[:address], option[:dist], option[:pkg], option[:passwd])
+when "snapshotlist" then
+ client = Client.new(option[:url],nil,nil);
+ client.printSnapshotList(option[:all]);
+when "changelog" then
+  client = Client.new(option[:url], nil, nil);
+  client.printChangeLog();
 else
        raise RuntimeError, "Input is incorrect : #{option[:cmd]}"
 end
diff --git a/src/common/PropertyParser.rb b/src/common/PropertyParser.rb
new file mode 100644 (file)
index 0000000..b383ff2
--- /dev/null
@@ -0,0 +1,39 @@
+#$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common/model"
+require 'model/Property'
+
+class PropertyParser
+  attr_accessor (:seperate)
+  def initialize(seperate)
+    if (seperate.nil?())
+      @seperate = ":";
+    else 
+      @seperate = seperate;
+    end
+  end
+  
+  public
+  def parseFile(filePath)
+    propertySection = Array.new;
+    properties = Array.new;
+    
+    f = File.open(filePath,"r");
+    f.each_line do |line|
+      if (line.empty? || line.eql?("\n")) then
+        if not properties.empty?() then
+          propertySection.push(properties);
+          properties = Array.new
+        end
+      else
+        sepLine = line.split(@seperate);
+        properties.push(Property.new(sepLine[0].strip, sepLine[1].strip))
+      end
+      
+    end
+    
+    if (not properties.empty?) then
+      propertySection.push(properties);
+    end
+    
+    return propertySection;
+  end
+end
\ No newline at end of file
diff --git a/src/common/model/Property.rb b/src/common/model/Property.rb
new file mode 100644 (file)
index 0000000..75cb749
--- /dev/null
@@ -0,0 +1,8 @@
+class Property
+  attr_accessor(:key, :value)
+  
+  def initialize(key, value)
+    @key = key;
+    @value = value;
+  end
+end
\ No newline at end of file
diff --git a/src/pkg_server/ChangeLogController.rb b/src/pkg_server/ChangeLogController.rb
new file mode 100644 (file)
index 0000000..31a28c5
--- /dev/null
@@ -0,0 +1,2 @@
+class ChangeLogController
+end
\ No newline at end of file
diff --git a/src/pkg_server/PackageServerConstants.rb b/src/pkg_server/PackageServerConstants.rb
new file mode 100644 (file)
index 0000000..0bca44e
--- /dev/null
@@ -0,0 +1,12 @@
+class PackageServerConstants
+  CHANGE_LOG_PATH_FROM_DISTRIBUTION = "changes"
+  DISTRIBUTION_INFO_FILE_NAME = "distribution.info"
+  
+  #snapshot information
+  SNAPSHOT_INFO_FILE_NAME = "snapshot.info"
+  SNAPSHOT_NAME_FIELD = "name"
+  SNAPSHOT_TIME_FIELD = "time"
+  SNAPSHOT_TYPE_FIELD = "type"
+  SNAPSHOT_PATH_FIELD = "path"
+  SNAPSHOT_MANUAL_TYPE_VALUE = "manual"
+end
\ No newline at end of file
diff --git a/src/pkg_server/SnapshotController.rb b/src/pkg_server/SnapshotController.rb
new file mode 100644 (file)
index 0000000..05c3bb0
--- /dev/null
@@ -0,0 +1,43 @@
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+require "PropertyParser"
+require "PackageServerConstants"
+require 'model/snapshot'
+  
+class SnapshotController
+  attr_accessor :snapshotList
+  def initialize(snapshotFilePath)
+    @snapshotList = Array.new
+      
+    loadSnapshot(snapshotFilePath)
+  end
+  
+  public
+  def getAllSnapshotList
+    return @snapshotList
+  end
+  
+  public
+  def getManualSnapshotList
+    manualSnapshotList = Array.new
+    
+    @snapshotList.each() do |snapshot|
+      if (snapshot.getValue(PackageServerConstants::SNAPSHOT_TYPE_FIELD).eql?(PackageServerConstants::SNAPSHOT_MANUAL_TYPE_VALUE)) then
+        manualSnapshotList.push(snapshot[name])
+      end
+    end
+    
+    return manualSnapshotList
+  end
+  
+  private
+  def loadSnapshot(snapshotPath)
+    parser = PropertyParser.new(nil)
+    propertySection = parser.parseFile(snapshotPath);
+    
+    propertySection.each() do |properties|
+      snapshot = Snapshot.new(properties)
+      @snapshotList.push(snapshot);
+    end
+    
+  end
+end
\ No newline at end of file
index d820c2c5d915555e07671b926ac4eb76250a1c55..195833319e7bd400191c1e3bd66981f19d42b4ee 100644 (file)
@@ -44,6 +44,8 @@ require "BuildComm"
 require "FileTransferViaFTP"
 require "FileTransferViaDirect"
 require 'digest'
+require "SnapshotController"
+require 'PackageServerConstants'
 
 
 $update_mutex = Mutex.new
@@ -1872,5 +1874,39 @@ class Client
 
                if ret then @log.info "Snapshot is generated : #{ret}" end
        end
-
+       
+       ##Print change log to console.
+       public
+       def printChangeLog(snapshot1 = nil, snapshot2 = nil)
+         changeLogController = ChangeLogController.new()
+         if (snapshot1.nil?()) then
+           changeLogController.getRecentLog();
+         elsif snapshot2.nil?() then
+           changeLogController.getLog(snapshot1);
+         else
+           changeLogController.getLog(snapshot1, snapshot2);
+         end
+         
+       end
+       
+       ##Print snapshot list to console.
+       public
+       def printSnapshotList(showAll=false)
+         snapshotPath = File.join(@config_dist_path, PackageServerConstants::SNAPSHOT_INFO_FILE_NAME)
+         @log.info("Read information of snapshot from " + snapshotPath);
+         
+         ssController = SnapshotController.new(snapshotPath);
+         if showAll then
+           result = ssController.getAllSnapshotList;
+         else
+           result = ssController.getManualSnapshotList ;
+         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
+         end
+           
+       end
 end
index dd5caa8bbc8ca22a1d0993225d1cd37b2e516eff..804ea9af0a73b44307b608edb6245b29c241e8df 100644 (file)
@@ -34,6 +34,7 @@ def set_default( options )
        if options[:t].nil? then options[:t] = false end
        if options[:f].nil? then options[:f] = false end
        if options[:v].nil? then options[:v] = false end
+ if options[:all].nil? then options[:all] = false end
 end
 
 def option_error_check( options )
@@ -109,6 +110,11 @@ def option_error_check( options )
                                options[:dist].nil? or options[:dist].empty? then
                        raise ArgumentError, "Usage: pkg-cli register -P <package file path> -a <server address> -d <distribution name> -w <password>"
                end
+       when "snapshotlist"
+  if options[:url].nil? or options[:url].empty? then
+    raise ArgumentError, "Usage: pkg-cli install-dep -P <package name> -u <package server url> [-o <os>]"
+  end
+       when "changelog"
 
        else
                raise ArgumentError, "Input is incorrect : #{options[:cmd]}"
@@ -201,6 +207,10 @@ def option_parse
                        puts "DIBS(Distributed Intelligent Build System) version " + Utils.get_version()
                        exit
                end
+               
+               opts.on('--all', 'show all information') do
+                 options[:all] = true
+               end
 
        end
 
@@ -214,6 +224,8 @@ def option_parse
                cmd.eql? "upgrade" or cmd.eql? "check-upgrade" or
                cmd.eql? "build-dep" or cmd.eql? "install-dep" or
                cmd.eql? "register" or
+               cmd.eql?("changelog") or
+               cmd.eql?("snapshotlist") or
                cmd =~ /(-v)|(--version)/  or
                cmd =~ /(help)|(-h)|(--help)/  then
 
diff --git a/src/pkg_server/model/distribution.rb b/src/pkg_server/model/distribution.rb
new file mode 100644 (file)
index 0000000..7253daa
--- /dev/null
@@ -0,0 +1,9 @@
+  
+class Distribution
+  attr_accessor :name, :time
+  
+  def initialize(name, time)
+    @name = name
+    @time = time
+  end
+end
\ No newline at end of file
diff --git a/src/pkg_server/model/snapshot.rb b/src/pkg_server/model/snapshot.rb
new file mode 100644 (file)
index 0000000..6d6a41f
--- /dev/null
@@ -0,0 +1,20 @@
+
+
+class Snapshot
+  attr_accessor :properties    
+  
+  def initialize(properties)
+    @properties = properties;
+  end                        
+  
+  public 
+  def getValue(key)
+    properties.each() do |property|
+      if property.key().eql?(key) then
+        return property.value()
+      end
+    end
+    
+    return nil;
+  end
+end
\ No newline at end of file