Skip to content

Commit

Permalink
Merge bffab10 into ff4c28f
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Feb 22, 2022
2 parents ff4c28f + bffab10 commit 11f3320
Show file tree
Hide file tree
Showing 23 changed files with 247 additions and 90 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion yastd/Gemfile.lock → service/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ PATH
eventmachine (~> 1.2.7)
fast_gettext (~> 2.2.0)
nokogiri (~> 1.13.1)
ruby-dbus (~> 0.16.0)
rexml (~> 3.2.5)
ruby-dbus (~> 0.17.0)

GEM
remote: https://rubygems.org/
Expand All @@ -32,6 +33,7 @@ GEM
rake
racc (1.6.0)
rake (13.0.6)
rexml (3.2.5)
ruby-augeas (0.5.0)
ruby-dbus (0.17.0)
rexml
Expand Down
4 changes: 2 additions & 2 deletions yastd/bin/d-installer → service/bin/d-installer
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ require "rubygems"
require "bundler/setup"

require "eventmachine"
require "yast2/dbus/service"
require "dinstaller/dbus/service"

EM.run do
service = Yast2::DBus::Service.new
service = DInstaller::DBus::Service.new
service.export
EventMachine::PeriodicTimer.new(0.1) { service.dispatch }
end
File renamed without changes.
File renamed without changes.
4 changes: 1 addition & 3 deletions yastd/lib/yast2.rb → service/lib/dinstaller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

# Specific YaST code lives within this module.
module Yast2
module DInstaller
end

require "yast2/installer"
11 changes: 11 additions & 0 deletions service/lib/dinstaller/dbus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

# Namespace for DBus API
module DInstaller
module DBus
end
end

require "dinstaller/dbus/manager"
require "dinstaller/dbus/language"
require "dinstaller/dbus/software"
79 changes: 79 additions & 0 deletions service/lib/dinstaller/dbus/language.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright (c) [2022] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "dbus"

module DInstaller
module DBus
# YaST D-Bus object (/org/opensuse/YaST/Installer1)
#
# @see https://rubygems.org/gems/ruby-dbus
class Language < ::DBus::Object
PATH = "/org/opensuse/DInstaller/Language1".freeze
private_constant :PATH

LANGUAGE_INTERFACE = "org.opensuse.DInstaller.Language1".freeze
private_constant :LANGUAGE_INTERFACE

# @param installer [Yast2::Installer] YaST installer instance
def initialize(installer, logger)
@installer = installer
@logger = logger

super(PATH)
end

dbus_interface LANGUAGE_INTERFACE do
dbus_reader :available_languages, "a(ssa{sv})"
attr_writer :available_languages
dbus_watcher :available_languages

dbus_reader :marked_for_install, "as"

dbus_method :ToInstall, "in LangIDs:as" do |lang_ids|
logger.info "ToInstall #{lang_ids.inspect}"
select_to_install(lang_ids)

self[DBus::PROPERTY_INTERFACE].PropertiesChanged(LANGUAGE_INTERFACE, {"MarkedForInstall" => lang_ids}, [])
end
end

def available_languages
@available_languages ||= installer.languages.map { |k,v| [k, v.first, {}] }
end

def marked_for_install
# TODO: change when installer support multiple target languages
res = [installer.language]
logger.info "MarkedForInstall #{res}"
res
end

def select_to_install(lang_ids)
# TODO: adapt installer API to allow more languages to install
installer.language = lang_ids.first
end

private

attr_reader :installer, :logger

end
end
end
62 changes: 62 additions & 0 deletions service/lib/dinstaller/dbus/manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# frozen_string_literal: true

# Copyright (c) [2021] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "dbus"

module DInstaller
module DBus
# YaST D-Bus object (/org/opensuse/DInstaller/Manager1)
#
# @see https://rubygems.org/gems/ruby-dbus
class Manager < ::DBus::Object
PATH = "/org/opensuse/DInstaller/Manager1".freeze
private_constant :PATH

MANAGER_INTERFACE = "org.opensuse.DInstaler.Manager1".freeze
private_constant :MANAGER_INTERFACE

attr_reader :installer, :logger

# @param installer [Yast2::Installer] YaST installer instance
# @param args [Array<Object>] ::DBus::Object arguments
def initialize(installer, logger)
@installer = installer
@logger = logger

# @available_base_products = installer.products

super(PATH)
end

dbus_interface MANAGER_INTERFACE do
dbus_method :probe, "out result:u" do
# TODO
0
end

dbus_method :commit, "out result:u" do
# TODO
0
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
# find current contact information at www.suse.com.

require "dbus"
require "yast2/dbus/installer"
require "yast2/installer"
require "dinstaller/dbus/manager"
require "dinstaller/dbus/language"
require "dinstaller/dbus/software"
require "dinstaller/installer"

