Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
239d0d7
add rubocop.yml
dmacvicar Mar 12, 2015
f551146
rubocop style: Lint/AssignmentInCondition
dmacvicar Mar 12, 2015
fb18d44
rubocop style: Lint/ParenthesesAsGroupedExpression
dmacvicar Mar 12, 2015
026d4a4
rubocop style: Lint/RescueException
dmacvicar Mar 12, 2015
49fc6b7
rubocop style: Lint/UnusedMethodArgument
dmacvicar Mar 12, 2015
2503c22
rubocop style: Lint/UselessAccessModifier
dmacvicar Mar 12, 2015
0fb9e14
rubocop style: Style/AccessModifierIndentation
dmacvicar Mar 12, 2015
1297c5d
rubocop style: Style/EmptyLineBetweenDefs
dmacvicar Mar 12, 2015
1f38dad
rubocop style: Style/EmptyLineBetweenDefs
dmacvicar Mar 12, 2015
68f7474
rubocop style: Style/IndentationConsistency
dmacvicar Mar 12, 2015
ca0139e
rubocop style: Style/MethodDefParentheses
dmacvicar Mar 12, 2015
4256ef9
rubocop style: Style/LeadingCommentSpace
dmacvicar Mar 12, 2015
f4e21ed
rubocop style: Style/PerlBackrefs
dmacvicar Mar 12, 2015
66ba7ef
rubocop style: Style/SignalException
dmacvicar Mar 12, 2015
63a3331
rubocop style: Style/SpaceAfterComma
dmacvicar Mar 12, 2015
dc7a3db
rubocop style: Style/SpaceAroundOperators
dmacvicar Mar 12, 2015
f58d706
rubocop style: Style/SpaceInsideBlockBraces
dmacvicar Mar 12, 2015
ccecd36
rubocop style: Style/SpaceInsideBrackets
dmacvicar Mar 12, 2015
3cc333c
rubocop style: Style/SpaceInsideParens
dmacvicar Mar 12, 2015
35278aa
rubocop style: Style/Style/StringLiterals
dmacvicar Mar 12, 2015
6ebf48f
rubocop style: Style/SymbolProc
dmacvicar Mar 12, 2015
3b4718a
rubocop style: Style/TrailingBlankLines
dmacvicar Mar 12, 2015
d8cdc1e
rubocop style: Style/TrailingWhitespace
dmacvicar Mar 12, 2015
495bfc2
rubocop style: Style/UnneededPercentQ
dmacvicar Mar 12, 2015
4f3937a
rubocop style: Style/WhileUntilDo
dmacvicar Mar 12, 2015
f1ff719
rubocop style: Style/WhileUntilModifier
dmacvicar Mar 12, 2015
459eceb
rubocop style: Style/SpecialGlobalVars
dmacvicar Mar 12, 2015
14db800
rubocop style: Style/SpaceBeforeBlockBraces
dmacvicar Mar 12, 2015
837b511
rubocop style: Style/EmptyLinesAroundMethodBody
dmacvicar Mar 12, 2015
1390830
rubocop style: Style/EmptyLinesAroundClassBody
dmacvicar Mar 12, 2015
8eb1931
rubocop style: Style/EmptyLinesAroundAccessModifier
dmacvicar Mar 12, 2015
579e75f
rubocop style: Style/BracesAroundHashParameters
dmacvicar Mar 12, 2015
1cab655
rubocop style: Style/ColonMethodCall
dmacvicar Mar 12, 2015
1b6fae1
rubocop style: Style/CommentAnnotation
dmacvicar Mar 12, 2015
69123e4
rubocop style: Style/EndOfLine
dmacvicar Mar 12, 2015
fa36abd
rubocop style: Style/WordArray
dmacvicar Mar 12, 2015
9ea5d9a
rubocop style: Style/NumericLiterals
dmacvicar Mar 12, 2015
acf8280
rubocop style: Style/Tab
dmacvicar Mar 12, 2015
12f1d74
rubocop style: Style/IndentationWidth
dmacvicar Mar 12, 2015
bc50281
rubocop style: Style/FormatString
dmacvicar Mar 12, 2015
bcf7bd8
rubocop style: Style/FileName
dmacvicar Mar 12, 2015
62aa48a
current rubocop status
dmacvicar Mar 12, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
inherit_from:
- rubocop_todo.yml
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "http://rubygems.org"
source 'http://rubygems.org'

# Specify your gem's dependencies in spacewalk.gemspec
gemspec
12 changes: 6 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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 }
70 changes: 35 additions & 35 deletions bin/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
#

# 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'))
require 'spacewalk'
require File.expand_path(File.join(File.dirname(__FILE__), 'client'))

#
# Usage
#

def usage msg=nil
def usage(msg=nil)
STDERR.puts "*** #{msg}" if msg
STDERR.puts "Usage:"
STDERR.puts " actions [<options>] <client-fqdn>"
STDERR.puts " --server <spacewalk-server-url>"
STDERR.puts " --future <hours>"
STDERR.puts "Checks server for client actions"
exit (msg ? 1 : 0)
STDERR.puts 'Usage:'
STDERR.puts ' actions [<options>] <client-fqdn>'
STDERR.puts ' --server <spacewalk-server-url>'
STDERR.puts ' --future <hours>'
STDERR.puts 'Checks server for client actions'
exit(msg ? 1 : 0)
end

#
Expand All @@ -31,47 +31,47 @@ 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|
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 <client-fqdn> given") if ARGV.empty?
usage('No <client-fqdn> given') if ARGV.empty?
result[:fqdn] = ARGV.shift
usage("Multiple <client-fqdn>s given") unless ARGV.empty?
usage('Multiple <client-fqdn>s given') unless ARGV.empty?
end
result
end

# 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"]
promise = "bundle agent "
#
def mk_promise(action)
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
raise "Task '#{task}' not supported"
fail "Task '#{task}' not supported"
end
promise << "\n{\n vars:\n \"package_list\" slist => {\n "
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
Expand All @@ -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

Expand All @@ -102,20 +102,20 @@ 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
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]
server.submit_response parms[:action], "0", "Action converted to promise", { }
server.submit_response parms[:action], '0', 'Action converted to promise', { }
end
end
end
end
rescue
raise
end
41 changes: 19 additions & 22 deletions bin/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ class Client
#
# Dump result as XML to file
#
def dump klass, result
File.open("#{klass}.xml", "w+") do |f|
def dump(klass, result)
File.open("#{klass}.xml", 'w+') do |f|
f.write result.to_xml
end
end

#
# Constructor
#
def initialize host
def initialize(host)
@host = host
@data = {}
end
Expand All @@ -37,20 +37,19 @@ 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
end

packages
end

def profile

def profile
# assemble registration information
# parse /etc/os-release
# NAME=openSUSE
Expand All @@ -64,26 +63,24 @@ 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("=")
val = val[1,-2] if val[0][1] == '"'
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
data
end


end # client

if $0 == __FILE__
client = Client.new "1.1.1.1"
if $PROGRAM_NAME == __FILE__
client = Client.new '1.1.1.1'
puts client.packages.inspect
end
Loading