Skip to content

Commit

Permalink
add basic qnx support for train (#203)
Browse files Browse the repository at this point in the history
* add basic qnx support for train

Signed-off-by: Christoph Hartmann <[email protected]>

* lint

Signed-off-by: Dominik Richter <[email protected]>
  • Loading branch information
chris-rock authored and arlimus committed Oct 14, 2017
1 parent 8fb6a6b commit 38e0fde
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/train/extras.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Train::Extras
require 'train/extras/file_common'
require 'train/extras/file_unix'
require 'train/extras/file_aix'
require 'train/extras/file_qnx'
require 'train/extras/file_linux'
require 'train/extras/file_windows'
require 'train/extras/os_common'
Expand Down
34 changes: 34 additions & 0 deletions lib/train/extras/file_qnx.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# encoding: utf-8
# author: Christoph Hartmann
# author: Dominik Richter

module Train::Extras
class QnxFile < UnixFile
def content
cat = 'cat'
cat = '/proc/boot/cat' if @backend.os[:release].to_i >= 7
@content ||= case
when !exist?
nil
else
@backend.run_command("#{cat} #{@spath}").stdout || ''
end
end

def type
if @backend.run_command("file #{@spath}").stdout.include?('directory')
return :directory
else
return :file
end
end

%w{
mode owner group uid gid mtime size selinux_label link_path mounted stat
}.each do |field|
define_method field.to_sym do
fail NotImplementedError, "QNX does not implement the #{m}() method yet."
end
end
end
end
2 changes: 1 addition & 1 deletion lib/train/extras/os_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def to_hash

OS['linux'] = %w{linux alpine arch coreos exherbo gentoo slackware fedora amazon} + OS['redhat'] + OS['debian'] + OS['suse']

OS['unix'] = %w{unix aix hpux} + OS['linux'] + OS['solaris'] + OS['bsd']
OS['unix'] = %w{unix aix hpux qnx} + OS['linux'] + OS['solaris'] + OS['bsd']

# Helper methods to check the OS type
# Provides methods in the form of: linux?, unix?, solaris? ...
Expand Down
6 changes: 6 additions & 0 deletions lib/train/extras/os_detect_unix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def detect_via_uname # rubocop:disable Metrics/AbcSize
@platform[:name] = uname_s.lines[0].chomp
@platform[:release] = uname_r.lines[0].chomp

when /qnx/
@platform[:family] = 'qnx'
@platform[:name] = uname_s.lines[0].chomp.downcase
@platform[:release] = uname_r.lines[0].chomp
@platform[:arch] = uname_m

when /sunos/
detect_solaris
else
Expand Down
2 changes: 2 additions & 0 deletions lib/train/transports/ssh_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def file(path)
AixFile.new(self, path)
elsif os.solaris?
UnixFile.new(self, path)
elsif os[:name] == 'qnx'
QnxFile.new(self, path)
else
LinuxFile.new(self, path)
end
Expand Down

0 comments on commit 38e0fde

Please sign in to comment.