module Yast2
module DInstaller
module DBus
# YaST D-Bus service (org.opensuse.YaST)
#
Expand All @@ -35,11 +37,9 @@ module DBus
# @see Yast2::DBus::Installer
class Service
# @return [String] service name
SERVICE_NAME = "org.opensuse.YaST"
SERVICE_NAME = "org.opensuse.DInstaller".freeze

# @return [String] D-Bus object path
OBJECT_PATH = "/org/opensuse/YaST/Installer1"

attr_reader :bus

def initialize(logger = nil)
Expand All @@ -49,12 +49,10 @@ def initialize(logger = nil)

# Exports the installer object through the D-Bus service
def export
service = bus.request_service(SERVICE_NAME)
installer_obj = Yast2::DBus::Installer.new(
build_installer, logger, OBJECT_PATH
)
service.export(installer_obj)
logger.info "Exported #{OBJECT_PATH} object"
dbus_objects.each { |o| service.export(o) }

paths = dbus_objects.map(&:path).join(", ")
logger.info "Exported #{paths} objects"
end

def dispatch
Expand All @@ -65,10 +63,31 @@ def dispatch

attr_reader :logger

def build_installer
installer = Yast2::Installer.new(logger: logger)
installer.probe
installer
def service
@service ||= bus.request_service(SERVICE_NAME)
end

def dbus_objects
@dbus_objects ||= [manager_bus, language_dbus, software_dbus]
end

def manager_bus
@manager_bus ||= DInstaller::DBus::Manager.new(installer, @logger)
end

def language_dbus
@language_dbus ||= DInstaller::DBus::Language.new(installer, @logger)
end

def software_dbus
@software_dbus ||= DInstaller::DBus::Software.new(installer, @logger)
end

def installer
@installer ||= DInstaller::Installer.new(logger: @logger).tap do |installer|
# FIXME: do not probe by default
installer.probe
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2021] SUSE LLC
# Copyright (c) [2022] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -21,70 +21,57 @@

require "dbus"

module Yast2
module DInstaller
module DBus
# YaST D-Bus object (/org/opensuse/YaST/Installer1)
#
# @see https://rubygems.org/gems/ruby-dbus
class Installer < ::DBus::Object
class Software < ::DBus::Object
PATH = "/org/opensuse/DInstaller/Software1".freeze
private_constant :PATH

SOFTWARE_INTERFACE = "org.opensuse.DInstaller.Software1"
private_constant :SOFTWARE_INTERFACE

attr_reader :installer, :logger

# @param installer [Yast2::Installer] YaST installer instance
# @param args [Array<Object>] ::DBus::Object arguments
def initialize(installer, logger, *args)
def initialize(installer, logger)
@installer = installer
@logger = logger
@available_languages = installer.languages.map { |k,v| [k, v.first, {}] }
@logger.debug "Available languages #{@available_languages.inspect}"
@available_base_products = installer.products

installer.dbus_obj = self

super(*args)
end

LANGUAGE_INTERFACE = "org.opensuse.YaST.Installer1.Language"
dbus_interface LANGUAGE_INTERFACE do
dbus_attr_reader :available_languages, "a(ssa{sv})"
attr_writer :available_languages
dbus_watcher :available_languages

def marked_for_install
# TODO: change when installer support multiple target languages
[installer.language]
end

dbus_reader :marked_for_install, "as"

dbus_method :ToInstall, "in LangIDs:as" do |lang_ids|
logger.info "ToInstall #{lang_ids.inspect}"

# TODO: adapt installer API to allow more languages to install
installer.language = lang_ids.first
self[DBus::PROPERTY_INTERFACE].PropertiesChanged(LANGUAGE_INTERFACE, {"MarkedForInstall" => lang_ids}, [])
end
super(PATH)
end

SOFTWARE_INTERFACE = "org.opensuse.YaST.Installer1.Software"
dbus_interface SOFTWARE_INTERFACE do
dbus_attr_reader :available_base_products, "a(ssa{sv})"
dbus_reader :available_base_products, "a(ssa{sv})"
attr_writer :available_base_products
dbus_watcher :available_base_products

def selected_base_product
installer.product
end

dbus_reader :selected_base_product, "s"


dbus_method :SelectProduct, "in ProductID:s" do |product_id|
logger.info "SelectProduct #{product_id}"

installer.product = product_id
select_product(product_id)
self[DBus::PROPERTY_INTERFACE].PropertiesChanged(SOFTWARE_INTERFACE, {"SelectedBaseProduct" => product_id}, [])
end
end

private

def available_base_products
@available_base_products ||= installer.products
end

def selected_base_product
installer.product
end

def select_product(product_id)
installer.product = product_id
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# find current contact information at www.suse.com.

# YaST specific code lives under this namespace
module Yast2
module DInstaller
# This class represents the installer status
class InstallationProgress
KNOWN_STEPS = 3 # keep it in sync with installer.rb
Expand Down

0 comments on commit 11f3320

Please sign in to comment.