Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/linux_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require 'active_support'
require 'active_support/core_ext'

require 'linux_admin/logging'
require 'linux_admin/null_logger'

require 'linux_admin/common'
require 'linux_admin/exceptions'
Expand All @@ -28,5 +30,11 @@

module LinuxAdmin
extend Common
include Common
extend self

attr_writer :logger

def logger
@logger ||= NullLogger.new
end
end
2 changes: 2 additions & 0 deletions lib/linux_admin/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ def cmd(cmd)
end

def run(cmd, options = {})
AwesomeSpawn.logger ||= logger
AwesomeSpawn.run(cmd, options)
end

def run!(cmd, options = {})
AwesomeSpawn.logger ||= logger
AwesomeSpawn.run!(cmd, options)
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/linux_admin/logging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module LinuxAdmin
module Logging
delegate :logger, :to => :LinuxAdmin
end
end
11 changes: 11 additions & 0 deletions lib/linux_admin/null_logger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'logger'

module LinuxAdmin
class NullLogger < Logger
def initialize(*_args)
end

def add(*_args, &_block)
end
end
end
1 change: 1 addition & 0 deletions lib/linux_admin/registration_system.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module LinuxAdmin
class RegistrationSystem
include Common
include Logging

def self.registration_type(reload = false)
return @registration_type if @registration_type && !reload
Expand Down
1 change: 1 addition & 0 deletions lib/linux_admin/registration_system/rhn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def enable_channel(repo, options)
cmd = "rhn-channel -a"
params = user_pwd(options).merge("--channel=" => repo)

logger.info("#{self.class.name}##{__method__} Enabling channel: #{repo}")
run!(cmd, :params => params)
end
alias_method :subscribe, :enable_channel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def enable_repo(repo, options = nil)
cmd = "subscription-manager repos"
params = {"--enable=" => repo}

logger.info("#{self.class.name}##{__method__} Enabling repository: #{repo}")
run!(cmd, :params => params)
end

Expand Down
6 changes: 4 additions & 2 deletions lib/linux_admin/rpm.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module LinuxAdmin
class Rpm < Package
extend Logging

def self.rpm_cmd
Distros.local.command(:rpm)
end
Expand All @@ -16,8 +18,8 @@ def self.list_installed
#
# Rpm.import_key("/etc/pki/my-gpg-key")
def self.import_key(file)
params = {"--import" => file}
run!("rpm", :params => params)
logger.info("#{self.class.name}##{__method__} Importing RPM-GPG-KEY: #{file}")
run!("rpm", :params => {"--import" => file})
end

def self.info(pkg)
Expand Down
2 changes: 1 addition & 1 deletion linux_admin.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ registration, updates, etc.
spec.add_dependency "activesupport", "> 3.2"
spec.add_dependency "inifile"
spec.add_dependency "more_core_extensions", "~> 1.1"
spec.add_dependency "awesome_spawn", "~> 1.2"
spec.add_dependency "awesome_spawn", "~> 1.3"
spec.add_dependency "nokogiri"
end