[DRE-commits] [ruby-aruba] 40/98: Output content of command and filesystem status on request

Hideki Yamane henrich at moszumanska.debian.org
Tue Mar 22 12:20:37 UTC 2016


This is an automated email from the git hooks/post-receive script.

henrich pushed a commit to branch debian/sid
in repository ruby-aruba.

commit 0f55025d994ae7f01ef6a9bba1e9b2a4f9e23fc0
Author: Dennis Günnewig <dg1 at ratiodata.de>
Date:   Mon Jan 4 10:57:37 2016 +0100

    Output content of command and filesystem status on request
---
 features/steps/core/announce.feature     | 53 +++++++++++++++++++++++++
 lib/aruba/cucumber/hooks.rb              |  8 ++++
 lib/aruba/platforms/announcer.rb         |  7 ++++
 lib/aruba/platforms/filesystem_status.rb | 68 ++++++++++++++++++++++++++++++++
 lib/aruba/platforms/unix_platform.rb     |  5 +++
 lib/aruba/processes/basic_process.rb     |  8 ++++
 lib/aruba/processes/spawn_process.rb     | 17 ++++++++
 7 files changed, 166 insertions(+)

diff --git a/features/steps/core/announce.feature b/features/steps/core/announce.feature
index b273abe..24cecae 100644
--- a/features/steps/core/announce.feature
+++ b/features/steps/core/announce.feature
@@ -201,3 +201,56 @@ Feature: Announce output during test run
     """
     $ export MY_VAR=my\ value\ \
     """
+
+  Scenario: Announce file system status of command
+    This will output information like owner, group, atime, mtime, ctime, size,
+    mode and if command is executable.
+
+    Given an executable named "bin/cli" with:
+    """bash
+    #!/usr/bin/env bash
+
+    echo 'Hello World'
+    """
+    And a file named "features/exit_status.feature" with:
+    """cucumber
+    Feature: Announce
+      @announce-command-filesystem-status
+      Scenario: Run command
+        And I run `cli`
+        Then the exit status should be 0
+    """
+    When I run `cucumber`
+    Then the features should all pass
+    And the output should contain:
+    """
+    # mode       => 755
+    """
+    And the output should contain:
+    """
+    # owner
+    """
+    And the output should contain:
+    """
+    # group
+    """
+    And the output should contain:
+    """
+    # ctime
+    """
+    And the output should contain:
+    """
+    # mtime
+    """
+    And the output should contain:
+    """
+    # atime
+    """
+    And the output should contain:
+    """
+    # size
+    """
+    And the output should contain:
+    """
+    # executable
+    """
diff --git a/lib/aruba/cucumber/hooks.rb b/lib/aruba/cucumber/hooks.rb
index 7fd739e..ad088ae 100644
--- a/lib/aruba/cucumber/hooks.rb
+++ b/lib/aruba/cucumber/hooks.rb
@@ -33,6 +33,14 @@ Before('@announce-command') do
   aruba.announcer.activate :command
 end
 
+Before('@announce-command-content') do
+  aruba.announcer.activate :command_content
+end
+
+Before('@announce-command-filesystem-status') do
+  aruba.announcer.activate :command_filesystem_status
+end
+
 Before('@announce-cmd') do
   Aruba.platform.deprecated 'The use of "@announce-cmd"-hook is deprecated. Please use "@announce-command"'
 
diff --git a/lib/aruba/platforms/announcer.rb b/lib/aruba/platforms/announcer.rb
index 31ac2be..4f14393 100644
--- a/lib/aruba/platforms/announcer.rb
+++ b/lib/aruba/platforms/announcer.rb
@@ -79,9 +79,16 @@ module Aruba
         output_format :modified_environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
         output_format :stderr, "<<-STDERR\n%s\nSTDERR"
         output_format :stdout, "<<-STDOUT\n%s\nSTDOUT"
+        output_format :command_content, "<<-COMMAND\n%s\nCOMMAND"
         output_format :stop_signal, proc { |p, s| format('Command will be stopped with `kill -%s %s`', s, p) }
         output_format :timeout, '# %s-timeout: %s seconds'
         output_format :wait_time, '# %s: %s seconds'
