-
Notifications
You must be signed in to change notification settings - Fork 71
Questions in a separate service/process #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
4d41555
[service] Add a new Question via D-Bus
mvidner 2831430
[service] a simple testing question in the same service
mvidner 78572e6
[service] Help with consistent indentation in VS Code
mvidner 2a2611a
[service] Change CanAskQuestion protocol to #delete the result of #add
mvidner 314c70f
[service] WIP: try asking a remote question
mvidner 36e8d19
[service] expose Software#testing_question via D-Bus
mvidner 3811e97
[service] continue implementing QuestionsManager+CanAskQuestion
mvidner b30be9c
[service] Clean up CanAskQuestion+QuestionsManager
mvidner 3cdafec
[service] Make DInstaller::DBus::Question#backend public
mvidner 4065680
[service] Use DInstaller::DBus::Clients::Question
mvidner 69ed210
[service] Fix Manager tests
mvidner 527d8f1
[service] Adapt test to changed #add #delete API truthy/falsy
mvidner 8e08749
[service] Ask testing questions only if env DINSTALLER_TEST_QUESTIONS=1
mvidner db9ad52
[service] Fix DInsaller::DBus::Client::Question API to use symbols
mvidner beacdef
[service] QuestionsManager will #wait for a specific list of Questions
mvidner 1e699e0
[service] Test DInstaller::DBus::Clients::QuestionsManager,Question
mvidner f3d1a2a
[service] argument checking for DInstaller::DBus::Questions#Delete
mvidner 7120bf4
[service] Test CanAskQuestion
mvidner a4f4c73
[cli] Test coverage
mvidner 7819fc2
[service] Test CanAskQuestion without relying on testing_question
mvidner 75d9464
[service] Remove all the testing questions
mvidner 70a279b
[service] Simplify QuestionsManager#wait
mvidner ea77d16
[service] Resolve fixmes for DInstaller::DBus::Clients::QuestionsManager
mvidner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,5 +25,4 @@ module Clients | |
| end | ||
| end | ||
|
|
||
| require "dinstaller_cli/clients/language" | ||
| require "dinstaller_cli/clients/storage" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # 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_relative "../test_helper" | ||
| require "dinstaller_cli/clients" | ||
|
|
||
| # nothing else, this test just covers the require-only files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # 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_relative "test_helper" | ||
| require "dinstaller_cli" | ||
|
|
||
| # nothing else, this test just covers the require-only files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # EditorConfig is awesome: https://EditorConfig.org | ||
|
|
||
| # top-most EditorConfig file | ||
| root = true | ||
|
|
||
| # 2 space indentation | ||
| [*.rb] | ||
| indent_style = space | ||
| indent_size = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # 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 "dinstaller/dbus/clients/base" | ||
|
|
||
| module DInstaller | ||
| module DBus | ||
| module Clients | ||
| # D-Bus client for asking a question. | ||
| # Its interface is a subset of {DInstaller::Question} | ||
| # so it can be used in the block of {DInstaller::CanAskQuestion#ask}. | ||
| class Question < Base | ||
| # @return [::DBus::ProxyObject] | ||
| attr_reader :dbus_object | ||
|
|
||
| # @param [::DBus::ObjectPath] object_path | ||
| def initialize(object_path) | ||
| super() | ||
|
|
||
| @dbus_object = service[object_path] | ||
| @dbus_iface = @dbus_object["org.opensuse.DInstaller.Question1"] | ||
| end | ||
|
|
||
| # @return [String] | ||
| def service_name | ||
| @service_name ||= "org.opensuse.DInstaller" | ||
| end | ||
|
|
||
| # TODO: what other methods are useful? | ||
|
|
||
| # @return [Symbol] no answer yet = :"" | ||
| def answer | ||
| @dbus_iface["Answer"].to_sym | ||
| end | ||
|
|
||
| # Whether the question is already answered | ||
| # | ||
| # @return [Boolean] | ||
| def answered? | ||
| answer != :"" | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # 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 "dinstaller/dbus/clients/base" | ||
| require "dinstaller/dbus/clients/question" | ||
|
|
||
| module DInstaller | ||
| module DBus | ||
| module Clients | ||
| # D-Bus client for asking a question. | ||
| # It has the same interface as {DInstaller::QuestionsManager} | ||
| # so it can be used for {DInstaller::CanAskQuestion}. | ||
| class QuestionsManager < Base | ||
| def initialize | ||
| super | ||
|
|
||
| @dbus_object = service["/org/opensuse/DInstaller/Questions1"] | ||
| @dbus_object.default_iface = "org.opensuse.DInstaller.Questions1" | ||
| end | ||
|
|
||
| # @return [String] | ||
| def service_name | ||
| @service_name ||= "org.opensuse.DInstaller" | ||
| end | ||
|
|
||
| # Adds a question | ||
| # | ||
| # @param question [DInstaller::Question] | ||
| # @return [DBus::Clients::Question] | ||
| def add(question) | ||
| q_path = @dbus_object.New( | ||
| question.text, | ||
| question.options.map(&:to_s), | ||
| Array(question.default_option&.to_s) | ||
| ) | ||
| DBus::Clients::Question.new(q_path) | ||
| end | ||
|
|
||
| # Deletes the given question | ||
| # | ||
| # @param question [DBus::Clients::Question] | ||
| # @return [void] | ||
| # @raise [::DBus::Error] if trying to delete a question twice | ||
| def delete(question) | ||
| @dbus_object.Delete(question.dbus_object.path) | ||
| end | ||
|
|
||
| # Waits until specified questions are answered. | ||
| # @param questions [Array<DBus::Clients::Question>] | ||
| # @return [void] | ||
| def wait(questions) | ||
| # TODO: detect if no UI showed up to display the questions and time out? | ||
| # for example: | ||
| # (0..Float::INFINITY).each { |i| break if i > 100 && !question.displayed; ... } | ||
|
|
||
| # We should register the InterfacesAdded callback... BEFORE adding to avoid races. | ||
| # Stupid but simple way: poll the answer property, sleep, repeat | ||
| loop do | ||
| questions = questions.find_all { |q| !q.answered? } | ||
| break if questions.empty? | ||
|
|
||
| sleep(0.5) | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # @return [::DBus::Object] | ||
| attr_reader :dbus_object | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,9 @@ class Questions < ::DBus::Object | |
| PATH = "/org/opensuse/DInstaller/Questions1" | ||
| private_constant :PATH | ||
|
|
||
| QUESTIONS_INTERFACE = "org.opensuse.DInstaller.Questions1" | ||
| private_constant :QUESTIONS_INTERFACE | ||
|
|
||
| OBJECT_MANAGER_INTERFACE = "org.freedesktop.DBus.ObjectManager" | ||
| private_constant :OBJECT_MANAGER_INTERFACE | ||
|
|
||
|
|
@@ -73,6 +76,31 @@ def managed_objects | |
| dbus_signal(:InterfacesRemoved, "object:o, interfaces:as") | ||
| end | ||
|
|
||
| dbus_interface QUESTIONS_INTERFACE do | ||
| # default_option is an array of 0 or 1 elements | ||
| dbus_method :New, "in text:s, in options:as, in default_option:as, out q:o" do | ||
| |text, options, default_option| | ||
|
|
||
| backend_q = DInstaller::Question.new( | ||
| text, | ||
| options: options.map(&:to_sym), | ||
| default_option: default_option.map(&:to_sym).first | ||
| ) | ||
| backend.add(backend_q) | ||
| path_for(backend_q) | ||
| end | ||
|
|
||
| dbus_method :Delete, "in question:o" do |question_path| | ||
| dbus_q = @service.get_node(question_path)&.object | ||
| raise ArgumentError, "Object path #{question_path} not found" unless dbus_q | ||
| raise ArgumentError, "Object #{question_path} is not a Question" unless | ||
| dbus_q.is_a? DInstaller::DBus::Question | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please do not use trailing if/unless when it is not single line |
||
|
|
||
| backend_q = dbus_q.backend | ||
| backend.delete(backend_q) | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # @return [DInstaller::QuestionsManager] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not
break if questions.all?(&:answered?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because our D-Bus clients do not cache properties and this way we don't make calls about questions that we already know are answered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so please document it. or maybe use better variable name.