From 239d0d7bd5ccb22ea9351290ae410815ce73fc9e Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 11:06:57 +0100 Subject: [PATCH 01/42] add rubocop.yml --- .rubocop.yml | 314 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 314 insertions(+) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..46b1cf8 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,314 @@ +# This configuration was generated by `rubocop --auto-gen-config` +# on 2015-03-12 11:03:52 +0100 using RuboCop version 0.28.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 3 +# Configuration parameters: AllowSafeAssignment. +Lint/AssignmentInCondition: + Enabled: false + +# Offense count: 4 +Lint/ParenthesesAsGroupedExpression: + Enabled: false + +# Offense count: 8 +Lint/RescueException: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Lint/UnusedMethodArgument: + Enabled: false + +# Offense count: 2 +Lint/UselessAccessModifier: + Enabled: false + +# Offense count: 9 +Lint/UselessAssignment: + Enabled: false + +# Offense count: 16 +Metrics/AbcSize: + Max: 79 + +# Offense count: 2 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 266 + +# Offense count: 6 +Metrics/CyclomaticComplexity: + Max: 17 + +# Offense count: 42 +# Configuration parameters: AllowURI, URISchemes. +Metrics/LineLength: + Max: 181 + +# Offense count: 21 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 87 + +# Offense count: 4 +Metrics/PerceivedComplexity: + Max: 15 + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/AccessModifierIndentation: + Enabled: false + +# Offense count: 1 +Style/AccessorMethodName: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles. +Style/AlignHash: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/BracesAroundHashParameters: + Enabled: false + +# Offense count: 6 +# Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep. +Style/CaseIndentation: + Enabled: false + +# Offense count: 4 +# Cop supports --auto-correct. +Style/ColonMethodCall: + Enabled: false + +# Offense count: 1 +# Configuration parameters: Keywords. +Style/CommentAnnotation: + Enabled: false + +# Offense count: 31 +# Cop supports --auto-correct. +Style/CommentIndentation: + Enabled: false + +# Offense count: 10 +Style/Documentation: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowAdjacentOneLineDefs. +Style/EmptyLineBetweenDefs: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Style/EmptyLines: + Enabled: false + +# Offense count: 4 +# Cop supports --auto-correct. +Style/EmptyLinesAroundAccessModifier: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/EmptyLinesAroundClassBody: + Enabled: false + +# Offense count: 3 +# Cop supports --auto-correct. +Style/EmptyLinesAroundMethodBody: + Enabled: false + +# Offense count: 1 +Style/EndOfLine: + Enabled: false + +# Offense count: 1 +# Configuration parameters: Exclude. +Style/FileName: + Enabled: false + +# Offense count: 2 +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/FormatString: + Enabled: false + +# Offense count: 2 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Enabled: false + +# Offense count: 30 +# Cop supports --auto-correct. +# Configuration parameters: SupportedStyles. +Style/HashSyntax: + EnforcedStyle: hash_rockets + +# Offense count: 8 +# Configuration parameters: MaxLineLength. +Style/IfUnlessModifier: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Style/IndentationConsistency: + Enabled: false + +# Offense count: 19 +# Cop supports --auto-correct. +# Configuration parameters: Width. +Style/IndentationWidth: + Enabled: false + +# Offense count: 12 +# Cop supports --auto-correct. +Style/LeadingCommentSpace: + Enabled: false + +# Offense count: 31 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/MethodDefParentheses: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +Style/NumericLiterals: + MinDigits: 11 + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Enabled: false + +# Offense count: 5 +# Cop supports --auto-correct. +Style/PerlBackrefs: + Enabled: false + +# Offense count: 4 +Style/RescueModifier: + Enabled: false + +# Offense count: 17 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/SignalException: + Enabled: false + +# Offense count: 46 +# Cop supports --auto-correct. +Style/SpaceAfterComma: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/SpaceAroundEqualsInParameterDefault: + Enabled: false + +# Offense count: 15 +# Cop supports --auto-correct. +Style/SpaceAroundOperators: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/SpaceBeforeBlockBraces: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. +Style/SpaceInsideBlockBraces: + Enabled: false + +# Offense count: 92 +# Cop supports --auto-correct. +Style/SpaceInsideBrackets: + Enabled: false + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. +Style/SpaceInsideHashLiteralBraces: + Enabled: false + +# Offense count: 20 +# Cop supports --auto-correct. +Style/SpaceInsideParens: + Enabled: false + +# Offense count: 10 +# Cop supports --auto-correct. +Style/SpecialGlobalVars: + Enabled: false + +# Offense count: 435 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/StringLiterals: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: IgnoredMethods. +Style/SymbolProc: + Enabled: false + +# Offense count: 55 +# Cop supports --auto-correct. +Style/Tab: + Enabled: false + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/TrailingBlankLines: + Enabled: false + +# Offense count: 32 +# Cop supports --auto-correct. +Style/TrailingWhitespace: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, Whitelist. +Style/TrivialAccessors: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Style/UnneededPercentQ: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +Style/WhileUntilDo: + Enabled: false + +# Offense count: 1 +# Configuration parameters: MaxLineLength. +Style/WhileUntilModifier: + Enabled: false + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: WordRegex. +Style/WordArray: + MinSize: 2 From f5511466380a3a835651a6fb8062ce8dee5e23c3 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 14:36:57 +0100 Subject: [PATCH 02/42] rubocop style: Lint/AssignmentInCondition --- lib/spacewalk/server.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/spacewalk/server.rb b/lib/spacewalk/server.rb index 41805aa..e4776db 100644 --- a/lib/spacewalk/server.rb +++ b/lib/spacewalk/server.rb @@ -127,7 +127,8 @@ def actions result = call "queue.get", @systemid, ACTION_VERSION, report # puts "queue.get => #{result.inspect}" - if action = result["action"] + action = result["action"] + if action result["action"] = @client.get_parser.parseMethodCall(action) end # puts "Actions => #{result.inspect}" @@ -146,7 +147,8 @@ def future_actions time_window results = call "queue.get_future_actions", @systemid, time_window # puts "queue.get_future_actions => #{results.inspect}" results.map! do |result| - if action = result["action"] + action = result["action"] + if action result["action"] = @client.get_parser.parseMethodCall(action) end result From fb18d44ab0a02a73f10cb3a54ec4f24b0ed29a7b Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 14:40:06 +0100 Subject: [PATCH 03/42] rubocop style: Lint/ParenthesesAsGroupedExpression --- bin/actions.rb | 2 +- bin/register_remote.rb | 2 +- bin/register_windows.rb | 2 +- bin/submit.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/actions.rb b/bin/actions.rb index ed8ff4b..adde997 100644 --- a/bin/actions.rb +++ b/bin/actions.rb @@ -21,7 +21,7 @@ def usage msg=nil STDERR.puts " --server " STDERR.puts " --future " STDERR.puts "Checks server for client actions" - exit (msg ? 1 : 0) + exit(msg ? 1 : 0) end # diff --git a/bin/register_remote.rb b/bin/register_remote.rb index eb31335..2f8d923 100644 --- a/bin/register_remote.rb +++ b/bin/register_remote.rb @@ -27,7 +27,7 @@ def usage msg=nil STDERR.puts " --solv " STDERR.puts " --arch " STDERR.puts "Does a registration of a 'remote' client system" - exit (msg ? 1 : 0) + exit(msg ? 1 : 0) end # diff --git a/bin/register_windows.rb b/bin/register_windows.rb index cbffbdb..97ce6c0 100644 --- a/bin/register_windows.rb +++ b/bin/register_windows.rb @@ -17,7 +17,7 @@ def usage msg=nil STDERR.puts "Usage:" STDERR.puts " register_windows --server --key --name --description --solv --port --arch " STDERR.puts "Does a registration of a remote Windows system (identified by and " - exit (msg ? 1 : 0) + exit(msg ? 1 : 0) end # diff --git a/bin/submit.rb b/bin/submit.rb index de96cfb..430bb86 100644 --- a/bin/submit.rb +++ b/bin/submit.rb @@ -23,7 +23,7 @@ def usage msg=nil STDERR.puts " --message " STDERR.puts " --result " STDERR.puts "Submit action status back to server" - exit (msg ? 1 : 0) + exit(msg ? 1 : 0) end # From 026d4a437bb71de69e1c14322a869f61715beeb5 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 14:46:49 +0100 Subject: [PATCH 04/42] rubocop style: Lint/RescueException --- bin/actions.rb | 2 +- bin/fakereg-threaded.rb | 2 +- bin/fakereg.rb | 6 +++--- bin/register_remote.rb | 2 +- bin/register_windows.rb | 2 +- bin/submit.rb | 2 +- lib/spacewalk/server.rb | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bin/actions.rb b/bin/actions.rb index adde997..79a8b8f 100644 --- a/bin/actions.rb +++ b/bin/actions.rb @@ -89,7 +89,7 @@ def mk_promise action parms = parse_args rescue SystemExit raise -rescue Exception => e +rescue StandardError => e usage e.to_s end diff --git a/bin/fakereg-threaded.rb b/bin/fakereg-threaded.rb index c733d09..1d8b74a 100644 --- a/bin/fakereg-threaded.rb +++ b/bin/fakereg-threaded.rb @@ -77,7 +77,7 @@ def fake_profile begin parms = parse_args -rescue Exception => e +rescue StandardError => e usage e.to_s end diff --git a/bin/fakereg.rb b/bin/fakereg.rb index a80e6d9..9be9cf3 100644 --- a/bin/fakereg.rb +++ b/bin/fakereg.rb @@ -77,7 +77,7 @@ def fake_profile begin parms = parse_args -rescue Exception => e +rescue StandardError => e usage e.to_s end @@ -140,7 +140,7 @@ def fake_profile end print "#{name} successfully registered\n" good += 1 - rescue Exception => e + rescue StandardError => e STDERR.puts "*** #{name} failed: #{e}" end end @@ -151,4 +151,4 @@ def fake_profile puts "Registered #{good} of #{count} systems at #{parms[:server]} in #{elapsed} seconds (#{good/elapsed} systems/sec, #{elapsed/good} secs/system)" else puts "Oops, no systems were registered" -end \ No newline at end of file +end diff --git a/bin/register_remote.rb b/bin/register_remote.rb index 2f8d923..0453455 100644 --- a/bin/register_remote.rb +++ b/bin/register_remote.rb @@ -68,7 +68,7 @@ def parse_args parms = parse_args rescue SystemExit raise -rescue Exception => e +rescue StandardError => e usage e.to_s end diff --git a/bin/register_windows.rb b/bin/register_windows.rb index 97ce6c0..4639f08 100644 --- a/bin/register_windows.rb +++ b/bin/register_windows.rb @@ -58,7 +58,7 @@ def parse_args parms = parse_args rescue SystemExit raise -rescue Exception => e +rescue StandardError => e usage e.to_s end diff --git a/bin/submit.rb b/bin/submit.rb index 430bb86..f1416aa 100644 --- a/bin/submit.rb +++ b/bin/submit.rb @@ -67,7 +67,7 @@ def mk_promise actions parms = parse_args rescue SystemExit raise -rescue Exception => e +rescue StandardError => e usage e.to_s end diff --git a/lib/spacewalk/server.rb b/lib/spacewalk/server.rb index e4776db..6ea3736 100644 --- a/lib/spacewalk/server.rb +++ b/lib/spacewalk/server.rb @@ -28,7 +28,7 @@ def call name, *args args.pop end result = @client.call(name, *args) - rescue Exception => e + rescue StandardError => e raise e unless e.message =~ /Wrong content-type/ end response = @client.http_last_response From 49fc6b751163507c4fe25c099cb54a1e62d2b3d9 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 14:47:40 +0100 Subject: [PATCH 05/42] rubocop style: Lint/UnusedMethodArgument --- bin/submit.rb | 2 +- lib/spacewalk/xmlrpc.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/submit.rb b/bin/submit.rb index f1416aa..9a84b49 100644 --- a/bin/submit.rb +++ b/bin/submit.rb @@ -57,7 +57,7 @@ def parse_args # convert actions to promises # Actions => {"id"=>6434, "version"=>2, "action"=>["packages.remove", [[["accountsservice-devel", "0.6.38", "79.1", "", ""]]]]} # -def mk_promise actions +def mk_promise _actions end #------------------------------------ diff --git a/lib/spacewalk/xmlrpc.rb b/lib/spacewalk/xmlrpc.rb index 9d60ad0..7fae30d 100644 --- a/lib/spacewalk/xmlrpc.rb +++ b/lib/spacewalk/xmlrpc.rb @@ -44,7 +44,7 @@ def self.value2ruby element # ... # ... # - def self.decode what + def self.decode _what @doc.root.elements["params/param"] initialize config From 2503c22b86698e59a9deac7c8d792ee6b80aa873 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 14:48:54 +0100 Subject: [PATCH 06/42] rubocop style: Lint/UselessAccessModifier --- lib/spacewalk/xmlrpc.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/spacewalk/xmlrpc.rb b/lib/spacewalk/xmlrpc.rb index 7fae30d..0d76d14 100644 --- a/lib/spacewalk/xmlrpc.rb +++ b/lib/spacewalk/xmlrpc.rb @@ -1,7 +1,7 @@ module Spacewalk class Xmlrpc require 'rexml/document' -private + def self.value2ruby element puts "value2ruby element #{element}" node = element[0] @@ -32,7 +32,7 @@ def self.value2ruby element raise "value2ruby: Can't handle element '#{element.name}'" end end -public + # # # @@ -55,4 +55,4 @@ def self.decode _what @members = @doc.root.elements["params/param"] end end -end \ No newline at end of file +end From 0fb9e14e94c09ea696643de4e262942af7d2fa21 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 14:51:03 +0100 Subject: [PATCH 07/42] rubocop style: Style/AccessModifierIndentation --- lib/spacewalk/server.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/spacewalk/server.rb b/lib/spacewalk/server.rb index 6ea3736..3935c90 100644 --- a/lib/spacewalk/server.rb +++ b/lib/spacewalk/server.rb @@ -19,7 +19,7 @@ class Server require 'base64' require 'rexml/document' -private + private def call name, *args # puts "Call #{name}(#{args.inspect})" begin @@ -54,7 +54,7 @@ def call name, *args raise unless ok result end -public + public # # Initialize server xmlrpc port From 1297c5d539e1172e3408fdc141a8cf1678194dcf Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 14:55:07 +0100 Subject: [PATCH 08/42] rubocop style: Style/EmptyLineBetweenDefs --- lib/spacewalk/system_id.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/spacewalk/system_id.rb b/lib/spacewalk/system_id.rb index b6bd685..e9e139f 100644 --- a/lib/spacewalk/system_id.rb +++ b/lib/spacewalk/system_id.rb @@ -19,6 +19,7 @@ def initialize client, config end puts "SystemId => #{@members.inspect}" end + def to_xml @raw end From 1f38dad5097ea42ac1e215a0b629111158cd0ef8 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 14:56:18 +0100 Subject: [PATCH 09/42] rubocop style: Style/EmptyLineBetweenDefs --- bin/client.rb | 1 - bin/refresh.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/bin/client.rb b/bin/client.rb index b22bc98..71bc704 100644 --- a/bin/client.rb +++ b/bin/client.rb @@ -80,7 +80,6 @@ def profile data end - end # client if $0 == __FILE__ diff --git a/bin/refresh.rb b/bin/refresh.rb index 7d762c4..cfd2ac7 100644 --- a/bin/refresh.rb +++ b/bin/refresh.rb @@ -47,7 +47,6 @@ def parse_args parms = parse_args - # Already registered ? fqdn = parms[:fqdn] From 68f7474c99cafdfeab81d4556fd6be84fab4ec4c Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:05:24 +0100 Subject: [PATCH 10/42] rubocop style: Style/IndentationConsistency --- lib/spacewalk/server.rb | 2 +- tasks/doc.rake | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/spacewalk/server.rb b/lib/spacewalk/server.rb index 3935c90..e6fc65b 100644 --- a/lib/spacewalk/server.rb +++ b/lib/spacewalk/server.rb @@ -67,7 +67,7 @@ def initialize options = {} @config = Spacewalk::Config.new if options[:noconfig] uri = URI.parse(options[:server]) - raise "Server '#{options[:server]}' is not proper URL" unless uri.host + raise "Server '#{options[:server]}' is not proper URL" unless uri.host uri.path = "/XMLRPC" else uri = URI.parse(@config.serverurl) diff --git a/tasks/doc.rake b/tasks/doc.rake index 5a22282..d67492b 100644 --- a/tasks/doc.rake +++ b/tasks/doc.rake @@ -1,9 +1,9 @@ begin require 'yard' - YARD::Rake::YardocTask.new(:doc) do |t| - t.files = ['lib/**/*.rb'] - t.options = ['--no-private'] - end + YARD::Rake::YardocTask.new(:doc) do |t| + t.files = ['lib/**/*.rb'] + t.options = ['--no-private'] + end rescue LoadError STDERR.puts "Install yard if you want prettier docs" require 'rdoc/task' From ca0139e1644bc3fa3321978ea46e2db3551266bc Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:07:56 +0100 Subject: [PATCH 11/42] rubocop style: Style/MethodDefParentheses --- bin/actions.rb | 4 ++-- bin/client.rb | 4 ++-- bin/fakereg-threaded.rb | 4 ++-- bin/fakereg.rb | 4 ++-- bin/refresh.rb | 2 +- bin/register_remote.rb | 2 +- bin/register_windows.rb | 2 +- bin/submit.rb | 4 ++-- bin/windows.rb | 8 ++++---- lib/spacewalk/capabilities.rb | 2 +- lib/spacewalk/config.rb | 6 +++--- lib/spacewalk/server.rb | 14 +++++++------- lib/spacewalk/system_id.rb | 2 +- lib/spacewalk/xmlrpc.rb | 4 ++-- 14 files changed, 31 insertions(+), 31 deletions(-) diff --git a/bin/actions.rb b/bin/actions.rb index 79a8b8f..d48d64f 100644 --- a/bin/actions.rb +++ b/bin/actions.rb @@ -14,7 +14,7 @@ # Usage # -def usage msg=nil +def usage(msg=nil) STDERR.puts "*** #{msg}" if msg STDERR.puts "Usage:" STDERR.puts " actions [] " @@ -53,7 +53,7 @@ def parse_args # {"id"=>6434, "version"=>2, "action"=>["packages.remove", [[["accountsservice-devel", "0.6.38", "79.1", "", ""]]]]} # {"id"=>6437, "version"=>2, "action"=>["packages.update", [[["aalib-devel", "1.4.0", "503.1.3", "", ""]]]]} # -def mk_promise action +def mk_promise(action) id = action["id"] task, packages = action["action"] promise = "bundle agent " diff --git a/bin/client.rb b/bin/client.rb index 71bc704..1225d1b 100644 --- a/bin/client.rb +++ b/bin/client.rb @@ -9,7 +9,7 @@ class Client # # Dump result as XML to file # - def dump klass, result + def dump(klass, result) File.open("#{klass}.xml", "w+") do |f| f.write result.to_xml end @@ -18,7 +18,7 @@ def dump klass, result # # Constructor # - def initialize host + def initialize(host) @host = host @data = {} end diff --git a/bin/fakereg-threaded.rb b/bin/fakereg-threaded.rb index 1d8b74a..311339e 100644 --- a/bin/fakereg-threaded.rb +++ b/bin/fakereg-threaded.rb @@ -11,7 +11,7 @@ # Usage # -def usage msg +def usage(msg) STDERR.puts "*** #{msg}" if msg STDERR.puts "Usage:" STDERR.puts " fakereg --server [--port ] --key [--description ] [--solv --yaml ] --arch --count " @@ -48,7 +48,7 @@ def parse_args # # Convert Satsolver::Repo to profile list # -def repo_packages repo +def repo_packages(repo) packages = [] repo.each do |p| entry = {} diff --git a/bin/fakereg.rb b/bin/fakereg.rb index 9be9cf3..bf143c5 100644 --- a/bin/fakereg.rb +++ b/bin/fakereg.rb @@ -11,7 +11,7 @@ # Usage # -def usage msg +def usage(msg) STDERR.puts "*** #{msg}" if msg STDERR.puts "Usage:" STDERR.puts " fakereg --server [--port ] --key [--description ] [--solv --yaml ] --arch --count " @@ -48,7 +48,7 @@ def parse_args # # Convert Satsolver::Repo to profile list # -def repo_packages repo +def repo_packages(repo) packages = [] repo.each do |p| entry = {} diff --git a/bin/refresh.rb b/bin/refresh.rb index cfd2ac7..ce9f842 100644 --- a/bin/refresh.rb +++ b/bin/refresh.rb @@ -12,7 +12,7 @@ # Usage # -def usage msg +def usage(msg) STDERR.puts "*** #{msg}" if msg STDERR.puts "Usage:" STDERR.puts " refresh [--packages] [--hardware] --server " diff --git a/bin/register_remote.rb b/bin/register_remote.rb index 0453455..248c82f 100644 --- a/bin/register_remote.rb +++ b/bin/register_remote.rb @@ -14,7 +14,7 @@ # Usage # -def usage msg=nil +def usage(msg=nil) STDERR.puts "*** #{msg}" if msg STDERR.puts "Usage:" STDERR.puts " register_remote [] " diff --git a/bin/register_windows.rb b/bin/register_windows.rb index 4639f08..135697b 100644 --- a/bin/register_windows.rb +++ b/bin/register_windows.rb @@ -12,7 +12,7 @@ # Usage # -def usage msg=nil +def usage(msg=nil) STDERR.puts "*** #{msg}" if msg STDERR.puts "Usage:" STDERR.puts " register_windows --server --key --name --description --solv --port --arch " diff --git a/bin/submit.rb b/bin/submit.rb index 9a84b49..3644a74 100644 --- a/bin/submit.rb +++ b/bin/submit.rb @@ -14,7 +14,7 @@ # Usage # -def usage msg=nil +def usage(msg=nil) STDERR.puts "*** #{msg}" if msg STDERR.puts "Usage:" STDERR.puts " submit [] " @@ -57,7 +57,7 @@ def parse_args # convert actions to promises # Actions => {"id"=>6434, "version"=>2, "action"=>["packages.remove", [[["accountsservice-devel", "0.6.38", "79.1", "", ""]]]]} # -def mk_promise _actions +def mk_promise(_actions) end #------------------------------------ diff --git a/bin/windows.rb b/bin/windows.rb index 0493428..d77dd25 100644 --- a/bin/windows.rb +++ b/bin/windows.rb @@ -24,13 +24,13 @@ class Windows 7 => :REG_MULTI_SZ, # multi string } - def dump klass, result + def dump(klass, result) File.open("#{klass}.xml", "w+") do |f| f.write result.to_xml end end - def initialize host, port = 5985 + def initialize(host, port = 5985) @data = {} port ||= 5985 # if an explicit nil is passed @wsurl = "http://wsman:secret@#{host}:#{port}/wsman" @@ -45,7 +45,7 @@ def initialize host, port = 5985 @wsopt.max_elements = 999 end - def fault result = nil + def fault(result = nil) if result && result.fault? fault = Openwsman::Fault.new result STDERR.puts "Fault code #{fault.code}, subcode #{fault.subcode}" @@ -195,7 +195,7 @@ def bios # # Return hash of hashes { "" : { ... }, ... } # - def network only_enabled=true + def network(only_enabled=true) netinterfaces = nil puts "Enumerating network configurations" uri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/" diff --git a/lib/spacewalk/capabilities.rb b/lib/spacewalk/capabilities.rb index 15e974e..ace87b9 100644 --- a/lib/spacewalk/capabilities.rb +++ b/lib/spacewalk/capabilities.rb @@ -1,7 +1,7 @@ module Spacewalk class Capabilities # - def initialize client + def initialize(client) # hash of => @caps = {} client.http_last_response["x-rhn-server-capability"].split(",").each do |caps| diff --git a/lib/spacewalk/config.rb b/lib/spacewalk/config.rb index 2a186c0..253120d 100644 --- a/lib/spacewalk/config.rb +++ b/lib/spacewalk/config.rb @@ -1,6 +1,6 @@ module Spacewalk class Config - def initialize path="/etc/sysconfig/rhn/up2date" + def initialize(path="/etc/sysconfig/rhn/up2date") @path = path @config = {} File.open path do |f| @@ -15,11 +15,11 @@ def initialize path="/etc/sysconfig/rhn/up2date" end rescue nil end - def [] key + def [](key) @config[key.downcase] end - def method_missing name + def method_missing(name) @config[name.to_s.downcase] end end diff --git a/lib/spacewalk/server.rb b/lib/spacewalk/server.rb index e6fc65b..4fa2925 100644 --- a/lib/spacewalk/server.rb +++ b/lib/spacewalk/server.rb @@ -20,7 +20,7 @@ class Server require 'rexml/document' private - def call name, *args + def call(name, *args) # puts "Call #{name}(#{args.inspect})" begin # remove trailing nil values, nil is not supported in xmlrpc @@ -63,7 +63,7 @@ def call name, *args # :server => string - url of server (for initial registration) # :systemid => string # - def initialize options = {} + def initialize(options = {}) @config = Spacewalk::Config.new if options[:noconfig] uri = URI.parse(options[:server]) @@ -139,7 +139,7 @@ def actions # # time_window: (int) number of hours to look forward # - def future_actions time_window + def future_actions(time_window) time_window = time_window.to_i unless time_window.is_a? Fixnum report = Spacewalk::StatusReport.status # puts "future_actions #{time_window}" @@ -159,7 +159,7 @@ def future_actions time_window # # submit action result back to server # - def submit_response action_id, status, message, data + def submit_response(action_id, status, message, data) raise "Data must be hash" unless data.is_a? Hash result = call "queue.submit", @systemid, action_id, status, message, data end @@ -167,7 +167,7 @@ def submit_response action_id, status, message, data # register with activation key # profile_name is hash of "os_release" => version, "release_name" => name, "architecture" => arch } # - def register activationkey, profile_name, other = {} + def register(activationkey, profile_name, other = {}) auth_dict = {} auth_dict["profile_name"] = profile_name # dict of other bits to send @@ -184,13 +184,13 @@ def register activationkey, profile_name, other = {} # # send package list to server # - def send_packages packages + def send_packages(packages) call "registration.add_packages", @systemid, packages end # # send hardware details to server # - def refresh_hardware devices + def refresh_hardware(devices) call "registration.refresh_hw_profile", @systemid, devices end end diff --git a/lib/spacewalk/system_id.rb b/lib/spacewalk/system_id.rb index e9e139f..3c8ac90 100644 --- a/lib/spacewalk/system_id.rb +++ b/lib/spacewalk/system_id.rb @@ -1,7 +1,7 @@ module Spacewalk class SystemId require 'xmlrpc/client' - def initialize client, config + def initialize(client, config) raise "Expecting a Spacewalk::Config parameter to #{self.class}.new" unless config.is_a?(Spacewalk::Config) @path = config["systemIdPath"] raise "systemIdPath is empty !" unless @path diff --git a/lib/spacewalk/xmlrpc.rb b/lib/spacewalk/xmlrpc.rb index 0d76d14..e7c0731 100644 --- a/lib/spacewalk/xmlrpc.rb +++ b/lib/spacewalk/xmlrpc.rb @@ -2,7 +2,7 @@ module Spacewalk class Xmlrpc require 'rexml/document' - def self.value2ruby element + def self.value2ruby(element) puts "value2ruby element #{element}" node = element[0] puts "value2ruby node #{node}" @@ -44,7 +44,7 @@ def self.value2ruby element # ... # ... # - def self.decode _what + def self.decode(_what) @doc.root.elements["params/param"] initialize config From 4256ef9c65ecefa8503bba6d7fef6f7d6b9879f8 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:08:51 +0100 Subject: [PATCH 12/42] rubocop style: Style/LeadingCommentSpace --- bin/windows.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/bin/windows.rb b/bin/windows.rb index d77dd25..64206b3 100644 --- a/bin/windows.rb +++ b/bin/windows.rb @@ -9,12 +9,12 @@ class Windows # mapping for Registry 'root' pointers HKEYS = { - :HKEY_CLASSES_ROOT => 2147483648, #(0x80000000) - :HKEY_CURRENT_USER => 2147483649, #(0x80000001) - :HKEY_LOCAL_MACHINE => 2147483650, #(0x80000002) - :HKEY_USERS => 2147483651, #(0x80000003) - :HKEY_CURRENT_CONFIG => 2147483653, #(0x80000005) - :HKEY_DYN_DATA => 2147483654 #(0x80000006) + :HKEY_CLASSES_ROOT => 2147483648, # (0x80000000) + :HKEY_CURRENT_USER => 2147483649, # (0x80000001) + :HKEY_LOCAL_MACHINE => 2147483650, # (0x80000002) + :HKEY_USERS => 2147483651, # (0x80000003) + :HKEY_CURRENT_CONFIG => 2147483653, # (0x80000005) + :HKEY_DYN_DATA => 2147483654 # (0x80000006) } TYPES = { 1 => :REG_SZ, # string @@ -317,10 +317,10 @@ def profile # puts result.to_xml os = result.body.EnumerateResponse.Items.send(klass.to_sym) # debug - #puts klass - #os.each do |node| + # puts klass + # os.each do |node| # puts " #{node.name}:\t#{node.text}" - #end + # end puts "Asking for computer system" klass = "Win32_ComputerSystem" @@ -329,10 +329,10 @@ def profile hw = result.body.EnumerateResponse.Items.send(klass.to_sym) @data["TotalPhysicalMemory"] = hw.TotalPhysicalMemory.text # debug - #puts klass - #hw.each do |node| + # puts klass + # hw.each do |node| # puts " #{node.name}:\t#{node.text}" - #end + # end rescue STDERR.puts "EnumerateResponse failed for #{klass}" From f4e21ed48dfdde3400248b8f3567c038eb72f720 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:10:05 +0100 Subject: [PATCH 13/42] rubocop style: Style/PerlBackrefs --- lib/spacewalk/capabilities.rb | 2 +- lib/spacewalk/config.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/spacewalk/capabilities.rb b/lib/spacewalk/capabilities.rb index ace87b9..6ab9020 100644 --- a/lib/spacewalk/capabilities.rb +++ b/lib/spacewalk/capabilities.rb @@ -9,7 +9,7 @@ def initialize(client) # puts "#{cap}" raise "Invalid cap '#{cap}'" unless cap =~ /(\s+)?(((\w+)|\.)+)\((\d(-\d)?)\)=(\d)/ # name = [ version, value ] - @caps[$2] = [$5, $7] + @caps[Regexp.last_match(2)] = [Regexp.last_match(5), Regexp.last_match(7)] # puts "#{$2}(#{$5})=#{$7}" end end diff --git a/lib/spacewalk/config.rb b/lib/spacewalk/config.rb index 253120d..d4e7ba1 100644 --- a/lib/spacewalk/config.rb +++ b/lib/spacewalk/config.rb @@ -7,8 +7,8 @@ def initialize(path="/etc/sysconfig/rhn/up2date") while l = f.gets # split =, drop everything else next unless l =~ /(\w+)=(.*)/ - key = $1 - val = $2 + key = Regexp.last_match(1) + val = Regexp.last_match(2) # fixme: handle array-type values @config[key.downcase] = val.empty? ? nil : val end From 66ba7ef4a7749a76be718788c5330d212f53f222 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:12:03 +0100 Subject: [PATCH 14/42] rubocop style: Style/SignalException --- bin/actions.rb | 2 +- bin/fakereg-threaded.rb | 2 +- bin/fakereg.rb | 2 +- bin/windows.rb | 4 ++-- lib/spacewalk/capabilities.rb | 2 +- lib/spacewalk/server.rb | 8 ++++---- lib/spacewalk/system_id.rb | 4 ++-- lib/spacewalk/xmlrpc.rb | 10 +++++----- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/bin/actions.rb b/bin/actions.rb index d48d64f..cdbe8ae 100644 --- a/bin/actions.rb +++ b/bin/actions.rb @@ -65,7 +65,7 @@ def mk_promise(action) promise << "mgr_update" policy = "remove" else - raise "Task '#{task}' not supported" + fail "Task '#{task}' not supported" end promise << "\n{\n vars:\n \"package_list\" slist => {\n " first = true diff --git a/bin/fakereg-threaded.rb b/bin/fakereg-threaded.rb index 311339e..8249043 100644 --- a/bin/fakereg-threaded.rb +++ b/bin/fakereg-threaded.rb @@ -85,7 +85,7 @@ def fake_profile require 'satsolver' pool = Satsolver::Pool.new repo = pool.add_solv( parms[:solv] ) - raise "Invalid .solv file: #{parms[:solv]}" unless repo + fail "Invalid .solv file: #{parms[:solv]}" unless repo if parms[:yaml] require 'yaml' diff --git a/bin/fakereg.rb b/bin/fakereg.rb index bf143c5..d6a0ef9 100644 --- a/bin/fakereg.rb +++ b/bin/fakereg.rb @@ -85,7 +85,7 @@ def fake_profile require 'satsolver' pool = Satsolver::Pool.new repo = pool.add_solv( parms[:solv] ) - raise "Invalid .solv file: #{parms[:solv]}" unless repo + fail "Invalid .solv file: #{parms[:solv]}" unless repo if parms[:yaml] require 'yaml' diff --git a/bin/windows.rb b/bin/windows.rb index 64206b3..d1af5b8 100644 --- a/bin/windows.rb +++ b/bin/windows.rb @@ -132,7 +132,7 @@ def packages packagekey = keymap[key.text] next unless packagekey type = types.shift - raise "sName #{key} has no type" unless type + fail "sName #{key} has no type" unless type reg_type = TYPES[type] method, valuename = case reg_type when :REG_SZ @@ -146,7 +146,7 @@ def packages when :REG_MULTI_SZ ["GetMultiStringValue","sValue"] # multi string else - raise "Unknown type #{type}" + fail "Unknown type #{type}" end subproperties = { "hDefKey" => HKEYS[:HKEY_LOCAL_MACHINE].to_s, diff --git a/lib/spacewalk/capabilities.rb b/lib/spacewalk/capabilities.rb index 6ab9020..b3737dc 100644 --- a/lib/spacewalk/capabilities.rb +++ b/lib/spacewalk/capabilities.rb @@ -7,7 +7,7 @@ def initialize(client) client.http_last_response["x-rhn-server-capability"].split(",").each do |caps| caps.split(",").each do |cap| # puts "#{cap}" - raise "Invalid cap '#{cap}'" unless cap =~ /(\s+)?(((\w+)|\.)+)\((\d(-\d)?)\)=(\d)/ + fail "Invalid cap '#{cap}'" unless cap =~ /(\s+)?(((\w+)|\.)+)\((\d(-\d)?)\)=(\d)/ # name = [ version, value ] @caps[Regexp.last_match(2)] = [Regexp.last_match(5), Regexp.last_match(7)] # puts "#{$2}(#{$5})=#{$7}" diff --git a/lib/spacewalk/server.rb b/lib/spacewalk/server.rb index 4fa2925..1d4c2bd 100644 --- a/lib/spacewalk/server.rb +++ b/lib/spacewalk/server.rb @@ -32,7 +32,7 @@ def call(name, *args) raise e unless e.message =~ /Wrong content-type/ end response = @client.http_last_response - raise "XMLRPC failed with #{response.code}" unless response.code == "200" + fail "XMLRPC failed with #{response.code}" unless response.code == "200" body = response.body case response["content-type"] when "text/base64" @@ -51,7 +51,7 @@ def call(name, *args) STDERR.puts "Unhandled content-encoding #{response['content-encoding']}" end ok, result = @client.get_parser.parseMethodResponse(body) - raise unless ok + fail unless ok result end public @@ -67,7 +67,7 @@ def initialize(options = {}) @config = Spacewalk::Config.new if options[:noconfig] uri = URI.parse(options[:server]) - raise "Server '#{options[:server]}' is not proper URL" unless uri.host + fail "Server '#{options[:server]}' is not proper URL" unless uri.host uri.path = "/XMLRPC" else uri = URI.parse(@config.serverurl) @@ -160,7 +160,7 @@ def future_actions(time_window) # submit action result back to server # def submit_response(action_id, status, message, data) - raise "Data must be hash" unless data.is_a? Hash + fail "Data must be hash" unless data.is_a? Hash result = call "queue.submit", @systemid, action_id, status, message, data end # diff --git a/lib/spacewalk/system_id.rb b/lib/spacewalk/system_id.rb index 3c8ac90..069e0e8 100644 --- a/lib/spacewalk/system_id.rb +++ b/lib/spacewalk/system_id.rb @@ -2,9 +2,9 @@ module Spacewalk class SystemId require 'xmlrpc/client' def initialize(client, config) - raise "Expecting a Spacewalk::Config parameter to #{self.class}.new" unless config.is_a?(Spacewalk::Config) + fail "Expecting a Spacewalk::Config parameter to #{self.class}.new" unless config.is_a?(Spacewalk::Config) @path = config["systemIdPath"] - raise "systemIdPath is empty !" unless @path + fail "systemIdPath is empty !" unless @path # # # diff --git a/lib/spacewalk/xmlrpc.rb b/lib/spacewalk/xmlrpc.rb index e7c0731..5539c01 100644 --- a/lib/spacewalk/xmlrpc.rb +++ b/lib/spacewalk/xmlrpc.rb @@ -10,7 +10,7 @@ def self.value2ruby(element) when "string" node.text when "struct" - raise "value2ruby: not following " unless node[0].name == "member" + fail "value2ruby: not following " unless node[0].name == "member" value = {} puts "Struct #{node}" node.each_element("member") do |e| @@ -20,7 +20,7 @@ def self.value2ruby(element) end value when "array" - raise "value2ruby: not following " unless node[0].name == "data" + fail "value2ruby: not following " unless node[0].name == "data" value = [] # puts "Array #{node}" node.each_element("data/value") do |e| @@ -29,7 +29,7 @@ def self.value2ruby(element) end value else - raise "value2ruby: Can't handle element '#{element.name}'" + fail "value2ruby: Can't handle element '#{element.name}'" end end @@ -48,9 +48,9 @@ def self.decode(_what) @doc.root.elements["params/param"] initialize config - raise "Expecting a Spacewalk::Config parameter to #{self.class}.new" unless config.is_a?(Spacewalk::Config) + fail "Expecting a Spacewalk::Config parameter to #{self.class}.new" unless config.is_a?(Spacewalk::Config) @path = config["systemIdPath"] - raise "systemIdPath is empty !" unless @path + fail "systemIdPath is empty !" unless @path @doc = REXML::Document.new(File.open(@path)) @members = @doc.root.elements["params/param"] end From 63a333153729e3b1821aa5008746ebf29bce971a Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:12:57 +0100 Subject: [PATCH 15/42] rubocop style: Style/SpaceAfterComma --- bin/actions.rb | 6 +++--- bin/client.rb | 4 ++-- bin/fakereg-threaded.rb | 6 +++--- bin/fakereg.rb | 6 +++--- bin/refresh.rb | 6 +++--- bin/register_remote.rb | 6 +++--- bin/register_windows.rb | 6 +++--- bin/submit.rb | 6 +++--- bin/windows.rb | 14 +++++++------- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/bin/actions.rb b/bin/actions.rb index cdbe8ae..d658efc 100644 --- a/bin/actions.rb +++ b/bin/actions.rb @@ -5,10 +5,10 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib")) +$: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) require "spacewalk" -require File.expand_path(File.join(File.dirname(__FILE__),'client')) +require File.expand_path(File.join(File.dirname(__FILE__), 'client')) # # Usage @@ -36,7 +36,7 @@ def parse_args [ "--future", "-f", GetoptLong::REQUIRED_ARGUMENT ] ) result = {} - opts.each do |opt,arg| + opts.each do |opt, arg| result[opt[2..-1].to_sym] = arg end usage if result[:help] diff --git a/bin/client.rb b/bin/client.rb index 1225d1b..35aa4bd 100644 --- a/bin/client.rb +++ b/bin/client.rb @@ -37,7 +37,7 @@ def packages IO.popen("rpm -qa --queryformat \"%{name} %{epoch} %{version} %{release} %{arch} %{installtime}\n\"") do |io| io.each do |rpm| - name,epoch,version,release,arch,installtime = rpm.split(" ") + name, epoch, version, release, arch, installtime = rpm.split(" ") next if name == "gpg-pubkey" next if arch == "src" package = { "name" => name, "epoch" => epoch, "version" => version, "release" => release, "arch" => arch, "installtime" => installtime.to_i } @@ -68,7 +68,7 @@ def profile File.open("/etc/os-release") do |f| f.each do |l| key, val = l.chomp.split("=") - val = val[1,-2] if val[0][1] == '"' + val = val[1, -2] if val[0][1] == '"' case key when "VERSION_ID" data["os_release"] = val diff --git a/bin/fakereg-threaded.rb b/bin/fakereg-threaded.rb index 8249043..c349443 100644 --- a/bin/fakereg-threaded.rb +++ b/bin/fakereg-threaded.rb @@ -3,7 +3,7 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib")) +$: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) require "spacewalk" @@ -35,7 +35,7 @@ def parse_args [ "--count", "-c", GetoptLong::REQUIRED_ARGUMENT ] ) result = {} - opts.each do |opt,arg| + opts.each do |opt, arg| result[opt[2..-1].to_sym] = arg end usage("No server url given") unless result[:server] @@ -95,7 +95,7 @@ def fake_profile # somehow, YAML::dump(packages, f) does not work packages.each do |p| first = true - p.each do |k,v| + p.each do |k, v| if first f.puts "- #{k}: #{v.inspect}" first = false diff --git a/bin/fakereg.rb b/bin/fakereg.rb index d6a0ef9..f687784 100644 --- a/bin/fakereg.rb +++ b/bin/fakereg.rb @@ -3,7 +3,7 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib")) +$: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) require "spacewalk" @@ -35,7 +35,7 @@ def parse_args [ "--count", "-c", GetoptLong::REQUIRED_ARGUMENT ] ) result = {} - opts.each do |opt,arg| + opts.each do |opt, arg| result[opt[2..-1].to_sym] = arg end usage("No server url given") unless result[:server] @@ -95,7 +95,7 @@ def fake_profile # somehow, YAML::dump(packages, f) does not work packages.each do |p| first = true - p.each do |k,v| + p.each do |k, v| if first f.puts "- #{k}: #{v.inspect}" first = false diff --git a/bin/refresh.rb b/bin/refresh.rb index ce9f842..b3e26e7 100644 --- a/bin/refresh.rb +++ b/bin/refresh.rb @@ -3,10 +3,10 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib")) +$: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) require "spacewalk" -require File.expand_path(File.join(File.dirname(__FILE__),'windows')) +require File.expand_path(File.join(File.dirname(__FILE__), 'windows')) # # Usage @@ -32,7 +32,7 @@ def parse_args [ "--hardware", "-h", GetoptLong::NO_ARGUMENT ] ) result = {} - opts.each do |opt,arg| + opts.each do |opt, arg| result[opt[2..-1].to_sym] = arg end usage("No server url given") unless result[:server] diff --git a/bin/register_remote.rb b/bin/register_remote.rb index 248c82f..9ab908a 100644 --- a/bin/register_remote.rb +++ b/bin/register_remote.rb @@ -5,10 +5,10 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib")) +$: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) require "spacewalk" -require File.expand_path(File.join(File.dirname(__FILE__),'client')) +require File.expand_path(File.join(File.dirname(__FILE__), 'client')) # # Usage @@ -48,7 +48,7 @@ def parse_args [ "--solv", "-S", GetoptLong::REQUIRED_ARGUMENT ] ) result = {} - opts.each do |opt,arg| + opts.each do |opt, arg| result[opt[2..-1].to_sym] = arg end usage if result[:help] diff --git a/bin/register_windows.rb b/bin/register_windows.rb index 135697b..12ab4ba 100644 --- a/bin/register_windows.rb +++ b/bin/register_windows.rb @@ -3,10 +3,10 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib")) +$: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) require "spacewalk" -require File.expand_path(File.join(File.dirname(__FILE__),'windows')) +require File.expand_path(File.join(File.dirname(__FILE__), 'windows')) # # Usage @@ -37,7 +37,7 @@ def parse_args [ "--solv", "-S", GetoptLong::REQUIRED_ARGUMENT ] ) result = {} - opts.each do |opt,arg| + opts.each do |opt, arg| result[opt[2..-1].to_sym] = arg end usage if result[:help] diff --git a/bin/submit.rb b/bin/submit.rb index 3644a74..2f28a1c 100644 --- a/bin/submit.rb +++ b/bin/submit.rb @@ -5,10 +5,10 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib")) +$: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) require "spacewalk" -require File.expand_path(File.join(File.dirname(__FILE__),'client')) +require File.expand_path(File.join(File.dirname(__FILE__), 'client')) # # Usage @@ -40,7 +40,7 @@ def parse_args [ "--result", "-r", GetoptLong::REQUIRED_ARGUMENT ] ) result = {} - opts.each do |opt,arg| + opts.each do |opt, arg| result[opt[2..-1].to_sym] = arg end usage if result[:help] diff --git a/bin/windows.rb b/bin/windows.rb index d1af5b8..f146732 100644 --- a/bin/windows.rb +++ b/bin/windows.rb @@ -136,15 +136,15 @@ def packages reg_type = TYPES[type] method, valuename = case reg_type when :REG_SZ - ["GetStringValue","sValue"] # string + ["GetStringValue", "sValue"] # string when :REG_EXPAND_SZ - ["GetExpandedStringValue","sValue"] # expanded string + ["GetExpandedStringValue", "sValue"] # expanded string when :REG_BINARY - ["GetBinaryValue","uValue"] # blob + ["GetBinaryValue", "uValue"] # blob when :REG_DWORD - ["GetDWORDValue","uValue"] # integer + ["GetDWORDValue", "uValue"] # integer when :REG_MULTI_SZ - ["GetMultiStringValue","sValue"] # multi string + ["GetMultiStringValue", "sValue"] # multi string else fail "Unknown type #{type}" end @@ -161,9 +161,9 @@ def packages if time # convert Windows time (20101127) to Spacewalk-time (seconds since 1.1.1970) t = time.to_s - package["installtime"] = Time.local(t[0,4],t[4,2],t[6,2]).to_i + package["installtime"] = Time.local(t[0, 4], t[4, 2], t[6, 2]).to_i else - package["installtime"] = Time.local(1970,"Jan",1).to_i + package["installtime"] = Time.local(1970, "Jan", 1).to_i end package["version"] = "0" if package["version"].empty? package["release"] = "0" if package["release"].empty? From dc7a3dbab7807fe8805e7411aa8ce36e903cc847 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:15:17 +0100 Subject: [PATCH 16/42] rubocop style: Style/SpaceAroundOperators --- bin/fakereg-threaded.rb | 4 ++-- bin/fakereg.rb | 4 ++-- bin/register_remote.rb | 2 +- bin/register_windows.rb | 2 +- bin/windows.rb | 12 ++++++------ lib/spacewalk/server.rb | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bin/fakereg-threaded.rb b/bin/fakereg-threaded.rb index c349443..19e7502 100644 --- a/bin/fakereg-threaded.rb +++ b/bin/fakereg-threaded.rb @@ -150,5 +150,5 @@ def fake_profile threads.each { |t| t.join } stop = Time.now -elapsed = stop-start -puts "Registered #{good} of #{count} systems in #{elapsed} seconds (#{good/elapsed} systems/sec)" +elapsed = stop - start +puts "Registered #{good} of #{count} systems in #{elapsed} seconds (#{good / elapsed} systems/sec)" diff --git a/bin/fakereg.rb b/bin/fakereg.rb index f687784..df42099 100644 --- a/bin/fakereg.rb +++ b/bin/fakereg.rb @@ -146,9 +146,9 @@ def fake_profile end stop = Time.now -elapsed = stop-start +elapsed = stop - start if good > 0 - puts "Registered #{good} of #{count} systems at #{parms[:server]} in #{elapsed} seconds (#{good/elapsed} systems/sec, #{elapsed/good} secs/system)" + puts "Registered #{good} of #{count} systems at #{parms[:server]} in #{elapsed} seconds (#{good / elapsed} systems/sec, #{elapsed / good} secs/system)" else puts "Oops, no systems were registered" end diff --git a/bin/register_remote.rb b/bin/register_remote.rb index 9ab908a..2c1fc29 100644 --- a/bin/register_remote.rb +++ b/bin/register_remote.rb @@ -104,7 +104,7 @@ def parse_args puts "Must register" usage("No activationkey given") unless parms[:key] puts "Registering" - systemid = server.register parms[:key], parms[:name]||fqdn, profile + systemid = server.register parms[:key], parms[:name] || fqdn, profile File.open(fqdn, "w+") do |f| f.write systemid end diff --git a/bin/register_windows.rb b/bin/register_windows.rb index 12ab4ba..2a942e6 100644 --- a/bin/register_windows.rb +++ b/bin/register_windows.rb @@ -92,7 +92,7 @@ def parse_args # if empty, Spacewalk will create it profile["description"] = parms[:description] puts "Registering" - systemid = server.register parms[:key], parms[:name]||fqdn, profile + systemid = server.register parms[:key], parms[:name] || fqdn, profile File.open(fqdn, "w+") do |f| f.write systemid end diff --git a/bin/windows.rb b/bin/windows.rb index f146732..dc805d6 100644 --- a/bin/windows.rb +++ b/bin/windows.rb @@ -177,7 +177,7 @@ def bios puts "Checking the BIOS" uri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/" klass = "Win32_BIOS" - result = @wsman.enumerate( @wsopt, nil, uri+klass) + result = @wsman.enumerate( @wsopt, nil, uri + klass) bios = result.body.EnumerateResponse.Items.send(klass.to_sym) # dump klass, result return nil unless bios.SMBIOSPresent.to_s == "true" @@ -200,7 +200,7 @@ def network(only_enabled=true) puts "Enumerating network configurations" uri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/" klass = "Win32_NetworkAdapterConfiguration" - result = @wsman.enumerate( @wsopt, nil, uri+klass) + result = @wsman.enumerate( @wsopt, nil, uri + klass) result.Items.each do |node| if only_enabled next unless node.IPEnabled.to_s == "true" @@ -237,7 +237,7 @@ def hardware net_if = network if @data["DNSHostName"] && @data["DNSDomain"] && @data["IPAddress"] hw << { "class" => "netinfo", - "hostname" => @data["DNSHostName"]+"."+@data["DNSDomain"].split(" ").first, + "hostname" => @data["DNSHostName"] + "." + @data["DNSDomain"].split(" ").first, "ipaddr" => @data["IPAddress"] } end @@ -247,7 +247,7 @@ def hardware puts "Enumerating system devices" uri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/" klass = "Win32_SystemDevices" - result = @wsman.enumerate( @wsopt, nil, uri+klass) + result = @wsman.enumerate( @wsopt, nil, uri + klass) # dump klass, result # extract # @@ -312,7 +312,7 @@ def profile puts "Asking for operating system" uri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/" klass = "Win32_OperatingSystem" - result = @wsman.enumerate( @wsopt, nil, uri+klass) + result = @wsman.enumerate( @wsopt, nil, uri + klass) # dump klass, result # puts result.to_xml os = result.body.EnumerateResponse.Items.send(klass.to_sym) @@ -324,7 +324,7 @@ def profile puts "Asking for computer system" klass = "Win32_ComputerSystem" - result = @wsman.enumerate( @wsopt, nil, uri+klass) + result = @wsman.enumerate( @wsopt, nil, uri + klass) # dump klass, result hw = result.body.EnumerateResponse.Items.send(klass.to_sym) @data["TotalPhysicalMemory"] = hw.TotalPhysicalMemory.text diff --git a/lib/spacewalk/server.rb b/lib/spacewalk/server.rb index 1d4c2bd..cfb5d62 100644 --- a/lib/spacewalk/server.rb +++ b/lib/spacewalk/server.rb @@ -73,7 +73,7 @@ def initialize(options = {}) uri = URI.parse(@config.serverurl) end - args = {:host=>uri.host, :path => uri.path, :use_ssl => (uri.scheme == "https"), :timeout => 120 } + args = {:host => uri.host, :path => uri.path, :use_ssl => (uri.scheme == "https"), :timeout => 120 } unless options[:noconfig] if @config.httpProxy From f58d7068c69a886d947b321cafdb8819cbc5b2e7 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:16:09 +0100 Subject: [PATCH 17/42] rubocop style: Style/SpaceInsideBlockBraces --- lib/spacewalk/status_report.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spacewalk/status_report.rb b/lib/spacewalk/status_report.rb index d046370..f3dee98 100644 --- a/lib/spacewalk/status_report.rb +++ b/lib/spacewalk/status_report.rb @@ -8,7 +8,7 @@ def self.status status["uname"] = [`uname -s`.chomp, `uname -n`.chomp, `uname -r`.chomp, `uname -v`.chomp, `uname -m`.chomp] begin File.open("/proc/uptime") do |f| - status["uptime"] = f.read.split(" ").map{|v| v.to_i} + status["uptime"] = f.read.split(" ").map{ |v| v.to_i } end rescue nil From ccecd36d668ab45ec83d056d697b984db9113f77 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:16:54 +0100 Subject: [PATCH 18/42] rubocop style: Style/SpaceInsideBrackets --- bin/actions.rb | 8 ++++---- bin/fakereg-threaded.rb | 16 ++++++++-------- bin/fakereg.rb | 16 ++++++++-------- bin/refresh.rb | 8 ++++---- bin/register_remote.rb | 18 +++++++++--------- bin/register_windows.rb | 16 ++++++++-------- bin/submit.rb | 10 +++++----- 7 files changed, 46 insertions(+), 46 deletions(-) diff --git a/bin/actions.rb b/bin/actions.rb index d658efc..5cd2141 100644 --- a/bin/actions.rb +++ b/bin/actions.rb @@ -31,9 +31,9 @@ def usage(msg=nil) def parse_args require 'getoptlong' opts = GetoptLong.new( - [ "--help", "-?", GetoptLong::NO_ARGUMENT ], - [ "--server", "-s", GetoptLong::REQUIRED_ARGUMENT ], - [ "--future", "-f", GetoptLong::REQUIRED_ARGUMENT ] + ["--help", "-?", GetoptLong::NO_ARGUMENT], + ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT], + ["--future", "-f", GetoptLong::REQUIRED_ARGUMENT] ) result = {} opts.each do |opt, arg| @@ -108,7 +108,7 @@ def mk_promise(action) server = Spacewalk::Server.new :noconfig => true, :server => parms[:server], :systemid => systemid actions = parms[:future] ? server.future_actions(parms[:future].to_i) : server.actions if actions - actions = [ actions ] unless actions.is_a? Array + actions = [actions] unless actions.is_a? Array actions.each do |action| puts mk_promise action unless parms[:future] diff --git a/bin/fakereg-threaded.rb b/bin/fakereg-threaded.rb index 19e7502..66763d8 100644 --- a/bin/fakereg-threaded.rb +++ b/bin/fakereg-threaded.rb @@ -25,14 +25,14 @@ def usage(msg) def parse_args require 'getoptlong' opts = GetoptLong.new( - [ "--server", "-s", GetoptLong::REQUIRED_ARGUMENT ], - [ "--description", "-d", GetoptLong::REQUIRED_ARGUMENT ], - [ "--key", "-k", GetoptLong::REQUIRED_ARGUMENT ], - [ "--port", "-p", GetoptLong::REQUIRED_ARGUMENT ], - [ "--arch", "-a", GetoptLong::REQUIRED_ARGUMENT ], - [ "--solv", "-S", GetoptLong::REQUIRED_ARGUMENT ], - [ "--yaml", "-Y", GetoptLong::REQUIRED_ARGUMENT ], - [ "--count", "-c", GetoptLong::REQUIRED_ARGUMENT ] + ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT], + ["--description", "-d", GetoptLong::REQUIRED_ARGUMENT], + ["--key", "-k", GetoptLong::REQUIRED_ARGUMENT], + ["--port", "-p", GetoptLong::REQUIRED_ARGUMENT], + ["--arch", "-a", GetoptLong::REQUIRED_ARGUMENT], + ["--solv", "-S", GetoptLong::REQUIRED_ARGUMENT], + ["--yaml", "-Y", GetoptLong::REQUIRED_ARGUMENT], + ["--count", "-c", GetoptLong::REQUIRED_ARGUMENT] ) result = {} opts.each do |opt, arg| diff --git a/bin/fakereg.rb b/bin/fakereg.rb index df42099..d6b5db1 100644 --- a/bin/fakereg.rb +++ b/bin/fakereg.rb @@ -25,14 +25,14 @@ def usage(msg) def parse_args require 'getoptlong' opts = GetoptLong.new( - [ "--server", "-s", GetoptLong::REQUIRED_ARGUMENT ], - [ "--description", "-d", GetoptLong::REQUIRED_ARGUMENT ], - [ "--key", "-k", GetoptLong::REQUIRED_ARGUMENT ], - [ "--port", "-p", GetoptLong::REQUIRED_ARGUMENT ], - [ "--arch", "-a", GetoptLong::REQUIRED_ARGUMENT ], - [ "--solv", "-S", GetoptLong::REQUIRED_ARGUMENT ], - [ "--yaml", "-Y", GetoptLong::REQUIRED_ARGUMENT ], - [ "--count", "-c", GetoptLong::REQUIRED_ARGUMENT ] + ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT], + ["--description", "-d", GetoptLong::REQUIRED_ARGUMENT], + ["--key", "-k", GetoptLong::REQUIRED_ARGUMENT], + ["--port", "-p", GetoptLong::REQUIRED_ARGUMENT], + ["--arch", "-a", GetoptLong::REQUIRED_ARGUMENT], + ["--solv", "-S", GetoptLong::REQUIRED_ARGUMENT], + ["--yaml", "-Y", GetoptLong::REQUIRED_ARGUMENT], + ["--count", "-c", GetoptLong::REQUIRED_ARGUMENT] ) result = {} opts.each do |opt, arg| diff --git a/bin/refresh.rb b/bin/refresh.rb index b3e26e7..ea6883d 100644 --- a/bin/refresh.rb +++ b/bin/refresh.rb @@ -26,10 +26,10 @@ def usage(msg) def parse_args require 'getoptlong' opts = GetoptLong.new( - [ "--port", "-P", GetoptLong::REQUIRED_ARGUMENT ], - [ "--server", "-s", GetoptLong::REQUIRED_ARGUMENT ], - [ "--packages", "-p", GetoptLong::NO_ARGUMENT ], - [ "--hardware", "-h", GetoptLong::NO_ARGUMENT ] + ["--port", "-P", GetoptLong::REQUIRED_ARGUMENT], + ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT], + ["--packages", "-p", GetoptLong::NO_ARGUMENT], + ["--hardware", "-h", GetoptLong::NO_ARGUMENT] ) result = {} opts.each do |opt, arg| diff --git a/bin/register_remote.rb b/bin/register_remote.rb index 2c1fc29..db196a4 100644 --- a/bin/register_remote.rb +++ b/bin/register_remote.rb @@ -37,15 +37,15 @@ def usage(msg=nil) def parse_args require 'getoptlong' opts = GetoptLong.new( - [ "--help", "-?", GetoptLong::NO_ARGUMENT ], - [ "--server", "-s", GetoptLong::REQUIRED_ARGUMENT ], - [ "--name", "-n", GetoptLong::REQUIRED_ARGUMENT ], - [ "--description", "-d", GetoptLong::REQUIRED_ARGUMENT ], - [ "--key", "-k", GetoptLong::REQUIRED_ARGUMENT ], - [ "--arch", "-a", GetoptLong::REQUIRED_ARGUMENT ], - [ "--packages", "-p", GetoptLong::NO_ARGUMENT ], - [ "--hardware", "-h", GetoptLong::NO_ARGUMENT ], - [ "--solv", "-S", GetoptLong::REQUIRED_ARGUMENT ] + ["--help", "-?", GetoptLong::NO_ARGUMENT], + ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT], + ["--name", "-n", GetoptLong::REQUIRED_ARGUMENT], + ["--description", "-d", GetoptLong::REQUIRED_ARGUMENT], + ["--key", "-k", GetoptLong::REQUIRED_ARGUMENT], + ["--arch", "-a", GetoptLong::REQUIRED_ARGUMENT], + ["--packages", "-p", GetoptLong::NO_ARGUMENT], + ["--hardware", "-h", GetoptLong::NO_ARGUMENT], + ["--solv", "-S", GetoptLong::REQUIRED_ARGUMENT] ) result = {} opts.each do |opt, arg| diff --git a/bin/register_windows.rb b/bin/register_windows.rb index 2a942e6..26daa0d 100644 --- a/bin/register_windows.rb +++ b/bin/register_windows.rb @@ -27,14 +27,14 @@ def usage(msg=nil) def parse_args require 'getoptlong' opts = GetoptLong.new( - [ "--help", "-?", GetoptLong::NO_ARGUMENT ], - [ "--server", "-s", GetoptLong::REQUIRED_ARGUMENT ], - [ "--name", "-n", GetoptLong::REQUIRED_ARGUMENT ], - [ "--description", "-d", GetoptLong::REQUIRED_ARGUMENT ], - [ "--key", "-k", GetoptLong::REQUIRED_ARGUMENT ], - [ "--port", "-p", GetoptLong::REQUIRED_ARGUMENT ], - [ "--arch", "-a", GetoptLong::REQUIRED_ARGUMENT ], - [ "--solv", "-S", GetoptLong::REQUIRED_ARGUMENT ] + ["--help", "-?", GetoptLong::NO_ARGUMENT], + ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT], + ["--name", "-n", GetoptLong::REQUIRED_ARGUMENT], + ["--description", "-d", GetoptLong::REQUIRED_ARGUMENT], + ["--key", "-k", GetoptLong::REQUIRED_ARGUMENT], + ["--port", "-p", GetoptLong::REQUIRED_ARGUMENT], + ["--arch", "-a", GetoptLong::REQUIRED_ARGUMENT], + ["--solv", "-S", GetoptLong::REQUIRED_ARGUMENT] ) result = {} opts.each do |opt, arg| diff --git a/bin/submit.rb b/bin/submit.rb index 2f28a1c..6910500 100644 --- a/bin/submit.rb +++ b/bin/submit.rb @@ -33,11 +33,11 @@ def usage(msg=nil) def parse_args require 'getoptlong' opts = GetoptLong.new( - [ "--help", "-?", GetoptLong::NO_ARGUMENT ], - [ "--server", "-s", GetoptLong::REQUIRED_ARGUMENT ], - [ "--action", "-a", GetoptLong::REQUIRED_ARGUMENT ], - [ "--message", "-m", GetoptLong::REQUIRED_ARGUMENT ], - [ "--result", "-r", GetoptLong::REQUIRED_ARGUMENT ] + ["--help", "-?", GetoptLong::NO_ARGUMENT], + ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT], + ["--action", "-a", GetoptLong::REQUIRED_ARGUMENT], + ["--message", "-m", GetoptLong::REQUIRED_ARGUMENT], + ["--result", "-r", GetoptLong::REQUIRED_ARGUMENT] ) result = {} opts.each do |opt, arg| From 3cc333cbfe6c70eb9175fc6c0538c6acd8ec2b3d Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:18:46 +0100 Subject: [PATCH 19/42] rubocop style: Style/SpaceInsideParens --- bin/fakereg-threaded.rb | 4 ++-- bin/fakereg.rb | 4 ++-- bin/refresh.rb | 2 +- bin/windows.rb | 18 +++++++++--------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bin/fakereg-threaded.rb b/bin/fakereg-threaded.rb index 66763d8..5def24e 100644 --- a/bin/fakereg-threaded.rb +++ b/bin/fakereg-threaded.rb @@ -15,7 +15,7 @@ def usage(msg) STDERR.puts "*** #{msg}" if msg STDERR.puts "Usage:" STDERR.puts " fakereg --server [--port ] --key [--description ] [--solv --yaml ] --arch --count " - exit( msg ? 1 : 0) + exit(msg ? 1 : 0) end # @@ -84,7 +84,7 @@ def fake_profile if parms[:solv] require 'satsolver' pool = Satsolver::Pool.new - repo = pool.add_solv( parms[:solv] ) + repo = pool.add_solv(parms[:solv]) fail "Invalid .solv file: #{parms[:solv]}" unless repo if parms[:yaml] diff --git a/bin/fakereg.rb b/bin/fakereg.rb index d6b5db1..66cb804 100644 --- a/bin/fakereg.rb +++ b/bin/fakereg.rb @@ -15,7 +15,7 @@ def usage(msg) STDERR.puts "*** #{msg}" if msg STDERR.puts "Usage:" STDERR.puts " fakereg --server [--port ] --key [--description ] [--solv --yaml ] --arch --count " - exit( msg ? 1 : 0) + exit(msg ? 1 : 0) end # @@ -84,7 +84,7 @@ def fake_profile if parms[:solv] require 'satsolver' pool = Satsolver::Pool.new - repo = pool.add_solv( parms[:solv] ) + repo = pool.add_solv(parms[:solv]) fail "Invalid .solv file: #{parms[:solv]}" unless repo if parms[:yaml] diff --git a/bin/refresh.rb b/bin/refresh.rb index ea6883d..eb6cdc0 100644 --- a/bin/refresh.rb +++ b/bin/refresh.rb @@ -16,7 +16,7 @@ def usage(msg) STDERR.puts "*** #{msg}" if msg STDERR.puts "Usage:" STDERR.puts " refresh [--packages] [--hardware] --server " - exit( msg ? 1 : 0) + exit(msg ? 1 : 0) end # diff --git a/bin/windows.rb b/bin/windows.rb index dc805d6..046d6cd 100644 --- a/bin/windows.rb +++ b/bin/windows.rb @@ -87,7 +87,7 @@ def packages @wsopt.set_dump_request # Name of method invoked on the class (resp. instrance) method = "EnumKey" - result = @wsman.invoke( @wsopt, uri, method ) + result = @wsman.invoke(@wsopt, uri, method) # dump method, result if result.nil? || result.fault? fault @@ -108,7 +108,7 @@ def packages puts "sSubKeyName >#{properties['sSubKeyName']}<" @wsopt.properties = properties method = "EnumValues" - subresult = @wsman.invoke( @wsopt, uri, method ) + subresult = @wsman.invoke(@wsopt, uri, method) if subresult.nil? || subresult.fault? fault break @@ -154,7 +154,7 @@ def packages "sValueName" => key } @wsopt.properties = subproperties - value = @wsman.invoke( @wsopt, uri, method ) + value = @wsman.invoke(@wsopt, uri, method) package[packagekey] = value.send(valuename.to_sym).text rescue "" end time = package["installtime"] @@ -177,7 +177,7 @@ def bios puts "Checking the BIOS" uri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/" klass = "Win32_BIOS" - result = @wsman.enumerate( @wsopt, nil, uri + klass) + result = @wsman.enumerate(@wsopt, nil, uri + klass) bios = result.body.EnumerateResponse.Items.send(klass.to_sym) # dump klass, result return nil unless bios.SMBIOSPresent.to_s == "true" @@ -200,7 +200,7 @@ def network(only_enabled=true) puts "Enumerating network configurations" uri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/" klass = "Win32_NetworkAdapterConfiguration" - result = @wsman.enumerate( @wsopt, nil, uri + klass) + result = @wsman.enumerate(@wsopt, nil, uri + klass) result.Items.each do |node| if only_enabled next unless node.IPEnabled.to_s == "true" @@ -247,7 +247,7 @@ def hardware puts "Enumerating system devices" uri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/" klass = "Win32_SystemDevices" - result = @wsman.enumerate( @wsopt, nil, uri + klass) + result = @wsman.enumerate(@wsopt, nil, uri + klass) # dump klass, result # extract # @@ -273,7 +273,7 @@ def hardware # # Get device # - result = @wsman.get( @wsopt, uri ) + result = @wsman.get(@wsopt, uri) if result.nil? || result.fault? STDERR.puts "Can't get #{uri}:#{selectors['DeviceID'].split('')}" next @@ -312,7 +312,7 @@ def profile puts "Asking for operating system" uri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/" klass = "Win32_OperatingSystem" - result = @wsman.enumerate( @wsopt, nil, uri + klass) + result = @wsman.enumerate(@wsopt, nil, uri + klass) # dump klass, result # puts result.to_xml os = result.body.EnumerateResponse.Items.send(klass.to_sym) @@ -324,7 +324,7 @@ def profile puts "Asking for computer system" klass = "Win32_ComputerSystem" - result = @wsman.enumerate( @wsopt, nil, uri + klass) + result = @wsman.enumerate(@wsopt, nil, uri + klass) # dump klass, result hw = result.body.EnumerateResponse.Items.send(klass.to_sym) @data["TotalPhysicalMemory"] = hw.TotalPhysicalMemory.text From 35278aa8a477f5098b8a1088d7d6f88c7c7db2c0 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:19:31 +0100 Subject: [PATCH 20/42] rubocop style: Style/Style/StringLiterals --- Gemfile | 2 +- bin/actions.rb | 48 +++++----- bin/client.rb | 26 +++--- bin/fakereg-threaded.rb | 62 ++++++------- bin/fakereg.rb | 62 ++++++------- bin/refresh.rb | 22 ++--- bin/register_remote.rb | 62 ++++++------- bin/register_windows.rb | 46 +++++----- bin/submit.rb | 38 ++++---- bin/windows.rb | 158 ++++++++++++++++----------------- lib/spacewalk.rb | 10 +-- lib/spacewalk/capabilities.rb | 4 +- lib/spacewalk/config.rb | 2 +- lib/spacewalk/server.rb | 54 +++++------ lib/spacewalk/status_report.rb | 6 +- lib/spacewalk/system_id.rb | 4 +- lib/spacewalk/version.rb | 2 +- lib/spacewalk/xmlrpc.rb | 26 +++--- spacewalk.gemspec | 16 ++-- tasks/doc.rake | 4 +- 20 files changed, 327 insertions(+), 327 deletions(-) diff --git a/Gemfile b/Gemfile index 0d33f08..7a9e487 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source "http://rubygems.org" +source 'http://rubygems.org' # Specify your gem's dependencies in spacewalk.gemspec gemspec diff --git a/bin/actions.rb b/bin/actions.rb index 5cd2141..18a568c 100644 --- a/bin/actions.rb +++ b/bin/actions.rb @@ -5,9 +5,9 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) +$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) -require "spacewalk" +require 'spacewalk' require File.expand_path(File.join(File.dirname(__FILE__), 'client')) # @@ -16,11 +16,11 @@ def usage(msg=nil) STDERR.puts "*** #{msg}" if msg - STDERR.puts "Usage:" - STDERR.puts " actions [] " - STDERR.puts " --server " - STDERR.puts " --future " - STDERR.puts "Checks server for client actions" + STDERR.puts 'Usage:' + STDERR.puts ' actions [] ' + STDERR.puts ' --server ' + STDERR.puts ' --future ' + STDERR.puts 'Checks server for client actions' exit(msg ? 1 : 0) end @@ -31,20 +31,20 @@ def usage(msg=nil) def parse_args require 'getoptlong' opts = GetoptLong.new( - ["--help", "-?", GetoptLong::NO_ARGUMENT], - ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT], - ["--future", "-f", GetoptLong::REQUIRED_ARGUMENT] + ['--help', '-?', GetoptLong::NO_ARGUMENT], + ['--server', '-s', GetoptLong::REQUIRED_ARGUMENT], + ['--future', '-f', GetoptLong::REQUIRED_ARGUMENT] ) result = {} opts.each do |opt, arg| result[opt[2..-1].to_sym] = arg end usage if result[:help] - usage("No server url given") unless result[:server] + usage('No server url given') unless result[:server] unless result[:solv] - usage("No given") if ARGV.empty? + usage('No given') if ARGV.empty? result[:fqdn] = ARGV.shift - usage("Multiple s given") unless ARGV.empty? + usage('Multiple s given') unless ARGV.empty? end result end @@ -54,16 +54,16 @@ def parse_args # {"id"=>6437, "version"=>2, "action"=>["packages.update", [[["aalib-devel", "1.4.0", "503.1.3", "", ""]]]]} # def mk_promise(action) - id = action["id"] - task, packages = action["action"] - promise = "bundle agent " + id = action['id'] + task, packages = action['action'] + promise = 'bundle agent ' case task - when "packages.remove" - promise << "mgr_remove" - policy = "add" - when "packages.update" - promise << "mgr_update" - policy = "remove" + when 'packages.remove' + promise << 'mgr_remove' + policy = 'add' + when 'packages.update' + promise << 'mgr_update' + policy = 'remove' else fail "Task '#{task}' not supported" end @@ -71,7 +71,7 @@ def mk_promise(action) first = true packages[0].each do |package| name, version, release, epoch, arch = package - promise << ", " unless first + promise << ', ' unless first first = false promise << "\"#{name}-#{version}-#{release}\"" end @@ -112,7 +112,7 @@ def mk_promise(action) actions.each do |action| puts mk_promise action unless parms[:future] - server.submit_response parms[:action], "0", "Action converted to promise", { } + server.submit_response parms[:action], '0', 'Action converted to promise', { } end end end diff --git a/bin/client.rb b/bin/client.rb index 35aa4bd..8bbfaf9 100644 --- a/bin/client.rb +++ b/bin/client.rb @@ -10,7 +10,7 @@ class Client # Dump result as XML to file # def dump(klass, result) - File.open("#{klass}.xml", "w+") do |f| + File.open("#{klass}.xml", 'w+') do |f| f.write result.to_xml end end @@ -37,10 +37,10 @@ def packages IO.popen("rpm -qa --queryformat \"%{name} %{epoch} %{version} %{release} %{arch} %{installtime}\n\"") do |io| io.each do |rpm| - name, epoch, version, release, arch, installtime = rpm.split(" ") - next if name == "gpg-pubkey" - next if arch == "src" - package = { "name" => name, "epoch" => epoch, "version" => version, "release" => release, "arch" => arch, "installtime" => installtime.to_i } + name, epoch, version, release, arch, installtime = rpm.split(' ') + next if name == 'gpg-pubkey' + next if arch == 'src' + package = { 'name' => name, 'epoch' => epoch, 'version' => version, 'release' => release, 'arch' => arch, 'installtime' => installtime.to_i } puts package.inspect packages << package end @@ -64,16 +64,16 @@ def profile # HOME_URL="https://opensuse.org/" # ID_LIKE="suse" - data = { "architecture" => RUBY_PLATFORM.split("-")[0] } - File.open("/etc/os-release") do |f| + data = { 'architecture' => RUBY_PLATFORM.split('-')[0] } + File.open('/etc/os-release') do |f| f.each do |l| - key, val = l.chomp.split("=") + key, val = l.chomp.split('=') val = val[1, -2] if val[0][1] == '"' case key - when "VERSION_ID" - data["os_release"] = val - when "PRETTY_NAME" - data["release_name"] = val + when 'VERSION_ID' + data['os_release'] = val + when 'PRETTY_NAME' + data['release_name'] = val end end end @@ -83,6 +83,6 @@ def profile end # client if $0 == __FILE__ - client = Client.new "1.1.1.1" + client = Client.new '1.1.1.1' puts client.packages.inspect end diff --git a/bin/fakereg-threaded.rb b/bin/fakereg-threaded.rb index 5def24e..b47199d 100644 --- a/bin/fakereg-threaded.rb +++ b/bin/fakereg-threaded.rb @@ -3,9 +3,9 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) +$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) -require "spacewalk" +require 'spacewalk' # # Usage @@ -13,8 +13,8 @@ def usage(msg) STDERR.puts "*** #{msg}" if msg - STDERR.puts "Usage:" - STDERR.puts " fakereg --server [--port ] --key [--description ] [--solv --yaml ] --arch --count " + STDERR.puts 'Usage:' + STDERR.puts ' fakereg --server [--port ] --key [--description ] [--solv --yaml ] --arch --count ' exit(msg ? 1 : 0) end @@ -25,22 +25,22 @@ def usage(msg) def parse_args require 'getoptlong' opts = GetoptLong.new( - ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT], - ["--description", "-d", GetoptLong::REQUIRED_ARGUMENT], - ["--key", "-k", GetoptLong::REQUIRED_ARGUMENT], - ["--port", "-p", GetoptLong::REQUIRED_ARGUMENT], - ["--arch", "-a", GetoptLong::REQUIRED_ARGUMENT], - ["--solv", "-S", GetoptLong::REQUIRED_ARGUMENT], - ["--yaml", "-Y", GetoptLong::REQUIRED_ARGUMENT], - ["--count", "-c", GetoptLong::REQUIRED_ARGUMENT] + ['--server', '-s', GetoptLong::REQUIRED_ARGUMENT], + ['--description', '-d', GetoptLong::REQUIRED_ARGUMENT], + ['--key', '-k', GetoptLong::REQUIRED_ARGUMENT], + ['--port', '-p', GetoptLong::REQUIRED_ARGUMENT], + ['--arch', '-a', GetoptLong::REQUIRED_ARGUMENT], + ['--solv', '-S', GetoptLong::REQUIRED_ARGUMENT], + ['--yaml', '-Y', GetoptLong::REQUIRED_ARGUMENT], + ['--count', '-c', GetoptLong::REQUIRED_ARGUMENT] ) result = {} opts.each do |opt, arg| result[opt[2..-1].to_sym] = arg end - usage("No server url given") unless result[:server] - usage("No activationkey given") unless result[:key] - usage("No given") if ARGV.empty? + usage('No server url given') unless result[:server] + usage('No activationkey given') unless result[:key] + usage('No given') if ARGV.empty? result[:name] = ARGV.shift result end @@ -52,12 +52,12 @@ def repo_packages(repo) packages = [] repo.each do |p| entry = {} - entry["name"] = p.name.to_s - entry["epoch"] = (p.epoch || "0").to_s - entry["version"] = p.version.to_s - entry["release"] = p.revision.to_s - entry["arch"] = p.arch.to_s - entry["installtime"] = p["solvable:installtime"] + entry['name'] = p.name.to_s + entry['epoch'] = (p.epoch || '0').to_s + entry['version'] = p.version.to_s + entry['release'] = p.revision.to_s + entry['arch'] = p.arch.to_s + entry['installtime'] = p['solvable:installtime'] packages << entry end packages @@ -67,9 +67,9 @@ def fake_profile # assemble registration information data = {} - data["os_release"] = "Fake testing" - data["release_name"] = "ruby-spacewalk" - data["architecture"] = "x86_64" + data['os_release'] = 'Fake testing' + data['release_name'] = 'ruby-spacewalk' + data['architecture'] = 'x86_64' data end #------------------------------------ @@ -90,8 +90,8 @@ def fake_profile if parms[:yaml] require 'yaml' packages = repo_packages repo - File.open(parms[:yaml], "w") do |f| - f.puts "---" + File.open(parms[:yaml], 'w') do |f| + f.puts '---' # somehow, YAML::dump(packages, f) does not work packages.each do |p| first = true @@ -113,14 +113,14 @@ def fake_profile require 'yaml' packages = YAML::load_file(parms[:yaml]) else - STDERR.puts "No --solv and no --yaml given, skipping packages" + STDERR.puts 'No --solv and no --yaml given, skipping packages' end end count = parms[:count].to_i rescue 1 profile = fake_profile -profile["packages"] = packages +profile['packages'] = packages start = Time.now puts "Start at #{start}, #{count} systems" @@ -133,10 +133,10 @@ def fake_profile server = Spacewalk::Server.new :noconfig => true, :server => parms[:server] # get "os_release","release_name","architecture" - name = "%s%04d" % [parms[:name], i] + name = '%s%04d' % [parms[:name], i] print "Registering #{name}\n" systemid = server.register parms[:key], name, profile - File.open("#{name}.systemid", "w+") do |f| + File.open("#{name}.systemid", 'w+') do |f| f.write systemid end print "#{name} successfully registered\n" @@ -146,7 +146,7 @@ def fake_profile end end end -puts "Waiting for threads" +puts 'Waiting for threads' threads.each { |t| t.join } stop = Time.now diff --git a/bin/fakereg.rb b/bin/fakereg.rb index 66cb804..4fbe3ac 100644 --- a/bin/fakereg.rb +++ b/bin/fakereg.rb @@ -3,9 +3,9 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) +$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) -require "spacewalk" +require 'spacewalk' # # Usage @@ -13,8 +13,8 @@ def usage(msg) STDERR.puts "*** #{msg}" if msg - STDERR.puts "Usage:" - STDERR.puts " fakereg --server [--port ] --key [--description ] [--solv --yaml ] --arch --count " + STDERR.puts 'Usage:' + STDERR.puts ' fakereg --server [--port ] --key [--description ] [--solv --yaml ] --arch --count ' exit(msg ? 1 : 0) end @@ -25,22 +25,22 @@ def usage(msg) def parse_args require 'getoptlong' opts = GetoptLong.new( - ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT], - ["--description", "-d", GetoptLong::REQUIRED_ARGUMENT], - ["--key", "-k", GetoptLong::REQUIRED_ARGUMENT], - ["--port", "-p", GetoptLong::REQUIRED_ARGUMENT], - ["--arch", "-a", GetoptLong::REQUIRED_ARGUMENT], - ["--solv", "-S", GetoptLong::REQUIRED_ARGUMENT], - ["--yaml", "-Y", GetoptLong::REQUIRED_ARGUMENT], - ["--count", "-c", GetoptLong::REQUIRED_ARGUMENT] + ['--server', '-s', GetoptLong::REQUIRED_ARGUMENT], + ['--description', '-d', GetoptLong::REQUIRED_ARGUMENT], + ['--key', '-k', GetoptLong::REQUIRED_ARGUMENT], + ['--port', '-p', GetoptLong::REQUIRED_ARGUMENT], + ['--arch', '-a', GetoptLong::REQUIRED_ARGUMENT], + ['--solv', '-S', GetoptLong::REQUIRED_ARGUMENT], + ['--yaml', '-Y', GetoptLong::REQUIRED_ARGUMENT], + ['--count', '-c', GetoptLong::REQUIRED_ARGUMENT] ) result = {} opts.each do |opt, arg| result[opt[2..-1].to_sym] = arg end - usage("No server url given") unless result[:server] - usage("No activationkey given") unless result[:key] - usage("No given") if ARGV.empty? + usage('No server url given') unless result[:server] + usage('No activationkey given') unless result[:key] + usage('No given') if ARGV.empty? result[:name] = ARGV.shift result end @@ -52,12 +52,12 @@ def repo_packages(repo) packages = [] repo.each do |p| entry = {} - entry["name"] = p.name.to_s - entry["epoch"] = (p.epoch || "0").to_s - entry["version"] = p.version.to_s - entry["release"] = p.revision.to_s - entry["arch"] = p.arch.to_s - entry["installtime"] = p["solvable:installtime"] + entry['name'] = p.name.to_s + entry['epoch'] = (p.epoch || '0').to_s + entry['version'] = p.version.to_s + entry['release'] = p.revision.to_s + entry['arch'] = p.arch.to_s + entry['installtime'] = p['solvable:installtime'] packages << entry end packages @@ -67,9 +67,9 @@ def fake_profile # assemble registration information data = {} - data["os_release"] = "Fake testing" - data["release_name"] = "ruby-spacewalk" - data["architecture"] = "x86_64" + data['os_release'] = 'Fake testing' + data['release_name'] = 'ruby-spacewalk' + data['architecture'] = 'x86_64' data end #------------------------------------ @@ -90,8 +90,8 @@ def fake_profile if parms[:yaml] require 'yaml' packages = repo_packages repo - File.open(parms[:yaml], "w") do |f| - f.puts "---" + File.open(parms[:yaml], 'w') do |f| + f.puts '---' # somehow, YAML::dump(packages, f) does not work packages.each do |p| first = true @@ -113,14 +113,14 @@ def fake_profile require 'yaml' packages = YAML::load_file(parms[:yaml]) else - STDERR.puts "No --solv and no --yaml given, skipping packages" + STDERR.puts 'No --solv and no --yaml given, skipping packages' end end count = parms[:count].to_i rescue 1 profile = fake_profile -profile["packages"] = packages if packages +profile['packages'] = packages if packages start = Time.now puts "Start at #{start}, #{count} systems" @@ -132,10 +132,10 @@ def fake_profile begin # get "os_release","release_name","architecture" - name = "%s%04d" % [parms[:name], i] + name = '%s%04d' % [parms[:name], i] print "Registering #{name}\n" systemid = server.register parms[:key], name, profile - File.open("#{name}.systemid", "w+") do |f| + File.open("#{name}.systemid", 'w+') do |f| f.write systemid end print "#{name} successfully registered\n" @@ -150,5 +150,5 @@ def fake_profile if good > 0 puts "Registered #{good} of #{count} systems at #{parms[:server]} in #{elapsed} seconds (#{good / elapsed} systems/sec, #{elapsed / good} secs/system)" else - puts "Oops, no systems were registered" + puts 'Oops, no systems were registered' end diff --git a/bin/refresh.rb b/bin/refresh.rb index eb6cdc0..5873219 100644 --- a/bin/refresh.rb +++ b/bin/refresh.rb @@ -3,9 +3,9 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) +$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) -require "spacewalk" +require 'spacewalk' require File.expand_path(File.join(File.dirname(__FILE__), 'windows')) # @@ -14,8 +14,8 @@ def usage(msg) STDERR.puts "*** #{msg}" if msg - STDERR.puts "Usage:" - STDERR.puts " refresh [--packages] [--hardware] --server " + STDERR.puts 'Usage:' + STDERR.puts ' refresh [--packages] [--hardware] --server ' exit(msg ? 1 : 0) end @@ -26,19 +26,19 @@ def usage(msg) def parse_args require 'getoptlong' opts = GetoptLong.new( - ["--port", "-P", GetoptLong::REQUIRED_ARGUMENT], - ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT], - ["--packages", "-p", GetoptLong::NO_ARGUMENT], - ["--hardware", "-h", GetoptLong::NO_ARGUMENT] + ['--port', '-P', GetoptLong::REQUIRED_ARGUMENT], + ['--server', '-s', GetoptLong::REQUIRED_ARGUMENT], + ['--packages', '-p', GetoptLong::NO_ARGUMENT], + ['--hardware', '-h', GetoptLong::NO_ARGUMENT] ) result = {} opts.each do |opt, arg| result[opt[2..-1].to_sym] = arg end - usage("No server url given") unless result[:server] - usage("No given") if ARGV.empty? + usage('No server url given') unless result[:server] + usage('No given') if ARGV.empty? result[:fqdn] = ARGV.shift - usage("Multiple s given") unless ARGV.empty? + usage('Multiple s given') unless ARGV.empty? result end diff --git a/bin/register_remote.rb b/bin/register_remote.rb index db196a4..e268a12 100644 --- a/bin/register_remote.rb +++ b/bin/register_remote.rb @@ -5,9 +5,9 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) +$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) -require "spacewalk" +require 'spacewalk' require File.expand_path(File.join(File.dirname(__FILE__), 'client')) # @@ -16,16 +16,16 @@ def usage(msg=nil) STDERR.puts "*** #{msg}" if msg - STDERR.puts "Usage:" - STDERR.puts " register_remote [] " - STDERR.puts " --server " - STDERR.puts " --key " - STDERR.puts " --name " - STDERR.puts " --description " - STDERR.puts " --packages" - STDERR.puts " --hardware" - STDERR.puts " --solv " - STDERR.puts " --arch " + STDERR.puts 'Usage:' + STDERR.puts ' register_remote [] ' + STDERR.puts ' --server ' + STDERR.puts ' --key ' + STDERR.puts ' --name ' + STDERR.puts ' --description ' + STDERR.puts ' --packages' + STDERR.puts ' --hardware' + STDERR.puts ' --solv ' + STDERR.puts ' --arch ' STDERR.puts "Does a registration of a 'remote' client system" exit(msg ? 1 : 0) end @@ -37,26 +37,26 @@ def usage(msg=nil) def parse_args require 'getoptlong' opts = GetoptLong.new( - ["--help", "-?", GetoptLong::NO_ARGUMENT], - ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT], - ["--name", "-n", GetoptLong::REQUIRED_ARGUMENT], - ["--description", "-d", GetoptLong::REQUIRED_ARGUMENT], - ["--key", "-k", GetoptLong::REQUIRED_ARGUMENT], - ["--arch", "-a", GetoptLong::REQUIRED_ARGUMENT], - ["--packages", "-p", GetoptLong::NO_ARGUMENT], - ["--hardware", "-h", GetoptLong::NO_ARGUMENT], - ["--solv", "-S", GetoptLong::REQUIRED_ARGUMENT] + ['--help', '-?', GetoptLong::NO_ARGUMENT], + ['--server', '-s', GetoptLong::REQUIRED_ARGUMENT], + ['--name', '-n', GetoptLong::REQUIRED_ARGUMENT], + ['--description', '-d', GetoptLong::REQUIRED_ARGUMENT], + ['--key', '-k', GetoptLong::REQUIRED_ARGUMENT], + ['--arch', '-a', GetoptLong::REQUIRED_ARGUMENT], + ['--packages', '-p', GetoptLong::NO_ARGUMENT], + ['--hardware', '-h', GetoptLong::NO_ARGUMENT], + ['--solv', '-S', GetoptLong::REQUIRED_ARGUMENT] ) result = {} opts.each do |opt, arg| result[opt[2..-1].to_sym] = arg end usage if result[:help] - usage("No server url given") unless result[:server] + usage('No server url given') unless result[:server] unless result[:solv] - usage("No given") if ARGV.empty? + usage('No given') if ARGV.empty? result[:fqdn] = ARGV.shift - usage("Multiple s given") unless ARGV.empty? + usage('Multiple s given') unless ARGV.empty? end result end @@ -92,20 +92,20 @@ def parse_args begin server = Spacewalk::Server.new :noconfig => true, :server => parms[:server], :systemid => systemid - puts " Computing profile" + puts ' Computing profile' # get "os_release","release_name","architecture" profile = client.profile # override with CLI arg - profile["architecture"] = parms[:arch] if parms[:arch] + profile['architecture'] = parms[:arch] if parms[:arch] # if empty, Spacewalk will create it - profile["description"] = parms[:description] + profile['description'] = parms[:description] unless systemid - puts "Must register" - usage("No activationkey given") unless parms[:key] - puts "Registering" + puts 'Must register' + usage('No activationkey given') unless parms[:key] + puts 'Registering' systemid = server.register parms[:key], parms[:name] || fqdn, profile - File.open(fqdn, "w+") do |f| + File.open(fqdn, 'w+') do |f| f.write systemid end puts "#{fqdn} successfully registered" diff --git a/bin/register_windows.rb b/bin/register_windows.rb index 26daa0d..efe08bc 100644 --- a/bin/register_windows.rb +++ b/bin/register_windows.rb @@ -3,9 +3,9 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) +$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) -require "spacewalk" +require 'spacewalk' require File.expand_path(File.join(File.dirname(__FILE__), 'windows')) # @@ -14,9 +14,9 @@ def usage(msg=nil) STDERR.puts "*** #{msg}" if msg - STDERR.puts "Usage:" - STDERR.puts " register_windows --server --key --name --description --solv --port --arch " - STDERR.puts "Does a registration of a remote Windows system (identified by and " + STDERR.puts 'Usage:' + STDERR.puts ' register_windows --server --key --name --description --solv --port --arch ' + STDERR.puts 'Does a registration of a remote Windows system (identified by and ' exit(msg ? 1 : 0) end @@ -27,26 +27,26 @@ def usage(msg=nil) def parse_args require 'getoptlong' opts = GetoptLong.new( - ["--help", "-?", GetoptLong::NO_ARGUMENT], - ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT], - ["--name", "-n", GetoptLong::REQUIRED_ARGUMENT], - ["--description", "-d", GetoptLong::REQUIRED_ARGUMENT], - ["--key", "-k", GetoptLong::REQUIRED_ARGUMENT], - ["--port", "-p", GetoptLong::REQUIRED_ARGUMENT], - ["--arch", "-a", GetoptLong::REQUIRED_ARGUMENT], - ["--solv", "-S", GetoptLong::REQUIRED_ARGUMENT] + ['--help', '-?', GetoptLong::NO_ARGUMENT], + ['--server', '-s', GetoptLong::REQUIRED_ARGUMENT], + ['--name', '-n', GetoptLong::REQUIRED_ARGUMENT], + ['--description', '-d', GetoptLong::REQUIRED_ARGUMENT], + ['--key', '-k', GetoptLong::REQUIRED_ARGUMENT], + ['--port', '-p', GetoptLong::REQUIRED_ARGUMENT], + ['--arch', '-a', GetoptLong::REQUIRED_ARGUMENT], + ['--solv', '-S', GetoptLong::REQUIRED_ARGUMENT] ) result = {} opts.each do |opt, arg| result[opt[2..-1].to_sym] = arg end usage if result[:help] - usage("No server url given") unless result[:server] - usage("No activationkey given") unless result[:key] + usage('No server url given') unless result[:server] + usage('No activationkey given') unless result[:key] unless result[:solv] - usage("No given") if ARGV.empty? + usage('No given') if ARGV.empty? result[:fqdn] = ARGV.shift - usage("Multiple s given") unless ARGV.empty? + usage('Multiple s given') unless ARGV.empty? end result end @@ -83,17 +83,17 @@ def parse_args server = Spacewalk::Server.new :noconfig => true, :server => parms[:server], :systemid => systemid unless systemid - puts "Must register" - puts "Retrieving Windows profile" + puts 'Must register' + puts 'Retrieving Windows profile' # get "os_release","release_name","architecture" profile = windows.profile # override with CLI arg - profile["architecture"] = parms[:arch] if parms[:arch] + profile['architecture'] = parms[:arch] if parms[:arch] # if empty, Spacewalk will create it - profile["description"] = parms[:description] - puts "Registering" + profile['description'] = parms[:description] + puts 'Registering' systemid = server.register parms[:key], parms[:name] || fqdn, profile - File.open(fqdn, "w+") do |f| + File.open(fqdn, 'w+') do |f| f.write systemid end puts "#{fqdn} successfully registered" diff --git a/bin/submit.rb b/bin/submit.rb index 6910500..6296196 100644 --- a/bin/submit.rb +++ b/bin/submit.rb @@ -5,9 +5,9 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) +$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) -require "spacewalk" +require 'spacewalk' require File.expand_path(File.join(File.dirname(__FILE__), 'client')) # @@ -16,13 +16,13 @@ def usage(msg=nil) STDERR.puts "*** #{msg}" if msg - STDERR.puts "Usage:" - STDERR.puts " submit [] " - STDERR.puts " --server " - STDERR.puts " --action " - STDERR.puts " --message " - STDERR.puts " --result " - STDERR.puts "Submit action status back to server" + STDERR.puts 'Usage:' + STDERR.puts ' submit [] ' + STDERR.puts ' --server ' + STDERR.puts ' --action ' + STDERR.puts ' --message ' + STDERR.puts ' --result ' + STDERR.puts 'Submit action status back to server' exit(msg ? 1 : 0) end @@ -33,23 +33,23 @@ def usage(msg=nil) def parse_args require 'getoptlong' opts = GetoptLong.new( - ["--help", "-?", GetoptLong::NO_ARGUMENT], - ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT], - ["--action", "-a", GetoptLong::REQUIRED_ARGUMENT], - ["--message", "-m", GetoptLong::REQUIRED_ARGUMENT], - ["--result", "-r", GetoptLong::REQUIRED_ARGUMENT] + ['--help', '-?', GetoptLong::NO_ARGUMENT], + ['--server', '-s', GetoptLong::REQUIRED_ARGUMENT], + ['--action', '-a', GetoptLong::REQUIRED_ARGUMENT], + ['--message', '-m', GetoptLong::REQUIRED_ARGUMENT], + ['--result', '-r', GetoptLong::REQUIRED_ARGUMENT] ) result = {} opts.each do |opt, arg| result[opt[2..-1].to_sym] = arg end usage if result[:help] - usage("No server url given") unless result[:server] - usage("No action id given") unless result[:action] + usage('No server url given') unless result[:server] + usage('No action id given') unless result[:action] unless result[:solv] - usage("No given") if ARGV.empty? + usage('No given') if ARGV.empty? result[:fqdn] = ARGV.shift - usage("Multiple s given") unless ARGV.empty? + usage('Multiple s given') unless ARGV.empty? end result end @@ -84,7 +84,7 @@ def mk_promise(_actions) begin systemid = File.open(fqdn).read server = Spacewalk::Server.new :noconfig => true, :server => parms[:server], :systemid => systemid - server.submit_response parms[:action], "0", parms[:message], { } + server.submit_response parms[:action], '0', parms[:message], { } rescue raise end diff --git a/bin/windows.rb b/bin/windows.rb index 046d6cd..36606eb 100644 --- a/bin/windows.rb +++ b/bin/windows.rb @@ -25,7 +25,7 @@ class Windows } def dump(klass, result) - File.open("#{klass}.xml", "w+") do |f| + File.open("#{klass}.xml", 'w+') do |f| f.write result.to_xml end end @@ -52,18 +52,18 @@ def fault(result = nil) STDERR.puts "\treason #{fault.reason}" STDERR.puts "\tdetail #{fault.detail}" else - STDERR.puts "Generic fault" + STDERR.puts 'Generic fault' STDERR.puts "Client error #{@wsman.last_error}" STDERR.puts "Client msg #{@wsman.fault_string}" end end def packages - puts "Enumerating package information" + puts 'Enumerating package information' # Class uri # note the root/default namespace (not root/cimv2) # - uri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/default/StdRegProv" + uri = 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/default/StdRegProv' # Selectors are for key/value pairs identifying instances # @@ -78,15 +78,15 @@ def packages # The sSubKeyName is the path name within the Registry # - uninstall_key = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall" + uninstall_key = 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall' properties = { - "hDefKey" => HKEYS[:HKEY_LOCAL_MACHINE].to_s, - "sSubKeyName" => uninstall_key + 'hDefKey' => HKEYS[:HKEY_LOCAL_MACHINE].to_s, + 'sSubKeyName' => uninstall_key } @wsopt.properties = properties @wsopt.set_dump_request # Name of method invoked on the class (resp. instrance) - method = "EnumKey" + method = 'EnumKey' result = @wsman.invoke(@wsopt, uri, method) # dump method, result if result.nil? || result.fault? @@ -96,18 +96,18 @@ def packages puts result.to_xml # map Registry keys to package keys keymap = { - "DisplayName" => "name", - "DisplayVersion" => "version", - "InstallDate" => "installtime" + 'DisplayName' => 'name', + 'DisplayVersion' => 'version', + 'InstallDate' => 'installtime' } packages = [] - result.EnumKey_OUTPUT.each("sNames") do |node| + result.EnumKey_OUTPUT.each('sNames') do |node| puts "Node #{node.text.inspect}" - properties["sSubKeyName"] = uninstall_key + "\\" + CGI::escapeHTML(node.text) + properties['sSubKeyName'] = uninstall_key + '\\' + CGI::escapeHTML(node.text) puts "sSubKeyName >#{properties['sSubKeyName']}<" @wsopt.properties = properties - method = "EnumValues" + method = 'EnumValues' subresult = @wsman.invoke(@wsopt, uri, method) if subresult.nil? || subresult.fault? fault @@ -122,11 +122,11 @@ def packages end package = { - "name" => node.text, - "epoch" => "", - "version" => "", - "release" => "", - "arch" => "i386" + 'name' => node.text, + 'epoch' => '', + 'version' => '', + 'release' => '', + 'arch' => 'i386' } subresult.sNames.each do |key| packagekey = keymap[key.text] @@ -136,37 +136,37 @@ def packages reg_type = TYPES[type] method, valuename = case reg_type when :REG_SZ - ["GetStringValue", "sValue"] # string + ['GetStringValue', 'sValue'] # string when :REG_EXPAND_SZ - ["GetExpandedStringValue", "sValue"] # expanded string + ['GetExpandedStringValue', 'sValue'] # expanded string when :REG_BINARY - ["GetBinaryValue", "uValue"] # blob + ['GetBinaryValue', 'uValue'] # blob when :REG_DWORD - ["GetDWORDValue", "uValue"] # integer + ['GetDWORDValue', 'uValue'] # integer when :REG_MULTI_SZ - ["GetMultiStringValue", "sValue"] # multi string + ['GetMultiStringValue', 'sValue'] # multi string else fail "Unknown type #{type}" end subproperties = { - "hDefKey" => HKEYS[:HKEY_LOCAL_MACHINE].to_s, - "sSubKeyName" => uninstall_key + "\\" + node.text, - "sValueName" => key + 'hDefKey' => HKEYS[:HKEY_LOCAL_MACHINE].to_s, + 'sSubKeyName' => uninstall_key + '\\' + node.text, + 'sValueName' => key } @wsopt.properties = subproperties value = @wsman.invoke(@wsopt, uri, method) - package[packagekey] = value.send(valuename.to_sym).text rescue "" + package[packagekey] = value.send(valuename.to_sym).text rescue '' end - time = package["installtime"] + time = package['installtime'] if time # convert Windows time (20101127) to Spacewalk-time (seconds since 1.1.1970) t = time.to_s - package["installtime"] = Time.local(t[0, 4], t[4, 2], t[6, 2]).to_i + package['installtime'] = Time.local(t[0, 4], t[4, 2], t[6, 2]).to_i else - package["installtime"] = Time.local(1970, "Jan", 1).to_i + package['installtime'] = Time.local(1970, 'Jan', 1).to_i end - package["version"] = "0" if package["version"].empty? - package["release"] = "0" if package["release"].empty? + package['version'] = '0' if package['version'].empty? + package['release'] = '0' if package['release'].empty? packages << package end @@ -174,18 +174,18 @@ def packages end def bios - puts "Checking the BIOS" - uri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/" - klass = "Win32_BIOS" + puts 'Checking the BIOS' + uri = 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/' + klass = 'Win32_BIOS' result = @wsman.enumerate(@wsopt, nil, uri + klass) bios = result.body.EnumerateResponse.Items.send(klass.to_sym) # dump klass, result - return nil unless bios.SMBIOSPresent.to_s == "true" + return nil unless bios.SMBIOSPresent.to_s == 'true' result = {} # result["smbios.bios.vendor"] = bios. - result["smbios.system.serial"] = bios.SerialNumber - result["smbios.system.manufacturer"] = bios.Manufacturer - result["smbios.system.product"] = bios.Name + result['smbios.system.serial'] = bios.SerialNumber + result['smbios.system.manufacturer'] = bios.Manufacturer + result['smbios.system.product'] = bios.Name # result["smbios.system.uuid"] = result end @@ -197,28 +197,28 @@ def bios # def network(only_enabled=true) netinterfaces = nil - puts "Enumerating network configurations" - uri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/" - klass = "Win32_NetworkAdapterConfiguration" + puts 'Enumerating network configurations' + uri = 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/' + klass = 'Win32_NetworkAdapterConfiguration' result = @wsman.enumerate(@wsopt, nil, uri + klass) result.Items.each do |node| if only_enabled - next unless node.IPEnabled.to_s == "true" + next unless node.IPEnabled.to_s == 'true' end - unless @data["DNSDomain"] - @data["DNSDomain"] = node.DNSDomain.text + unless @data['DNSDomain'] + @data['DNSDomain'] = node.DNSDomain.text end - unless @data["DNSHostName"] - @data["DNSHostName"] = node.DNSHostName.text + unless @data['DNSHostName'] + @data['DNSHostName'] = node.DNSHostName.text end - unless @data["IPAddress"] - @data["IPAddress"] = node.IPAddress.text + unless @data['IPAddress'] + @data['IPAddress'] = node.IPAddress.text end netinterfaces ||= {} netinterfaces["net#{node.Index}"] = { 'hwaddr' => node.MACAddress.text, 'module' => node.ServiceName.text, - 'broadcast' => "255.255.255.255", # FIXME, compute from ip+subnet + 'broadcast' => '255.255.255.255', # FIXME, compute from ip+subnet 'ipaddr' => node.IPAddress.text, 'netmask' => node.IPSubnet.text } @@ -231,22 +231,22 @@ def network(only_enabled=true) # def hardware hw = [] - if @data["TotalPhysicalMemory"] - hw << { "class" => "memory", "ram" => (@data["TotalPhysicalMemory"].to_i / (1024 * 1024)).to_s } + if @data['TotalPhysicalMemory'] + hw << { 'class' => 'memory', 'ram' => (@data['TotalPhysicalMemory'].to_i / (1024 * 1024)).to_s } end net_if = network - if @data["DNSHostName"] && @data["DNSDomain"] && @data["IPAddress"] - hw << { "class" => "netinfo", - "hostname" => @data["DNSHostName"] + "." + @data["DNSDomain"].split(" ").first, - "ipaddr" => @data["IPAddress"] + if @data['DNSHostName'] && @data['DNSDomain'] && @data['IPAddress'] + hw << { 'class' => 'netinfo', + 'hostname' => @data['DNSHostName'] + '.' + @data['DNSDomain'].split(' ').first, + 'ipaddr' => @data['IPAddress'] } end # enum Win32_SystemDevices # then get CIM_LogicalDevice REF PartComponent; - puts "Enumerating system devices" - uri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/" - klass = "Win32_SystemDevices" + puts 'Enumerating system devices' + uri = 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/' + klass = 'Win32_SystemDevices' result = @wsman.enumerate(@wsopt, nil, uri + klass) # dump klass, result # extract @@ -280,24 +280,24 @@ def hardware end result.body.each do |node| case node.name - when "Win32_Processor" - hw << { "class" => "cpu", - 'architecture' => (node.Architecture.text == "9") ? "x86_64" : "i686", + when 'Win32_Processor' + hw << { 'class' => 'cpu', + 'architecture' => (node.Architecture.text == '9') ? 'x86_64' : 'i686', 'family' => node.Family.text, 'mhz' => node.MaxClockSpeed.text, 'stepping' => node.Stepping.text, 'model' => node.Name.text, 'vendor' => node.Manufacturer.text, - 'nrcpu' => result.body.size("Win32_Processor") + 'nrcpu' => result.body.size('Win32_Processor') } - when "Win32_NetworkAdapter" - when "Win32_PnPEntity" + when 'Win32_NetworkAdapter' + when 'Win32_PnPEntity' else STDERR.puts "Unhandled #{node.name}" end end if net_if - hw << net_if.merge({ 'class' => "netinterfaces" }) + hw << net_if.merge({ 'class' => 'netinterfaces' }) end end @@ -309,9 +309,9 @@ def hardware def profile begin - puts "Asking for operating system" - uri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/" - klass = "Win32_OperatingSystem" + puts 'Asking for operating system' + uri = 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/' + klass = 'Win32_OperatingSystem' result = @wsman.enumerate(@wsopt, nil, uri + klass) # dump klass, result # puts result.to_xml @@ -322,12 +322,12 @@ def profile # puts " #{node.name}:\t#{node.text}" # end - puts "Asking for computer system" - klass = "Win32_ComputerSystem" + puts 'Asking for computer system' + klass = 'Win32_ComputerSystem' result = @wsman.enumerate(@wsopt, nil, uri + klass) # dump klass, result hw = result.body.EnumerateResponse.Items.send(klass.to_sym) - @data["TotalPhysicalMemory"] = hw.TotalPhysicalMemory.text + @data['TotalPhysicalMemory'] = hw.TotalPhysicalMemory.text # debug # puts klass # hw.each do |node| @@ -340,20 +340,20 @@ def profile return {} end - puts "Assembling Windows profile" + puts 'Assembling Windows profile' # assemble registration information data = {} - data["os_release"] = os.CSDVersion.text + data['os_release'] = os.CSDVersion.text puts "OS Release #{os.CSDVersion.text}" - data["release_name"] = os.Caption.text + data['release_name'] = os.Caption.text puts "Release name #{os.Caption.text}" - data["architecture"] = case os.OSType.text.to_i - when 18 then "x86-microsoft-windows" # normalize architecture + data['architecture'] = case os.OSType.text.to_i + when 18 then 'x86-microsoft-windows' # normalize architecture else STDERR.puts "Can't map #{os.OSType} to a known value" - "x86-microsoft-windows" + 'x86-microsoft-windows' end puts "Windows.profile: #{data.inspect}" data diff --git a/lib/spacewalk.rb b/lib/spacewalk.rb index 34c6724..9620b6f 100644 --- a/lib/spacewalk.rb +++ b/lib/spacewalk.rb @@ -1,6 +1,6 @@ $: << File.dirname(__FILE__) -require "spacewalk/config" -require "spacewalk/system_id" -require "spacewalk/capabilities" -require "spacewalk/status_report" -require "spacewalk/server" +require 'spacewalk/config' +require 'spacewalk/system_id' +require 'spacewalk/capabilities' +require 'spacewalk/status_report' +require 'spacewalk/server' diff --git a/lib/spacewalk/capabilities.rb b/lib/spacewalk/capabilities.rb index b3737dc..8890539 100644 --- a/lib/spacewalk/capabilities.rb +++ b/lib/spacewalk/capabilities.rb @@ -4,8 +4,8 @@ class Capabilities def initialize(client) # hash of => @caps = {} - client.http_last_response["x-rhn-server-capability"].split(",").each do |caps| - caps.split(",").each do |cap| + client.http_last_response['x-rhn-server-capability'].split(',').each do |caps| + caps.split(',').each do |cap| # puts "#{cap}" fail "Invalid cap '#{cap}'" unless cap =~ /(\s+)?(((\w+)|\.)+)\((\d(-\d)?)\)=(\d)/ # name = [ version, value ] diff --git a/lib/spacewalk/config.rb b/lib/spacewalk/config.rb index d4e7ba1..aaa2073 100644 --- a/lib/spacewalk/config.rb +++ b/lib/spacewalk/config.rb @@ -1,6 +1,6 @@ module Spacewalk class Config - def initialize(path="/etc/sysconfig/rhn/up2date") + def initialize(path='/etc/sysconfig/rhn/up2date') @path = path @config = {} File.open path do |f| diff --git a/lib/spacewalk/server.rb b/lib/spacewalk/server.rb index cfb5d62..c92e6f5 100644 --- a/lib/spacewalk/server.rb +++ b/lib/spacewalk/server.rb @@ -12,7 +12,7 @@ class Server # action version we understand ACTION_VERSION = 2 - require "xmlrpc/client" + require 'xmlrpc/client' require 'openssl' require 'uri' require 'zlib' @@ -32,18 +32,18 @@ def call(name, *args) raise e unless e.message =~ /Wrong content-type/ end response = @client.http_last_response - fail "XMLRPC failed with #{response.code}" unless response.code == "200" + fail "XMLRPC failed with #{response.code}" unless response.code == '200' body = response.body - case response["content-type"] - when "text/base64" + case response['content-type'] + when 'text/base64' body = Base64.decode64(body) - when "text/xml" + when 'text/xml' # fallthru else STDERR.puts "Unhandled content-type #{response['content-type']}" end - case response["content-encoding"] - when "x-zlib" + case response['content-encoding'] + when 'x-zlib' body = Zlib::Inflate.inflate(body) when nil # fallthru @@ -68,30 +68,30 @@ def initialize(options = {}) if options[:noconfig] uri = URI.parse(options[:server]) fail "Server '#{options[:server]}' is not proper URL" unless uri.host - uri.path = "/XMLRPC" + uri.path = '/XMLRPC' else uri = URI.parse(@config.serverurl) end - args = {:host => uri.host, :path => uri.path, :use_ssl => (uri.scheme == "https"), :timeout => 120 } + args = {:host => uri.host, :path => uri.path, :use_ssl => (uri.scheme == 'https'), :timeout => 120 } unless options[:noconfig] if @config.httpProxy - args[:proxy_host], clientargs[:proxy_port] = @config.httpProxy.split ":" + args[:proxy_host], clientargs[:proxy_port] = @config.httpProxy.split ':' end end @client = XMLRPC::Client.new_from_hash args @client.http_header_extra = {} - @client.instance_variable_get("@http").verify_mode = OpenSSL::SSL::VERIFY_NONE + @client.instance_variable_get('@http').verify_mode = OpenSSL::SSL::VERIFY_NONE welcome # parse server capabilities @capabilities = Spacewalk::Capabilities.new @client - @client.http_header_extra["X-Up2date-Version"] = "1.6.42" # from rhn-client-tools.spec - @client.http_header_extra["X-RHN-Client-Capability"] = "packages.extended_profile(2)=1" + @client.http_header_extra['X-Up2date-Version'] = '1.6.42' # from rhn-client-tools.spec + @client.http_header_extra['X-RHN-Client-Capability'] = 'packages.extended_profile(2)=1' @systemid = options[:systemid] unless @systemid || options[:noconfig] @systemid = Spacewalk::SystemId.new(@client, @config).to_xml @@ -104,7 +104,7 @@ def initialize(options = {}) # welcome to/from server def welcome - result = call "registration.welcome_message" + result = call 'registration.welcome_message' # puts "Welcome => #{result.inspect}" end @@ -124,12 +124,12 @@ def actions # puts "report => #{report.inspect}" # puts "@systemid => #{@systemid.inspect}" - result = call "queue.get", @systemid, ACTION_VERSION, report + result = call 'queue.get', @systemid, ACTION_VERSION, report # puts "queue.get => #{result.inspect}" - action = result["action"] + action = result['action'] if action - result["action"] = @client.get_parser.parseMethodCall(action) + result['action'] = @client.get_parser.parseMethodCall(action) end # puts "Actions => #{result.inspect}" end @@ -144,12 +144,12 @@ def future_actions(time_window) report = Spacewalk::StatusReport.status # puts "future_actions #{time_window}" - results = call "queue.get_future_actions", @systemid, time_window + results = call 'queue.get_future_actions', @systemid, time_window # puts "queue.get_future_actions => #{results.inspect}" results.map! do |result| - action = result["action"] + action = result['action'] if action - result["action"] = @client.get_parser.parseMethodCall(action) + result['action'] = @client.get_parser.parseMethodCall(action) end result end @@ -160,8 +160,8 @@ def future_actions(time_window) # submit action result back to server # def submit_response(action_id, status, message, data) - fail "Data must be hash" unless data.is_a? Hash - result = call "queue.submit", @systemid, action_id, status, message, data + fail 'Data must be hash' unless data.is_a? Hash + result = call 'queue.submit', @systemid, action_id, status, message, data end # # register with activation key @@ -169,29 +169,29 @@ def submit_response(action_id, status, message, data) # def register(activationkey, profile_name, other = {}) auth_dict = {} - auth_dict["profile_name"] = profile_name + auth_dict['profile_name'] = profile_name # dict of other bits to send auth_dict.update other - auth_dict["token"] = activationkey + auth_dict['token'] = activationkey # auth_dict["username"] = username # auth_dict["password"] = password # if cfg['supportsSMBIOS']: # auth_dict["smbios"] = _encode_characters(hardware.get_smbios()) # STDERR.puts "registration.new_system #{auth_dict.inspect}" - @systemid = call "registration.new_system", auth_dict + @systemid = call 'registration.new_system', auth_dict end # # send package list to server # def send_packages(packages) - call "registration.add_packages", @systemid, packages + call 'registration.add_packages', @systemid, packages end # # send hardware details to server # def refresh_hardware(devices) - call "registration.refresh_hw_profile", @systemid, devices + call 'registration.refresh_hw_profile', @systemid, devices end end end diff --git a/lib/spacewalk/status_report.rb b/lib/spacewalk/status_report.rb index f3dee98..b80f428 100644 --- a/lib/spacewalk/status_report.rb +++ b/lib/spacewalk/status_report.rb @@ -5,10 +5,10 @@ def self.status # Return a 5-tuple containing information identifying the current operating system. # The tuple contains 5 strings: (sysname, nodename, release, version, machine). # (uname -s, uname -n, uname -r, uname -v, uname -m) - status["uname"] = [`uname -s`.chomp, `uname -n`.chomp, `uname -r`.chomp, `uname -v`.chomp, `uname -m`.chomp] + status['uname'] = [`uname -s`.chomp, `uname -n`.chomp, `uname -r`.chomp, `uname -v`.chomp, `uname -m`.chomp] begin - File.open("/proc/uptime") do |f| - status["uptime"] = f.read.split(" ").map{ |v| v.to_i } + File.open('/proc/uptime') do |f| + status['uptime'] = f.read.split(' ').map{ |v| v.to_i } end rescue nil diff --git a/lib/spacewalk/system_id.rb b/lib/spacewalk/system_id.rb index 069e0e8..d5cae61 100644 --- a/lib/spacewalk/system_id.rb +++ b/lib/spacewalk/system_id.rb @@ -3,8 +3,8 @@ class SystemId require 'xmlrpc/client' def initialize(client, config) fail "Expecting a Spacewalk::Config parameter to #{self.class}.new" unless config.is_a?(Spacewalk::Config) - @path = config["systemIdPath"] - fail "systemIdPath is empty !" unless @path + @path = config['systemIdPath'] + fail 'systemIdPath is empty !' unless @path # # # diff --git a/lib/spacewalk/version.rb b/lib/spacewalk/version.rb index 55614f1..224b0b1 100644 --- a/lib/spacewalk/version.rb +++ b/lib/spacewalk/version.rb @@ -1,3 +1,3 @@ module Spacewalk - VERSION = "0.0.2" + VERSION = '0.0.2' end diff --git a/lib/spacewalk/xmlrpc.rb b/lib/spacewalk/xmlrpc.rb index 5539c01..61f8424 100644 --- a/lib/spacewalk/xmlrpc.rb +++ b/lib/spacewalk/xmlrpc.rb @@ -7,23 +7,23 @@ def self.value2ruby(element) node = element[0] puts "value2ruby node #{node}" case node.name - when "string" + when 'string' node.text - when "struct" - fail "value2ruby: not following " unless node[0].name == "member" + when 'struct' + fail 'value2ruby: not following ' unless node[0].name == 'member' value = {} puts "Struct #{node}" - node.each_element("member") do |e| - name = e.elements["member/name"].text - v = value2ruby m.elements["member/value"] + node.each_element('member') do |e| + name = e.elements['member/name'].text + v = value2ruby m.elements['member/value'] value[name] = v end value - when "array" - fail "value2ruby: not following " unless node[0].name == "data" + when 'array' + fail 'value2ruby: not following ' unless node[0].name == 'data' value = [] # puts "Array #{node}" - node.each_element("data/value") do |e| + node.each_element('data/value') do |e| # puts "recursive #{e}" value << value2ruby(e) end @@ -45,14 +45,14 @@ def self.value2ruby(element) # ... # def self.decode(_what) - @doc.root.elements["params/param"] + @doc.root.elements['params/param'] initialize config fail "Expecting a Spacewalk::Config parameter to #{self.class}.new" unless config.is_a?(Spacewalk::Config) - @path = config["systemIdPath"] - fail "systemIdPath is empty !" unless @path + @path = config['systemIdPath'] + fail 'systemIdPath is empty !' unless @path @doc = REXML::Document.new(File.open(@path)) - @members = @doc.root.elements["params/param"] + @members = @doc.root.elements['params/param'] end end end diff --git a/spacewalk.gemspec b/spacewalk.gemspec index 8aef6b2..1aa27ee 100644 --- a/spacewalk.gemspec +++ b/spacewalk.gemspec @@ -1,20 +1,20 @@ # -*- encoding: utf-8 -*- -$:.push File.expand_path("../lib", __FILE__) -require "spacewalk/version" +$:.push File.expand_path('../lib', __FILE__) +require 'spacewalk/version' Gem::Specification.new do |s| - s.name = "spacewalk" + s.name = 'spacewalk' s.version = Spacewalk::VERSION s.platform = Gem::Platform::RUBY - s.authors = ["Klaus Kämpf"] - s.email = ["kkaempf@suse.de"] - s.homepage = "https://github.com/kkaempf/ruby-spacewalk" + s.authors = ['Klaus Kämpf'] + s.email = ['kkaempf@suse.de'] + s.homepage = 'https://github.com/kkaempf/ruby-spacewalk' s.summary = %q{A pure-Ruby implementation of the Spacewalk client side} s.description = %q{Can be used for testing or to attach 'foreign' systems} - s.rubyforge_project = "spacewalk" + s.rubyforge_project = 'spacewalk' s.add_development_dependency('rake') s.add_development_dependency('bundler') @@ -24,5 +24,5 @@ systems} s.extra_rdoc_files = Dir['README*', 'TODO*', 'CHANGELOG*', 'LICENSE'] s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } - s.require_paths = ["lib"] + s.require_paths = ['lib'] end diff --git a/tasks/doc.rake b/tasks/doc.rake index d67492b..194ef0a 100644 --- a/tasks/doc.rake +++ b/tasks/doc.rake @@ -5,10 +5,10 @@ begin t.options = ['--no-private'] end rescue LoadError - STDERR.puts "Install yard if you want prettier docs" + STDERR.puts 'Install yard if you want prettier docs' require 'rdoc/task' Rake::RDocTask.new(:doc) do |rdoc| - rdoc.rdoc_dir = "doc" + rdoc.rdoc_dir = 'doc' rdoc.title = "Spacewalk #{Spacewalk::VERSION}" end end From 6ebf48fe9c28b11278048740ba6f82bbf2814f99 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:20:02 +0100 Subject: [PATCH 21/42] rubocop style: Style/SymbolProc --- bin/fakereg-threaded.rb | 2 +- lib/spacewalk/status_report.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/fakereg-threaded.rb b/bin/fakereg-threaded.rb index b47199d..74ddfb7 100644 --- a/bin/fakereg-threaded.rb +++ b/bin/fakereg-threaded.rb @@ -147,7 +147,7 @@ def fake_profile end end puts 'Waiting for threads' -threads.each { |t| t.join } +threads.each(&:join) stop = Time.now elapsed = stop - start diff --git a/lib/spacewalk/status_report.rb b/lib/spacewalk/status_report.rb index b80f428..90080ce 100644 --- a/lib/spacewalk/status_report.rb +++ b/lib/spacewalk/status_report.rb @@ -8,7 +8,7 @@ def self.status status['uname'] = [`uname -s`.chomp, `uname -n`.chomp, `uname -r`.chomp, `uname -v`.chomp, `uname -m`.chomp] begin File.open('/proc/uptime') do |f| - status['uptime'] = f.read.split(' ').map{ |v| v.to_i } + status['uptime'] = f.read.split(' ').map(&:to_i) end rescue nil From 3b4718ae279b6d36ed6de3c3d700ed09d22e94b6 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:26:40 +0100 Subject: [PATCH 22/42] rubocop style: Style/TrailingBlankLines --- lib/spacewalk/system_id.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spacewalk/system_id.rb b/lib/spacewalk/system_id.rb index d5cae61..1ba7d4a 100644 --- a/lib/spacewalk/system_id.rb +++ b/lib/spacewalk/system_id.rb @@ -24,4 +24,4 @@ def to_xml @raw end end -end \ No newline at end of file +end From d8cdc1efecaaa603c64415d5c91b692c3ee79a0e Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:27:34 +0100 Subject: [PATCH 23/42] rubocop style: Style/TrailingWhitespace --- bin/actions.rb | 6 +++--- bin/client.rb | 4 ++-- bin/fakereg-threaded.rb | 2 +- bin/fakereg.rb | 4 ++-- bin/refresh.rb | 6 +++--- bin/register_remote.rb | 2 +- bin/submit.rb | 4 ++-- bin/windows.rb | 22 +++++++++++----------- lib/spacewalk/capabilities.rb | 2 +- lib/spacewalk/config.rb | 4 ++-- lib/spacewalk/server.rb | 4 ++-- spacewalk.gemspec | 2 +- 12 files changed, 31 insertions(+), 31 deletions(-) diff --git a/bin/actions.rb b/bin/actions.rb index 18a568c..c073d5f 100644 --- a/bin/actions.rb +++ b/bin/actions.rb @@ -52,7 +52,7 @@ def parse_args # convert action to promises # {"id"=>6434, "version"=>2, "action"=>["packages.remove", [[["accountsservice-devel", "0.6.38", "79.1", "", ""]]]]} # {"id"=>6437, "version"=>2, "action"=>["packages.update", [[["aalib-devel", "1.4.0", "503.1.3", "", ""]]]]} -# +# def mk_promise(action) id = action['id'] task, packages = action['action'] @@ -102,7 +102,7 @@ def mk_promise(action) unless File.exist? fqdn STDERR.puts "#{fqdn} must be registered first" end - + begin systemid = File.open(fqdn).read server = Spacewalk::Server.new :noconfig => true, :server => parms[:server], :systemid => systemid @@ -115,7 +115,7 @@ def mk_promise(action) server.submit_response parms[:action], '0', 'Action converted to promise', { } end end - end + end rescue raise end diff --git a/bin/client.rb b/bin/client.rb index 8bbfaf9..dd676a0 100644 --- a/bin/client.rb +++ b/bin/client.rb @@ -45,10 +45,10 @@ def packages packages << package end end - + packages end - + def profile # assemble registration information diff --git a/bin/fakereg-threaded.rb b/bin/fakereg-threaded.rb index 74ddfb7..555009a 100644 --- a/bin/fakereg-threaded.rb +++ b/bin/fakereg-threaded.rb @@ -65,7 +65,7 @@ def repo_packages(repo) def fake_profile # assemble registration information - + data = {} data['os_release'] = 'Fake testing' data['release_name'] = 'ruby-spacewalk' diff --git a/bin/fakereg.rb b/bin/fakereg.rb index 4fbe3ac..04f6869 100644 --- a/bin/fakereg.rb +++ b/bin/fakereg.rb @@ -65,7 +65,7 @@ def repo_packages(repo) def fake_profile # assemble registration information - + data = {} data['os_release'] = 'Fake testing' data['release_name'] = 'ruby-spacewalk' @@ -130,7 +130,7 @@ def fake_profile count.times do |i| begin - + # get "os_release","release_name","architecture" name = '%s%04d' % [parms[:name], i] print "Registering #{name}\n" diff --git a/bin/refresh.rb b/bin/refresh.rb index 5873219..a9fbe0e 100644 --- a/bin/refresh.rb +++ b/bin/refresh.rb @@ -29,7 +29,7 @@ def parse_args ['--port', '-P', GetoptLong::REQUIRED_ARGUMENT], ['--server', '-s', GetoptLong::REQUIRED_ARGUMENT], ['--packages', '-p', GetoptLong::NO_ARGUMENT], - ['--hardware', '-h', GetoptLong::NO_ARGUMENT] + ['--hardware', '-h', GetoptLong::NO_ARGUMENT] ) result = {} opts.each do |opt, arg| @@ -71,12 +71,12 @@ def parse_args packages = windows.packages # server.send_packages packages end - + if parms[:hardware] hardware = windows.hardware server.refresh_hardware hardware end - + rescue raise end diff --git a/bin/register_remote.rb b/bin/register_remote.rb index e268a12..837c364 100644 --- a/bin/register_remote.rb +++ b/bin/register_remote.rb @@ -115,7 +115,7 @@ def parse_args packages = client.packages server.send_packages packages end - + # if parms[:hardware] # hardware = client.hardware # server.refresh_hardware hardware diff --git a/bin/submit.rb b/bin/submit.rb index 6296196..68bf1f8 100644 --- a/bin/submit.rb +++ b/bin/submit.rb @@ -56,7 +56,7 @@ def parse_args # convert actions to promises # Actions => {"id"=>6434, "version"=>2, "action"=>["packages.remove", [[["accountsservice-devel", "0.6.38", "79.1", "", ""]]]]} -# +# def mk_promise(_actions) end @@ -80,7 +80,7 @@ def mk_promise(_actions) unless File.exist? fqdn STDERR.puts "#{fqdn} must be registered first" end - + begin systemid = File.open(fqdn).read server = Spacewalk::Server.new :noconfig => true, :server => parms[:server], :systemid => systemid diff --git a/bin/windows.rb b/bin/windows.rb index 36606eb..389cb76 100644 --- a/bin/windows.rb +++ b/bin/windows.rb @@ -40,7 +40,7 @@ def initialize(host, port = 5985) @wsopt = Openwsman::ClientOptions.new # @wsopt.set_dump_request # Openwsman.debug = -1 - + @wsopt.flags = Openwsman::FLAG_ENUMERATION_OPTIMIZATION @wsopt.max_elements = 999 end @@ -70,7 +70,7 @@ def packages # StdRegProv is a Singleton, no selectors needed # # options.add_selector( "key", value ) - + # Properties add method parameters # (Marked with [in] in method definitions) # @@ -84,7 +84,7 @@ def packages 'sSubKeyName' => uninstall_key } @wsopt.properties = properties - @wsopt.set_dump_request + @wsopt.set_dump_request # Name of method invoked on the class (resp. instrance) method = 'EnumKey' result = @wsman.invoke(@wsopt, uri, method) @@ -120,7 +120,7 @@ def packages subresult.Types.each do |key| types << key.text.to_i end - + package = { 'name' => node.text, 'epoch' => '', @@ -169,10 +169,10 @@ def packages package['release'] = '0' if package['release'].empty? packages << package end - + packages end - + def bios puts 'Checking the BIOS' uri = 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/' @@ -186,7 +186,7 @@ def bios result['smbios.system.serial'] = bios.SerialNumber result['smbios.system.manufacturer'] = bios.Manufacturer result['smbios.system.product'] = bios.Name -# result["smbios.system.uuid"] = +# result["smbios.system.uuid"] = result end @@ -215,7 +215,7 @@ def network(only_enabled=true) @data['IPAddress'] = node.IPAddress.text end netinterfaces ||= {} - netinterfaces["net#{node.Index}"] = { + netinterfaces["net#{node.Index}"] = { 'hwaddr' => node.MACAddress.text, 'module' => node.ServiceName.text, 'broadcast' => '255.255.255.255', # FIXME, compute from ip+subnet @@ -300,7 +300,7 @@ def hardware hw << net_if.merge({ 'class' => 'netinterfaces' }) end end - + @wsopt.selectors = {} puts "#{count} devices" hw @@ -321,7 +321,7 @@ def profile # os.each do |node| # puts " #{node.name}:\t#{node.text}" # end - + puts 'Asking for computer system' klass = 'Win32_ComputerSystem' result = @wsman.enumerate(@wsopt, nil, uri + klass) @@ -339,7 +339,7 @@ def profile fault result return {} end - + puts 'Assembling Windows profile' # assemble registration information diff --git a/lib/spacewalk/capabilities.rb b/lib/spacewalk/capabilities.rb index 8890539..594efe9 100644 --- a/lib/spacewalk/capabilities.rb +++ b/lib/spacewalk/capabilities.rb @@ -1,6 +1,6 @@ module Spacewalk class Capabilities - # + # def initialize(client) # hash of => @caps = {} diff --git a/lib/spacewalk/config.rb b/lib/spacewalk/config.rb index aaa2073..ada85fd 100644 --- a/lib/spacewalk/config.rb +++ b/lib/spacewalk/config.rb @@ -14,11 +14,11 @@ def initialize(path='/etc/sysconfig/rhn/up2date') end end rescue nil end - + def [](key) @config[key.downcase] end - + def method_missing(name) @config[name.to_s.downcase] end diff --git a/lib/spacewalk/server.rb b/lib/spacewalk/server.rb index c92e6f5..bb6e715 100644 --- a/lib/spacewalk/server.rb +++ b/lib/spacewalk/server.rb @@ -5,7 +5,7 @@ def get_parser end end end - + module Spacewalk class Server # from /usr/sbin/rhn_check @@ -40,7 +40,7 @@ def call(name, *args) when 'text/xml' # fallthru else - STDERR.puts "Unhandled content-type #{response['content-type']}" + STDERR.puts "Unhandled content-type #{response['content-type']}" end case response['content-encoding'] when 'x-zlib' diff --git a/spacewalk.gemspec b/spacewalk.gemspec index 1aa27ee..0d09217 100644 --- a/spacewalk.gemspec +++ b/spacewalk.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |s| s.summary = %q{A pure-Ruby implementation of the Spacewalk client side} s.description = %q{Can be used for testing or to attach 'foreign' systems} - + s.rubyforge_project = 'spacewalk' s.add_development_dependency('rake') From 495bfc27998ead7d8769216213817e5a85405575 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:31:10 +0100 Subject: [PATCH 24/42] rubocop style: Style/UnneededPercentQ --- spacewalk.gemspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spacewalk.gemspec b/spacewalk.gemspec index 0d09217..c1ddaf3 100644 --- a/spacewalk.gemspec +++ b/spacewalk.gemspec @@ -10,9 +10,9 @@ Gem::Specification.new do |s| s.authors = ['Klaus Kämpf'] s.email = ['kkaempf@suse.de'] s.homepage = 'https://github.com/kkaempf/ruby-spacewalk' - s.summary = %q{A pure-Ruby implementation of the Spacewalk client side} - s.description = %q{Can be used for testing or to attach 'foreign' -systems} + s.summary = 'A pure-Ruby implementation of the Spacewalk client side' + s.description = "Can be used for testing or to attach 'foreign' +systems" s.rubyforge_project = 'spacewalk' From 4f3937a72f46c5ddebc760c0d3354c7b1e33be81 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:32:00 +0100 Subject: [PATCH 25/42] rubocop style: Style/WhileUntilDo --- lib/spacewalk/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spacewalk/server.rb b/lib/spacewalk/server.rb index bb6e715..d6be361 100644 --- a/lib/spacewalk/server.rb +++ b/lib/spacewalk/server.rb @@ -24,7 +24,7 @@ def call(name, *args) # puts "Call #{name}(#{args.inspect})" begin # remove trailing nil values, nil is not supported in xmlrpc - while args.size > 0 && args[-1].nil? do + while args.size > 0 && args[-1].nil? args.pop end result = @client.call(name, *args) From f1ff7197d94d1f397b2e8ebb8da6e4e2cabd211a Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:34:21 +0100 Subject: [PATCH 26/42] rubocop style: Style/WhileUntilModifier --- lib/spacewalk/server.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/spacewalk/server.rb b/lib/spacewalk/server.rb index d6be361..7c6ce2b 100644 --- a/lib/spacewalk/server.rb +++ b/lib/spacewalk/server.rb @@ -24,9 +24,7 @@ def call(name, *args) # puts "Call #{name}(#{args.inspect})" begin # remove trailing nil values, nil is not supported in xmlrpc - while args.size > 0 && args[-1].nil? - args.pop - end + args.pop while args.size > 0 && args[-1].nil? result = @client.call(name, *args) rescue StandardError => e raise e unless e.message =~ /Wrong content-type/ From 459eceb0ad55547ef68d8ed8c7759c35ee78ca49 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:35:19 +0100 Subject: [PATCH 27/42] rubocop style: Style/SpecialGlobalVars --- bin/actions.rb | 2 +- bin/client.rb | 2 +- bin/fakereg-threaded.rb | 2 +- bin/fakereg.rb | 2 +- bin/refresh.rb | 2 +- bin/register_remote.rb | 2 +- bin/register_windows.rb | 2 +- bin/submit.rb | 2 +- lib/spacewalk.rb | 2 +- spacewalk.gemspec | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/actions.rb b/bin/actions.rb index c073d5f..6dd4549 100644 --- a/bin/actions.rb +++ b/bin/actions.rb @@ -5,7 +5,7 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) +$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) require 'spacewalk' require File.expand_path(File.join(File.dirname(__FILE__), 'client')) diff --git a/bin/client.rb b/bin/client.rb index dd676a0..3763b83 100644 --- a/bin/client.rb +++ b/bin/client.rb @@ -82,7 +82,7 @@ def profile end # client -if $0 == __FILE__ +if $PROGRAM_NAME == __FILE__ client = Client.new '1.1.1.1' puts client.packages.inspect end diff --git a/bin/fakereg-threaded.rb b/bin/fakereg-threaded.rb index 555009a..be6aef6 100644 --- a/bin/fakereg-threaded.rb +++ b/bin/fakereg-threaded.rb @@ -3,7 +3,7 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) +$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) require 'spacewalk' diff --git a/bin/fakereg.rb b/bin/fakereg.rb index 04f6869..0be33fa 100644 --- a/bin/fakereg.rb +++ b/bin/fakereg.rb @@ -3,7 +3,7 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) +$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) require 'spacewalk' diff --git a/bin/refresh.rb b/bin/refresh.rb index a9fbe0e..6a6b23a 100644 --- a/bin/refresh.rb +++ b/bin/refresh.rb @@ -3,7 +3,7 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) +$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) require 'spacewalk' require File.expand_path(File.join(File.dirname(__FILE__), 'windows')) diff --git a/bin/register_remote.rb b/bin/register_remote.rb index 837c364..c4bd005 100644 --- a/bin/register_remote.rb +++ b/bin/register_remote.rb @@ -5,7 +5,7 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) +$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) require 'spacewalk' require File.expand_path(File.join(File.dirname(__FILE__), 'client')) diff --git a/bin/register_windows.rb b/bin/register_windows.rb index efe08bc..0129a8f 100644 --- a/bin/register_windows.rb +++ b/bin/register_windows.rb @@ -3,7 +3,7 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) +$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) require 'spacewalk' require File.expand_path(File.join(File.dirname(__FILE__), 'windows')) diff --git a/bin/submit.rb b/bin/submit.rb index 68bf1f8..097de59 100644 --- a/bin/submit.rb +++ b/bin/submit.rb @@ -5,7 +5,7 @@ # # for testing: prefer local path -$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) +$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) require 'spacewalk' require File.expand_path(File.join(File.dirname(__FILE__), 'client')) diff --git a/lib/spacewalk.rb b/lib/spacewalk.rb index 9620b6f..778552c 100644 --- a/lib/spacewalk.rb +++ b/lib/spacewalk.rb @@ -1,4 +1,4 @@ -$: << File.dirname(__FILE__) +$LOAD_PATH << File.dirname(__FILE__) require 'spacewalk/config' require 'spacewalk/system_id' require 'spacewalk/capabilities' diff --git a/spacewalk.gemspec b/spacewalk.gemspec index c1ddaf3..d1140b3 100644 --- a/spacewalk.gemspec +++ b/spacewalk.gemspec @@ -1,5 +1,5 @@ # -*- encoding: utf-8 -*- -$:.push File.expand_path('../lib', __FILE__) +$LOAD_PATH.push File.expand_path('../lib', __FILE__) require 'spacewalk/version' Gem::Specification.new do |s| From 14db800a8ca87117fbbc1de83c15c6c9ae75aa6c Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:36:12 +0100 Subject: [PATCH 28/42] rubocop style: Style/SpaceBeforeBlockBraces --- spacewalk.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spacewalk.gemspec b/spacewalk.gemspec index d1140b3..8fc7827 100644 --- a/spacewalk.gemspec +++ b/spacewalk.gemspec @@ -23,6 +23,6 @@ systems" s.files.reject! { |fn| fn == '.gitignore' } s.extra_rdoc_files = Dir['README*', 'TODO*', 'CHANGELOG*', 'LICENSE'] s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } s.require_paths = ['lib'] end From 837b511f1046dfd3624d499e6e3bfd9b13ee17e3 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:39:53 +0100 Subject: [PATCH 29/42] rubocop style: Style/EmptyLinesAroundMethodBody --- bin/client.rb | 1 - bin/windows.rb | 1 - lib/spacewalk/server.rb | 1 - 3 files changed, 3 deletions(-) diff --git a/bin/client.rb b/bin/client.rb index 3763b83..e5c01b1 100644 --- a/bin/client.rb +++ b/bin/client.rb @@ -50,7 +50,6 @@ def packages end def profile - # assemble registration information # parse /etc/os-release # NAME=openSUSE diff --git a/bin/windows.rb b/bin/windows.rb index 389cb76..b4bed77 100644 --- a/bin/windows.rb +++ b/bin/windows.rb @@ -307,7 +307,6 @@ def hardware end def profile - begin puts 'Asking for operating system' uri = 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/' diff --git a/lib/spacewalk/server.rb b/lib/spacewalk/server.rb index 7c6ce2b..6f426d5 100644 --- a/lib/spacewalk/server.rb +++ b/lib/spacewalk/server.rb @@ -97,7 +97,6 @@ def initialize(options = {}) # check for distribution update # my_id = @systemid.os_release # server_id = osversion - end # welcome to/from server From 1390830d1b9ad86759d10ad1d3ec745ba548218b Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:40:24 +0100 Subject: [PATCH 30/42] rubocop style: Style/EmptyLinesAroundClassBody --- bin/client.rb | 1 - bin/windows.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/bin/client.rb b/bin/client.rb index e5c01b1..415cb12 100644 --- a/bin/client.rb +++ b/bin/client.rb @@ -78,7 +78,6 @@ def profile end data end - end # client if $PROGRAM_NAME == __FILE__ diff --git a/bin/windows.rb b/bin/windows.rb index b4bed77..6eeb7b9 100644 --- a/bin/windows.rb +++ b/bin/windows.rb @@ -357,5 +357,4 @@ def profile puts "Windows.profile: #{data.inspect}" data end - end # windows From 8eb1931220826d974476c4692f24d6f5c7282cd1 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:40:51 +0100 Subject: [PATCH 31/42] rubocop style: Style/EmptyLinesAroundAccessModifier --- lib/spacewalk/server.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/spacewalk/server.rb b/lib/spacewalk/server.rb index 6f426d5..1a95dc0 100644 --- a/lib/spacewalk/server.rb +++ b/lib/spacewalk/server.rb @@ -20,6 +20,7 @@ class Server require 'rexml/document' private + def call(name, *args) # puts "Call #{name}(#{args.inspect})" begin @@ -52,6 +53,7 @@ def call(name, *args) fail unless ok result end + public # From 579e75ffbdc160c7bbc1dfbebeb922ff9b68d64e Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 15:41:42 +0100 Subject: [PATCH 32/42] rubocop style: Style/BracesAroundHashParameters --- bin/windows.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/windows.rb b/bin/windows.rb index 6eeb7b9..2d16b15 100644 --- a/bin/windows.rb +++ b/bin/windows.rb @@ -297,7 +297,7 @@ def hardware end end if net_if - hw << net_if.merge({ 'class' => 'netinterfaces' }) + hw << net_if.merge('class' => 'netinterfaces') end end From 1cab65532ca73889faad4a310f20d7c9b61c7f0c Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 18:37:18 +0100 Subject: [PATCH 33/42] rubocop style: Style/ColonMethodCall --- bin/fakereg-threaded.rb | 2 +- bin/fakereg.rb | 2 +- bin/windows.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/fakereg-threaded.rb b/bin/fakereg-threaded.rb index be6aef6..77db157 100644 --- a/bin/fakereg-threaded.rb +++ b/bin/fakereg-threaded.rb @@ -111,7 +111,7 @@ def fake_profile else if parms[:yaml] require 'yaml' - packages = YAML::load_file(parms[:yaml]) + packages = YAML.load_file(parms[:yaml]) else STDERR.puts 'No --solv and no --yaml given, skipping packages' end diff --git a/bin/fakereg.rb b/bin/fakereg.rb index 0be33fa..84f0320 100644 --- a/bin/fakereg.rb +++ b/bin/fakereg.rb @@ -111,7 +111,7 @@ def fake_profile else if parms[:yaml] require 'yaml' - packages = YAML::load_file(parms[:yaml]) + packages = YAML.load_file(parms[:yaml]) else STDERR.puts 'No --solv and no --yaml given, skipping packages' end diff --git a/bin/windows.rb b/bin/windows.rb index 2d16b15..4bc2bba 100644 --- a/bin/windows.rb +++ b/bin/windows.rb @@ -104,7 +104,7 @@ def packages result.EnumKey_OUTPUT.each('sNames') do |node| puts "Node #{node.text.inspect}" - properties['sSubKeyName'] = uninstall_key + '\\' + CGI::escapeHTML(node.text) + properties['sSubKeyName'] = uninstall_key + '\\' + CGI.escapeHTML(node.text) puts "sSubKeyName >#{properties['sSubKeyName']}<" @wsopt.properties = properties method = 'EnumValues' @@ -267,7 +267,7 @@ def hardware uri = part.ResourceURI.text selectors = {} part.SelectorSet.each do |sel| - selectors[sel.attr.to_s] = CGI::escapeHTML(sel.text) + selectors[sel.attr.to_s] = CGI.escapeHTML(sel.text) end @wsopt.selectors = selectors # From 1b6fae1dae9bb18e7830adf576ba015bce1a89af Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 18:39:56 +0100 Subject: [PATCH 34/42] rubocop style: Style/CommentAnnotation --- lib/spacewalk/config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spacewalk/config.rb b/lib/spacewalk/config.rb index ada85fd..f9b4d79 100644 --- a/lib/spacewalk/config.rb +++ b/lib/spacewalk/config.rb @@ -9,7 +9,7 @@ def initialize(path='/etc/sysconfig/rhn/up2date') next unless l =~ /(\w+)=(.*)/ key = Regexp.last_match(1) val = Regexp.last_match(2) - # fixme: handle array-type values + # FIXME: handle array-type values @config[key.downcase] = val.empty? ? nil : val end end rescue nil From 69123e4709f62345003577a3877a5d8504ebfc8e Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 18:41:52 +0100 Subject: [PATCH 35/42] rubocop style: Style/EndOfLine --- Rakefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Rakefile b/Rakefile index 9e740ad..00c1229 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,6 @@ -require 'bundler/gem_tasks' -require 'rake/testtask' - -task :default => [:test] - -Dir['tasks/**/*.rake'].each { |t| load t } +require 'bundler/gem_tasks' +require 'rake/testtask' + +task :default => [:test] + +Dir['tasks/**/*.rake'].each { |t| load t } From fa36abd8591f0c809915e0e2698f858a03a0be6f Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 18:43:21 +0100 Subject: [PATCH 36/42] rubocop style: Style/WordArray --- bin/windows.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/windows.rb b/bin/windows.rb index 4bc2bba..e80008f 100644 --- a/bin/windows.rb +++ b/bin/windows.rb @@ -136,15 +136,15 @@ def packages reg_type = TYPES[type] method, valuename = case reg_type when :REG_SZ - ['GetStringValue', 'sValue'] # string + %w(GetStringValue sValue) # string when :REG_EXPAND_SZ - ['GetExpandedStringValue', 'sValue'] # expanded string + %w(GetExpandedStringValue sValue) # expanded string when :REG_BINARY - ['GetBinaryValue', 'uValue'] # blob + %w(GetBinaryValue uValue) # blob when :REG_DWORD - ['GetDWORDValue', 'uValue'] # integer + %w(GetDWORDValue uValue) # integer when :REG_MULTI_SZ - ['GetMultiStringValue', 'sValue'] # multi string + %w(GetMultiStringValue sValue) # multi string else fail "Unknown type #{type}" end From 9ea5d9a17c4b4120844777a0f09cba39a9f76e0c Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 18:45:19 +0100 Subject: [PATCH 37/42] rubocop style: Style/NumericLiterals --- bin/windows.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/windows.rb b/bin/windows.rb index e80008f..f5fe5ac 100644 --- a/bin/windows.rb +++ b/bin/windows.rb @@ -9,12 +9,12 @@ class Windows # mapping for Registry 'root' pointers HKEYS = { - :HKEY_CLASSES_ROOT => 2147483648, # (0x80000000) - :HKEY_CURRENT_USER => 2147483649, # (0x80000001) - :HKEY_LOCAL_MACHINE => 2147483650, # (0x80000002) - :HKEY_USERS => 2147483651, # (0x80000003) - :HKEY_CURRENT_CONFIG => 2147483653, # (0x80000005) - :HKEY_DYN_DATA => 2147483654 # (0x80000006) + :HKEY_CLASSES_ROOT => 2_147_483_648, # (0x80000000) + :HKEY_CURRENT_USER => 2_147_483_649, # (0x80000001) + :HKEY_LOCAL_MACHINE => 2_147_483_650, # (0x80000002) + :HKEY_USERS => 2_147_483_651, # (0x80000003) + :HKEY_CURRENT_CONFIG => 2_147_483_653, # (0x80000005) + :HKEY_DYN_DATA => 2_147_483_654 # (0x80000006) } TYPES = { 1 => :REG_SZ, # string From acf82805ad471b65344ac43cde076c21421e2c3d Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 19:27:20 +0100 Subject: [PATCH 38/42] rubocop style: Style/Tab --- lib/spacewalk/capabilities.rb | 14 ++++++------- lib/spacewalk/config.rb | 16 +++++++------- lib/spacewalk/server.rb | 38 +++++++++++++++++----------------- lib/spacewalk/status_report.rb | 8 +++---- lib/spacewalk/system_id.rb | 4 ++-- lib/spacewalk/xmlrpc.rb | 38 +++++++++++++++++----------------- 6 files changed, 59 insertions(+), 59 deletions(-) diff --git a/lib/spacewalk/capabilities.rb b/lib/spacewalk/capabilities.rb index 594efe9..3536ecc 100644 --- a/lib/spacewalk/capabilities.rb +++ b/lib/spacewalk/capabilities.rb @@ -5,13 +5,13 @@ def initialize(client) # hash of => @caps = {} client.http_last_response['x-rhn-server-capability'].split(',').each do |caps| - caps.split(',').each do |cap| -# puts "#{cap}" - fail "Invalid cap '#{cap}'" unless cap =~ /(\s+)?(((\w+)|\.)+)\((\d(-\d)?)\)=(\d)/ - # name = [ version, value ] - @caps[Regexp.last_match(2)] = [Regexp.last_match(5), Regexp.last_match(7)] -# puts "#{$2}(#{$5})=#{$7}" - end + caps.split(',').each do |cap| +# puts "#{cap}" + fail "Invalid cap '#{cap}'" unless cap =~ /(\s+)?(((\w+)|\.)+)\((\d(-\d)?)\)=(\d)/ + # name = [ version, value ] + @caps[Regexp.last_match(2)] = [Regexp.last_match(5), Regexp.last_match(7)] +# puts "#{$2}(#{$5})=#{$7}" + end end end end diff --git a/lib/spacewalk/config.rb b/lib/spacewalk/config.rb index f9b4d79..1ed5bbe 100644 --- a/lib/spacewalk/config.rb +++ b/lib/spacewalk/config.rb @@ -4,14 +4,14 @@ def initialize(path='/etc/sysconfig/rhn/up2date') @path = path @config = {} File.open path do |f| - while l = f.gets - # split =, drop everything else - next unless l =~ /(\w+)=(.*)/ - key = Regexp.last_match(1) - val = Regexp.last_match(2) - # FIXME: handle array-type values - @config[key.downcase] = val.empty? ? nil : val - end + while l = f.gets + # split =, drop everything else + next unless l =~ /(\w+)=(.*)/ + key = Regexp.last_match(1) + val = Regexp.last_match(2) + # FIXME: handle array-type values + @config[key.downcase] = val.empty? ? nil : val + end end rescue nil end diff --git a/lib/spacewalk/server.rb b/lib/spacewalk/server.rb index 1a95dc0..0ce3821 100644 --- a/lib/spacewalk/server.rb +++ b/lib/spacewalk/server.rb @@ -24,30 +24,30 @@ class Server def call(name, *args) # puts "Call #{name}(#{args.inspect})" begin - # remove trailing nil values, nil is not supported in xmlrpc - args.pop while args.size > 0 && args[-1].nil? - result = @client.call(name, *args) + # remove trailing nil values, nil is not supported in xmlrpc + args.pop while args.size > 0 && args[-1].nil? + result = @client.call(name, *args) rescue StandardError => e - raise e unless e.message =~ /Wrong content-type/ + raise e unless e.message =~ /Wrong content-type/ end response = @client.http_last_response fail "XMLRPC failed with #{response.code}" unless response.code == '200' body = response.body case response['content-type'] when 'text/base64' - body = Base64.decode64(body) + body = Base64.decode64(body) when 'text/xml' - # fallthru + # fallthru else STDERR.puts "Unhandled content-type #{response['content-type']}" end case response['content-encoding'] when 'x-zlib' - body = Zlib::Inflate.inflate(body) + body = Zlib::Inflate.inflate(body) when nil - # fallthru + # fallthru else - STDERR.puts "Unhandled content-encoding #{response['content-encoding']}" + STDERR.puts "Unhandled content-encoding #{response['content-encoding']}" end ok, result = @client.get_parser.parseMethodResponse(body) fail unless ok @@ -66,19 +66,19 @@ def call(name, *args) def initialize(options = {}) @config = Spacewalk::Config.new if options[:noconfig] - uri = URI.parse(options[:server]) - fail "Server '#{options[:server]}' is not proper URL" unless uri.host - uri.path = '/XMLRPC' + uri = URI.parse(options[:server]) + fail "Server '#{options[:server]}' is not proper URL" unless uri.host + uri.path = '/XMLRPC' else - uri = URI.parse(@config.serverurl) + uri = URI.parse(@config.serverurl) end args = {:host => uri.host, :path => uri.path, :use_ssl => (uri.scheme == 'https'), :timeout => 120 } unless options[:noconfig] - if @config.httpProxy - args[:proxy_host], clientargs[:proxy_port] = @config.httpProxy.split ':' - end + if @config.httpProxy + args[:proxy_host], clientargs[:proxy_port] = @config.httpProxy.split ':' + end end @client = XMLRPC::Client.new_from_hash args @@ -111,7 +111,7 @@ def welcome def osversion result = @config.versionOverride unless result - # find rpm provider of redhat-release or distribution-release, get its version + # find rpm provider of redhat-release or distribution-release, get its version end result end @@ -128,7 +128,7 @@ def actions action = result['action'] if action - result['action'] = @client.get_parser.parseMethodCall(action) + result['action'] = @client.get_parser.parseMethodCall(action) end # puts "Actions => #{result.inspect}" end @@ -176,7 +176,7 @@ def register(activationkey, profile_name, other = {}) # auth_dict["password"] = password # if cfg['supportsSMBIOS']: - # auth_dict["smbios"] = _encode_characters(hardware.get_smbios()) + # auth_dict["smbios"] = _encode_characters(hardware.get_smbios()) # STDERR.puts "registration.new_system #{auth_dict.inspect}" @systemid = call 'registration.new_system', auth_dict end diff --git a/lib/spacewalk/status_report.rb b/lib/spacewalk/status_report.rb index 90080ce..012dfb7 100644 --- a/lib/spacewalk/status_report.rb +++ b/lib/spacewalk/status_report.rb @@ -7,11 +7,11 @@ def self.status # (uname -s, uname -n, uname -r, uname -v, uname -m) status['uname'] = [`uname -s`.chomp, `uname -n`.chomp, `uname -r`.chomp, `uname -v`.chomp, `uname -m`.chomp] begin - File.open('/proc/uptime') do |f| - status['uptime'] = f.read.split(' ').map(&:to_i) - end + File.open('/proc/uptime') do |f| + status['uptime'] = f.read.split(' ').map(&:to_i) + end rescue - nil + nil end # puts status.inspect status diff --git a/lib/spacewalk/system_id.rb b/lib/spacewalk/system_id.rb index 1ba7d4a..9cf837c 100644 --- a/lib/spacewalk/system_id.rb +++ b/lib/spacewalk/system_id.rb @@ -14,8 +14,8 @@ def initialize(client, config) # admin # File.open(@path) do |f| - @raw = f.read - @members = client.get_parser.parseMethodResponse(@raw) + @raw = f.read + @members = client.get_parser.parseMethodResponse(@raw) end puts "SystemId => #{@members.inspect}" end diff --git a/lib/spacewalk/xmlrpc.rb b/lib/spacewalk/xmlrpc.rb index 61f8424..72b47d0 100644 --- a/lib/spacewalk/xmlrpc.rb +++ b/lib/spacewalk/xmlrpc.rb @@ -8,28 +8,28 @@ def self.value2ruby(element) puts "value2ruby node #{node}" case node.name when 'string' - node.text + node.text when 'struct' - fail 'value2ruby: not following ' unless node[0].name == 'member' - value = {} - puts "Struct #{node}" - node.each_element('member') do |e| - name = e.elements['member/name'].text - v = value2ruby m.elements['member/value'] - value[name] = v - end - value + fail 'value2ruby: not following ' unless node[0].name == 'member' + value = {} + puts "Struct #{node}" + node.each_element('member') do |e| + name = e.elements['member/name'].text + v = value2ruby m.elements['member/value'] + value[name] = v + end + value when 'array' - fail 'value2ruby: not following ' unless node[0].name == 'data' - value = [] -# puts "Array #{node}" - node.each_element('data/value') do |e| -# puts "recursive #{e}" - value << value2ruby(e) - end - value + fail 'value2ruby: not following ' unless node[0].name == 'data' + value = [] +# puts "Array #{node}" + node.each_element('data/value') do |e| +# puts "recursive #{e}" + value << value2ruby(e) + end + value else - fail "value2ruby: Can't handle element '#{element.name}'" + fail "value2ruby: Can't handle element '#{element.name}'" end end From 12f1d74ae107f57d5f5d15aa6ba2d04ec3852dc8 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 19:29:35 +0100 Subject: [PATCH 39/42] rubocop style: Style/IndentationWidth --- tasks/doc.rake | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tasks/doc.rake b/tasks/doc.rake index 194ef0a..ebb9a6c 100644 --- a/tasks/doc.rake +++ b/tasks/doc.rake @@ -1,14 +1,14 @@ begin - require 'yard' - YARD::Rake::YardocTask.new(:doc) do |t| - t.files = ['lib/**/*.rb'] - t.options = ['--no-private'] - end -rescue LoadError - STDERR.puts 'Install yard if you want prettier docs' - require 'rdoc/task' - Rake::RDocTask.new(:doc) do |rdoc| - rdoc.rdoc_dir = 'doc' - rdoc.title = "Spacewalk #{Spacewalk::VERSION}" + require 'yard' + YARD::Rake::YardocTask.new(:doc) do |t| + t.files = ['lib/**/*.rb'] + t.options = ['--no-private'] end + rescue LoadError + STDERR.puts 'Install yard if you want prettier docs' + require 'rdoc/task' + Rake::RDocTask.new(:doc) do |rdoc| + rdoc.rdoc_dir = 'doc' + rdoc.title = "Spacewalk #{Spacewalk::VERSION}" + end end From bc50281dca014a9205c1dd8692eb91e1b2488e2f Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 19:41:25 +0100 Subject: [PATCH 40/42] rubocop style: Style/FormatString --- bin/fakereg-threaded.rb | 2 +- bin/fakereg.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/fakereg-threaded.rb b/bin/fakereg-threaded.rb index 77db157..e105b7a 100644 --- a/bin/fakereg-threaded.rb +++ b/bin/fakereg-threaded.rb @@ -133,7 +133,7 @@ def fake_profile server = Spacewalk::Server.new :noconfig => true, :server => parms[:server] # get "os_release","release_name","architecture" - name = '%s%04d' % [parms[:name], i] + name = format('%s%04d', parms[:name], i) print "Registering #{name}\n" systemid = server.register parms[:key], name, profile File.open("#{name}.systemid", 'w+') do |f| diff --git a/bin/fakereg.rb b/bin/fakereg.rb index 84f0320..cdd5161 100644 --- a/bin/fakereg.rb +++ b/bin/fakereg.rb @@ -132,7 +132,7 @@ def fake_profile begin # get "os_release","release_name","architecture" - name = '%s%04d' % [parms[:name], i] + name = format('%s%04d', parms[:name], i) print "Registering #{name}\n" systemid = server.register parms[:key], name, profile File.open("#{name}.systemid", 'w+') do |f| From bcf7bd8c603dff4e3b2aac3b82657587580e36f9 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 19:48:09 +0100 Subject: [PATCH 41/42] rubocop style: Style/FileName --- bin/{fakereg-threaded.rb => fakereg_threaded.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bin/{fakereg-threaded.rb => fakereg_threaded.rb} (100%) diff --git a/bin/fakereg-threaded.rb b/bin/fakereg_threaded.rb similarity index 100% rename from bin/fakereg-threaded.rb rename to bin/fakereg_threaded.rb From 62aa48aa93b45166d0daa39fd4d7832c537606da Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 12 Mar 2015 20:23:13 +0100 Subject: [PATCH 42/42] current rubocop status --- .rubocop.yml | 316 +---------------------------------------------- rubocop_todo.yml | 105 ++++++++++++++++ 2 files changed, 107 insertions(+), 314 deletions(-) create mode 100644 rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index 46b1cf8..cf4b0f7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,314 +1,2 @@ -# This configuration was generated by `rubocop --auto-gen-config` -# on 2015-03-12 11:03:52 +0100 using RuboCop version 0.28.0. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 3 -# Configuration parameters: AllowSafeAssignment. -Lint/AssignmentInCondition: - Enabled: false - -# Offense count: 4 -Lint/ParenthesesAsGroupedExpression: - Enabled: false - -# Offense count: 8 -Lint/RescueException: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -Lint/UnusedMethodArgument: - Enabled: false - -# Offense count: 2 -Lint/UselessAccessModifier: - Enabled: false - -# Offense count: 9 -Lint/UselessAssignment: - Enabled: false - -# Offense count: 16 -Metrics/AbcSize: - Max: 79 - -# Offense count: 2 -# Configuration parameters: CountComments. -Metrics/ClassLength: - Max: 266 - -# Offense count: 6 -Metrics/CyclomaticComplexity: - Max: 17 - -# Offense count: 42 -# Configuration parameters: AllowURI, URISchemes. -Metrics/LineLength: - Max: 181 - -# Offense count: 21 -# Configuration parameters: CountComments. -Metrics/MethodLength: - Max: 87 - -# Offense count: 4 -Metrics/PerceivedComplexity: - Max: 15 - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/AccessModifierIndentation: - Enabled: false - -# Offense count: 1 -Style/AccessorMethodName: - Enabled: false - -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles. -Style/AlignHash: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/BracesAroundHashParameters: - Enabled: false - -# Offense count: 6 -# Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep. -Style/CaseIndentation: - Enabled: false - -# Offense count: 4 -# Cop supports --auto-correct. -Style/ColonMethodCall: - Enabled: false - -# Offense count: 1 -# Configuration parameters: Keywords. -Style/CommentAnnotation: - Enabled: false - -# Offense count: 31 -# Cop supports --auto-correct. -Style/CommentIndentation: - Enabled: false - -# Offense count: 10 -Style/Documentation: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowAdjacentOneLineDefs. -Style/EmptyLineBetweenDefs: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -Style/EmptyLines: - Enabled: false - -# Offense count: 4 -# Cop supports --auto-correct. -Style/EmptyLinesAroundAccessModifier: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/EmptyLinesAroundClassBody: - Enabled: false - -# Offense count: 3 -# Cop supports --auto-correct. -Style/EmptyLinesAroundMethodBody: - Enabled: false - -# Offense count: 1 -Style/EndOfLine: - Enabled: false - -# Offense count: 1 -# Configuration parameters: Exclude. -Style/FileName: - Enabled: false - -# Offense count: 2 -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/FormatString: - Enabled: false - -# Offense count: 2 -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Enabled: false - -# Offense count: 30 -# Cop supports --auto-correct. -# Configuration parameters: SupportedStyles. -Style/HashSyntax: - EnforcedStyle: hash_rockets - -# Offense count: 8 -# Configuration parameters: MaxLineLength. -Style/IfUnlessModifier: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -Style/IndentationConsistency: - Enabled: false - -# Offense count: 19 -# Cop supports --auto-correct. -# Configuration parameters: Width. -Style/IndentationWidth: - Enabled: false - -# Offense count: 12 -# Cop supports --auto-correct. -Style/LeadingCommentSpace: - Enabled: false - -# Offense count: 31 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/MethodDefParentheses: - Enabled: false - -# Offense count: 6 -# Cop supports --auto-correct. -Style/NumericLiterals: - MinDigits: 11 - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Enabled: false - -# Offense count: 5 -# Cop supports --auto-correct. -Style/PerlBackrefs: - Enabled: false - -# Offense count: 4 -Style/RescueModifier: - Enabled: false - -# Offense count: 17 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SignalException: - Enabled: false - -# Offense count: 46 -# Cop supports --auto-correct. -Style/SpaceAfterComma: - Enabled: false - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SpaceAroundEqualsInParameterDefault: - Enabled: false - -# Offense count: 15 -# Cop supports --auto-correct. -Style/SpaceAroundOperators: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SpaceBeforeBlockBraces: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -Style/SpaceInsideBlockBraces: - Enabled: false - -# Offense count: 92 -# Cop supports --auto-correct. -Style/SpaceInsideBrackets: - Enabled: false - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. -Style/SpaceInsideHashLiteralBraces: - Enabled: false - -# Offense count: 20 -# Cop supports --auto-correct. -Style/SpaceInsideParens: - Enabled: false - -# Offense count: 10 -# Cop supports --auto-correct. -Style/SpecialGlobalVars: - Enabled: false - -# Offense count: 435 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/StringLiterals: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: IgnoredMethods. -Style/SymbolProc: - Enabled: false - -# Offense count: 55 -# Cop supports --auto-correct. -Style/Tab: - Enabled: false - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/TrailingBlankLines: - Enabled: false - -# Offense count: 32 -# Cop supports --auto-correct. -Style/TrailingWhitespace: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, Whitelist. -Style/TrivialAccessors: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -Style/UnneededPercentQ: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -Style/WhileUntilDo: - Enabled: false - -# Offense count: 1 -# Configuration parameters: MaxLineLength. -Style/WhileUntilModifier: - Enabled: false - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: WordRegex. -Style/WordArray: - MinSize: 2 +inherit_from: + - rubocop_todo.yml \ No newline at end of file diff --git a/rubocop_todo.yml b/rubocop_todo.yml new file mode 100644 index 0000000..3b12c80 --- /dev/null +++ b/rubocop_todo.yml @@ -0,0 +1,105 @@ +# This configuration was generated by `rubocop --auto-gen-config` +# on 2015-03-12 11:03:52 +0100 using RuboCop version 0.28.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 3 +# Configuration parameters: AllowSafeAssignment. +Lint/AssignmentInCondition: + Enabled: false + +# Offense count: 9 +Lint/UselessAssignment: + Enabled: false + +# Offense count: 16 +Metrics/AbcSize: + Max: 79 + +# Offense count: 2 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 266 + +# Offense count: 6 +Metrics/CyclomaticComplexity: + Max: 17 + +# Offense count: 42 +# Configuration parameters: AllowURI, URISchemes. +Metrics/LineLength: + Max: 181 + +# Offense count: 21 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 87 + +# Offense count: 4 +Metrics/PerceivedComplexity: + Max: 15 + +# Offense count: 1 +Style/AccessorMethodName: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles. +Style/AlignHash: + Enabled: false + +# Offense count: 6 +# Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep. +Style/CaseIndentation: + Enabled: false + +# Offense count: 31 +# Cop supports --auto-correct. +Style/CommentIndentation: + Enabled: false + +# Offense count: 10 +Style/Documentation: + Enabled: false + +# Offense count: 2 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Enabled: false + +# Offense count: 30 +# Cop supports --auto-correct. +# Configuration parameters: SupportedStyles. +Style/HashSyntax: + EnforcedStyle: hash_rockets + +# Offense count: 8 +# Configuration parameters: MaxLineLength. +Style/IfUnlessModifier: + Enabled: false + +# Offense count: 4 +Style/RescueModifier: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/SpaceAroundEqualsInParameterDefault: + Enabled: false + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. +Style/SpaceInsideHashLiteralBraces: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, Whitelist. +Style/TrivialAccessors: + Enabled: false +