Permalink
Browse files

Moved code out of clients for better testability.

  • Loading branch information...
mvidner committed Jun 11, 2015
1 parent 5dfcdab commit 2e37e022e03c514706fb14906084a9e98a3f2cab
Showing with 374 additions and 379 deletions.
  1. +1 −0 package/yast2-proxy.spec
  2. +2 −252 src/clients/proxy.rb
  3. +2 −126 src/clients/proxy_auto.rb
  4. +121 −0 src/lib/proxy/auto_client.rb
  5. +247 −0 src/lib/proxy/client.rb
  6. +1 −1 test/test_helper.rb
View
@@ -62,6 +62,7 @@ This package contains the YaST2 component for proxy configuration.
%files
%defattr(-,root,root)
%{yast_clientdir}/*.rb
%{yast_libdir}/proxy
%{yast_moduledir}/*.rb
%{yast_yncludedir}/proxy
%{yast_desktopdir}/*.desktop
View
@@ -1,254 +1,4 @@
# encoding: utf-8
# File: clients/proxy.ycp
# Package: Network configuration
# Summary: Proxy client
# Authors: Michal Svec <msvec@suse.cz>
#
# $Id$
#
# Main file for proxy configuration.
# Uses all other files.
module Yast
class ProxyClient < Client
def main
Yast.import "UI"
textdomain "proxy"
# The main ()
Builtins.y2milestone("----------------------------------------")
Builtins.y2milestone("Proxy module started")
Yast.import "CommandLine"
Yast.import "Label"
Yast.import "Proxy"
Yast.import "Wizard"
Yast.include self, "proxy/dialogs.rb"
@cmdline = {
# Commandline help title
"help" => _("Proxy Configuration"),
"id" => "proxy",
"guihandler" => fun_ref(method(:ProxyGUI), "any ()"),
"initialize" => fun_ref(Proxy.method(:Read), "boolean ()"),
"finish" => fun_ref(Proxy.method(:Write), "boolean ()"),
"actions" => {
"enable" => {
# command-line help
"help" => _("Enable proxy settings"),
"handler" => fun_ref(
method(:EnableHandler),
"boolean (map <string, string>)"
)
},
"disable" => {
# command-line help
"help" => _("Disable proxy settings"),
"handler" => fun_ref(
method(:DisableHandler),
"boolean (map <string, string>)"
)
},
"set" => {
# command-line help
"help" => _(
"Change the current proxy settings"
),
"handler" => fun_ref(
method(:SetHandler),
"boolean (map <string, string>)"
)
},
"authentication" => {
# command-line help
"help" => _(
"Set the authentication for proxy"
),
"handler" => fun_ref(
method(:AuthHandler),
"boolean (map <string, string>)"
)
},
"summary" => {
# command-line help
"help" => _(
"Show the summary of the current settings"
),
"handler" => fun_ref(
method(:SummaryHandler),
"boolean (map <string, string>)"
)
}
},
"options" => {
"http" => {
# command-line option help
"help" => _("Set HTTP proxy"),
"type" => "string"
},
"https" => {
# command-line option help
"help" => _("Set HTTPS proxy"),
"type" => "string"
},
"ftp" => {
# command-line option help
"help" => _("Set FTP proxy"),
"type" => "string"
},
"clear" => {
# command-line option help
"help" => _("Clear all options listed")
},
"noproxy" => {
# command-line option help
"help" => _(
"Set domains for not using the proxy settings"
),
"type" => "string"
},
"username" => {
# command-line option help
"help" => _(
"The username to be used for proxy authentication"
),
"type" => "string"
},
"password" => {
# command-line option help
"help" => _(
"The password to be used for proxy authentication"
),
"type" => "string"
}
},
"mappings" => {
"enable" => [],
"disable" => [],
"summary" => [],
"set" => ["http", "https", "ftp", "noproxy", "clear"],
"authentication" => ["username", "password", "clear"]
}
}
@ret = CommandLine.Run(@cmdline)
# Finish
Builtins.y2milestone("Proxy module finished")
Builtins.y2milestone("----------------------------------------")
deep_copy(@ret)
# EOF
end
# Return a modification status
# @return true if data was modified
def Modified
Proxy.modified
end
def ProxyGUI
Proxy.Read
Wizard.CreateDialog
Wizard.SetDesktopTitleAndIcon("proxy")
Wizard.SetNextButton(:next, Label.FinishButton)
# main ui function
ret = ProxyMainDialog(true)
Builtins.y2debug("ret == %1", ret)
Proxy.Write if ret == :next && Modified()
UI.CloseDialog
deep_copy(ret)
end
def EnableHandler(options)
options = deep_copy(options)
Proxy.enabled = true
Proxy.modified = true
true
end
def DisableHandler(options)
options = deep_copy(options)
Proxy.enabled = false
Proxy.modified = true
true
end
def SetHandler(options)
options = deep_copy(options)
clear = Builtins.haskey(options, "clear")
# TODO: maybe we should validate the values
Builtins.foreach(options) do |option, value|
case option
when "http"
Builtins.y2milestone(
"Setting HTTP proxy to '%1'",
clear ? "" : option
)
Proxy.http = clear ? "" : value
Proxy.modified = true
when "https"
Builtins.y2milestone(
"Setting HTTPS proxy to '%1'",
clear ? "" : option
)
Proxy.https = clear ? "" : value
Proxy.modified = true
when "ftp"
Builtins.y2milestone(
"Setting FTP proxy to '%1'",
clear ? "" : option
)
Proxy.ftp = clear ? "" : value
Proxy.modified = true
when "noproxy"
Builtins.y2milestone(
"Setting NO proxy to '%1'",
clear ? "" : option
)
Proxy.no = clear ? "" : value
Proxy.modified = true
end
end
true
end
def AuthHandler(options)
options = deep_copy(options)
if Builtins.haskey(options, "clear")
Proxy.user = ""
Proxy.pass = ""
else
Proxy.user = Ops.get(options, "username", "")
Proxy.pass = Ops.get(options, "password")
if Proxy.pass == nil
# ask the user
# translators: command line prompt for entering a password
Proxy.pass = CommandLine.PasswordInput(_("Password:"))
end
end
true
end
def SummaryHandler(options)
options = deep_copy(options)
Yast.import "RichText"
CommandLine.Print(RichText.Rich2Plain(Proxy.Summary))
true
end
end
end
require "yast"
require "proxy/client"
Yast::ProxyClient.new.main
View
@@ -1,128 +1,4 @@
# encoding: utf-8
# File: clients/proxy_auto.ycp
# Package: Network configuration
# Summary: Client for autoinstallation
# Authors: Michal Svec <msvec@suse.cz>
#
# $Id$
#
# This is a client for autoinstallation. It takes its arguments,
# goes through the configuration and return the setting.
# Does not do any changes to the configuration.
# @param function to execute
# @param map/list of proxy settings
# @return [Hash] edited settings, Summary or boolean on success depending on called function
# @example map mm = $[ "FAIL_DELAY" : "77" ];
# @example map ret = WFM::CallFunction ("proxy_auto", [ "Summary", mm ]);
module Yast
class ProxyAutoClient < Client
def main
Yast.import "UI"
textdomain "proxy"
Builtins.y2milestone("----------------------------------------")
Builtins.y2milestone("Proxy auto started")
Yast.import "Proxy"
Yast.import "Wizard"
Yast.import "Summary"
Yast.include self, "proxy/dialogs.rb"
@ret = nil
@func = ""
@param = {}
# Check arguments
if Ops.greater_than(Builtins.size(WFM.Args), 0) &&
Ops.is_string?(WFM.Args(0))
@func = Convert.to_string(WFM.Args(0))
if Ops.greater_than(Builtins.size(WFM.Args), 1) &&
Ops.is_map?(WFM.Args(1))
@param = Convert.to_map(WFM.Args(1))
end
end
Builtins.y2debug("func=%1", @func)
Builtins.y2debug("param=%1", @param)
# Create a summary
if @func == "Summary"
@ret = ProxySummary()
# Reset configuration
elsif @func == "Reset"
Proxy.Import({})
@ret = {}
# Change configuration (run AutoSequence)
elsif @func == "Change"
Wizard.CreateDialog
Wizard.SetDesktopTitleAndIcon("proxy")
@ret = ProxyMainDialog(true)
UI.CloseDialog
# return required package list
elsif @func == "Packages"
@ret = {}
# Import configuration
elsif @func == "Import"
@ret = Proxy.Import(@param)
elsif @func == "SetModified"
@ret = Proxy.SetModified
elsif @func == "GetModified"
@ret = Proxy.GetModified
# Read configuration (useful for cloning)
elsif @func == "Read"
@ret = Proxy.Read
# Return actual state
elsif @func == "Export"
@ret = Proxy.Export
# Write givven settings
elsif @func == "Write"
Yast.import "Progress"
@progress_orig = Progress.set(false)
Proxy.write_only = true
@ret = Proxy.Write
Progress.set(@progress_orig)
else
Builtins.y2error("Unknown function: %1", @func)
@ret = false
end
Builtins.y2debug("ret=%1", @ret)
Builtins.y2milestone("Proxy auto finished")
Builtins.y2milestone("----------------------------------------")
deep_copy(@ret)
# EOF
end
# Return a modification status
# @return true if data was modified
def Modified
Proxy.modified
end
def ProxySummary
summary = ""
nc = Summary.NotConfigured
summary = Summary.AddHeader(summary, _("Status of Proxy Configuration"))
summary = Summary.AddLine(summary, Proxy.enabled ? _("Enabled") : nc)
if Proxy.http != ""
summary = Summary.AddHeader(summary, _("HTTP"))
summary = Summary.AddLine(summary, Proxy.http)
end
if Proxy.https != ""
summary = Summary.AddHeader(summary, _("HTTPS"))
summary = Summary.AddLine(summary, Proxy.https)
end
if Proxy.ftp != ""
summary = Summary.AddHeader(summary, _("FTP"))
summary = Summary.AddLine(summary, Proxy.ftp)
end
summary
end
end
end
require "yast"
require "proxy/auto_client"
Yast::ProxyAutoClient.new.main
Oops, something went wrong.

0 comments on commit 2e37e02

Please sign in to comment.