+        output_format(
+          :command_filesystem_status, proc do |status|
+          puts 'Command Filesystem Status:'
+          Aruba.platform.simple_table(status.to_h, :sort => false)
+        end
+        )
 
         # rubocop:disable Metrics/LineLength
         if @options[:stdout]
diff --git a/lib/aruba/platforms/filesystem_status.rb b/lib/aruba/platforms/filesystem_status.rb
new file mode 100644
index 0000000..c4b5c0a
--- /dev/null
+++ b/lib/aruba/platforms/filesystem_status.rb
@@ -0,0 +1,68 @@
+require 'forwardable'
+
+module Aruba
+  module Platforms
+    # File System Status object
+    #
+    # This is a wrapper for File::Stat returning only a subset of information.
+    class FilesystemStatus
+      METHODS = [
+        :executable?,
+        :ctime,
+        :atime,
+        :mtime,
+        :size
+      ]
+
+      extend Forwardable
+
+      private
+
+      attr_reader :status
+
+      public
+
+      if RUBY_VERSION >= '1.9.3'
+        def_delegators :@status, *METHODS
+      else
+        def_delegators :@status, :executable?, :ctime, :atime, :mtime, :size
+      end
+
+      def initialize(path)
+        @status = File::Stat.new(path)
+      end
+
+      # Return permissions
+      def mode
+        format("%o", status.mode)[-4,4].gsub(/^0*/, '')
+      end
+
+      # Return owner
+      def owner
+        status.uid
+      end
+
+      # Return owning group
+      def group
+        status.gid
+      end
+
+      # Convert status to hash
+      #
+      # @return [Hash]
+      #   A hash of values
+      def to_h
+        {
+          :owner      => owner,
+          :group      => group,
+          :mode       => mode,
+          :executable => executable?,
+          :ctime      => ctime,
+          :atime      => atime,
+          :mtime      => mtime,
+          :size       => size,
+        }
+      end
+    end
+  end
+end
diff --git a/lib/aruba/platforms/unix_platform.rb b/lib/aruba/platforms/unix_platform.rb
index b199360..6c218e3 100644
--- a/lib/aruba/platforms/unix_platform.rb
+++ b/lib/aruba/platforms/unix_platform.rb
@@ -14,6 +14,7 @@ require 'aruba/platforms/local_environment'
 require 'aruba/platforms/aruba_logger'
 require 'aruba/platforms/announcer'
 require 'aruba/platforms/command_monitor'
+require 'aruba/platforms/filesystem_status'
 
 # Aruba
 module Aruba
@@ -41,6 +42,10 @@ module Aruba
         UnixCommandString
       end
 
+      def filesystem_status
+        FilesystemStatus
+      end
+
       def announcer
         Announcer
       end
diff --git a/lib/aruba/processes/basic_process.rb b/lib/aruba/processes/basic_process.rb
index f607e91..60d1fda 100644
--- a/lib/aruba/processes/basic_process.rb
+++ b/lib/aruba/processes/basic_process.rb
@@ -67,6 +67,14 @@ module Aruba
         NotImplementedError
       end
 
+      def filesystem_status
+        NotImplementedError
+      end
+
+      def content
+        NotImplementedError
+      end
+
       def wait
         NotImplementedError
       end
diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb
index 38f6b21..229300f 100644
--- a/lib/aruba/processes/spawn_process.rb
+++ b/lib/aruba/processes/spawn_process.rb
@@ -232,6 +232,23 @@ module Aruba
         raise CommandAlreadyStoppedError, %(Command "#{commandline}" with PID "#{pid}" has already stopped.)
       end
 
+      # Return file system stats for the given command
+      #
+      # @return [Aruba::Platforms::FilesystemStatus]
+      #   This returns a File::Stat-object
+      def filesystem_status
+        Aruba.platform.filesystem_status.new(command_string.to_s)
+      end
+
+      # Content of command
+      #
+      # @return [String]
+      #   The content of the script/command. This might be binary output as
+      #   string if your command is a binary executable.
+      def content
+        File.read command_string.to_s
+      end
+
       private
 
       def command_string

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-aruba.git



More information about the Pkg-ruby-extras-commits mailing list