Skip to content
Permalink
Browse files

Improve from code review

  • Loading branch information...
dgdavid committed Aug 20, 2018
1 parent 877d29d commit 0f6ec0b1e7bbb60c97f3bc8df4088aa1c96bd6e1
@@ -144,7 +144,7 @@ def find!(name)
# @param name [String] Service name
# @return [SystemService] System service based on the given name
#
# @see Yast2::Systemd::ServiceClass#build
# @see Yast2::Systemd::Service.build
def build(name)
new(Yast2::Systemd::Service.build(name))
end
@@ -537,7 +537,7 @@ def clear_errors

# Returns the associated socket
#
# @return [Yast::SystemdSocketClass::Socket]
# @return [Yast2::Systemd::Socket]
def socket
service && service.socket
end
@@ -3,5 +3,5 @@
require "yast2/systemd/service"
require "yast2/systemd/socket"

# Systemd control API
module Systemd; end
# Yast2::Systemd control API
module Yast2::Systemd; end
@@ -1,15 +1,16 @@
require "yast"
require "yast2/systemd/unit"

module Yast2
module Systemd
# Represent a missed service
# Represent a missing service
class ServiceNotFound < StandardError
def initialize(service_name)
super "Service unit '#{service_name}' not found"
end
end

# Systemd.service unit control API
# API to manage a systemd.service unit
#
# @example How to use it in other yast libraries
# require 'yast'
@@ -18,17 +19,17 @@ def initialize(service_name)
# ## Get a service unit by its name
# ## If the service unit can't be found, you'll get nil
#
# service = Yast::Systemd::Service.find('sshd') # service unit object
# service = Yast2::Systemd::Service.find('sshd') # service unit object
#
# # or using the full unit id 'sshd.service'
#
# service = Yast::Systemd::Service.find('sshd.service')
# service = Yast2::Systemd::Service.find('sshd.service')
#
# ## If you can't handle any nil at the place of calling,
# ## use the finder with exclamation mark;
# ## Systemd::ServiceNotFound exception will be raised
#
# service = Yast::Systemd::Service.find!('IcanHasMoar') # Systemd::ServiceNotFound: Service unit 'IcanHasMoar' not found
# service = Yast2::Systemd::Service.find!('IcanHasMoar') # Systemd::ServiceNotFound: Service unit 'IcanHasMoar' not found
#
# ## Get basic unit properties
#
@@ -65,7 +66,7 @@ def initialize(service_name)
# # no automatical casting is done by yast.
# # To get an overview of available service properties, try e.g., `systemctl show sshd.service`
#
# service = Yast::Systemd::Service.find('sshd', :type=>'Type')
# service = Yast2::Systemd::Service.find('sshd', :type=>'Type')
# service.properties.type # 'simple'
class Service < Unit
Yast.import "Stage"
@@ -129,7 +130,7 @@ def find_many(service_names, propmap = {})
# @param propmap [Systemd::Unit::PropMap]
# @return [Array<Service>]
def all(propmap = {})
Systemctl.service_units.map { |service_unit| new(service_unit, propmap) }
Systemctl.service_units.map { |s| new(s, propmap) }
end

# Instantiate a Systemd::Service object based on the given name
@@ -198,6 +199,8 @@ def socket?
!socket.nil?
end

private

def installation_system?
File.exist?(START_SERVICE_INSTSYS_COMMAND)
end
@@ -10,8 +10,7 @@ def initialize(socket_name)
end
end

###
# Systemd.socket unit control API
# API to manage a systemd.socket unit
#
# @example How to use it in other yast libraries
#
@@ -61,7 +60,7 @@ def initialize(socket_name)
# # then available under the #properties instance method. To get an overview of
# # available socket properties, try e.g., `systemctl show iscsid.socket`
#
# socket = Yast::Systemd::Socket.find('iscsid', :can_start=>'CanStart', :triggers=>'Triggers')
# socket = Yast2::Systemd::Socket.find('iscsid', :can_start=>'CanStart', :triggers=>'Triggers')
# socket.properties.can_start # 'yes'
# socket.properties.triggers # 'iscsid.service'
class Socket < Unit
@@ -83,14 +82,14 @@ def find!(socket_name, propmap = {})

# @param propmap [SystemdUnit::PropMap]
def all(propmap = {})
sockets = Systemctl.socket_units.map { |socket_unit| new(socket_unit, propmap) }
sockets = Systemctl.socket_units.map { |s| new(s, propmap) }
sockets.select { |s| s.properties.supported? }
end

# Returns the socket for a given service
#
# @param service_name [String] Service name (without the `.service` extension)
# @return [Yast::Systemd::Socket, nil]
# @return [Yast2::Systemd::Socket, nil]
def for_service(service_name)
@socket_finder ||= Yast2::Systemd::SocketFinder.new
@socket_finder.for_service(service_name)
@@ -1,3 +1,4 @@
require "yast"
require "yast2/systemd/unit"

module Yast2
@@ -9,8 +10,8 @@ def initialize(target_name)
end
end

###
# Systemd.target unit control API
# API to manage a systemd.target unit
#
# @example How to find a custom systemd target
#
# require 'yast'
@@ -39,7 +40,6 @@ def initialize(target_name)
# target = Yast2::Systemd::Target.find('graphical')
# target.allow_isolate? # must be true to set default target
# target.set_default # returns true if success
###
class Target < Unit
include Yast::Logger

@@ -10,7 +10,7 @@ module Systemd
#
# @example Create a systemd service unit
#
# class Service < Yast::Systemd::Unit
# class Service < Yast2::Systemd::Unit
# SUFFIX = ".service"
# PROPMAP = {
# before: "Before"
@@ -277,7 +277,7 @@ def read_enabled_state
else
# Check for exit code of `systemctl is-enabled systemd_unit.name` ; additionally
# test the stdout of the command for valid values when the service is enabled
# http://www.freedesktop.org/software/systemd/man/systemctl.html#is-enabled%20NAME...
# https://www.freedesktop.org/software/systemd/man/systemctl.html#is-enabled%20UNIT%E2%80%A6
status = systemd_unit.command("is-enabled")
status.exit.zero? && state_name_enabled?(status.stdout)
end

0 comments on commit 0f6ec0b

Please sign in to comment.
You can’t perform that action at this time.