Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaempf committed Jun 8, 2016
0 parents commit 9d9a1a5
Show file tree
Hide file tree
Showing 13 changed files with 390 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.gem
.bundle
Gemfile.lock
pkg/*
.yardoc
*.rbc
*~
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in supportconfig.gemspec
gemspec
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2011 SUSE LINUX Products GmbH

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 changes: 34 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
= Supportconfig

* http://github.com/kkaempf/supportconfig

== Introduction

Library to access SUSE supportconfig and command line tool.

Its main goal is to be clean and provide a command line tool
that exposes its features.

== Features

Main use case is easy access to data inside supportconfig.

Plugins can be written to deal with specific needs.

== Extending Supportconfig

Derive your class from Supportconfig::Supportconfig.

== Debugging

Set DEBUG environment variable non-empty.

== Authors

* Klaus Kämpf <[email protected]>

== License

Copyright (c) 2016 SUSE LINUX Products GmbH.

Bicho is licensed under the MIT license. See MIT-LICENSE for details.
31 changes: 31 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
$:.push(File.join(File.dirname(__FILE__), 'lib'))
require 'bundler/gem_tasks'
require 'supportconfig/version'
require 'rake/testtask'

extra_docs = ['README*', 'TODO*', 'CHANGELOG*']

task :default => [:test]

Rake::TestTask.new do |t|
t.libs << File.expand_path('../test', __FILE__)
t.libs << File.expand_path('../', __FILE__)
t.test_files = FileList['test/test*.rb']
t.verbose = true
end

begin
require 'yard'
YARD::Rake::YardocTask.new(:doc) do |t|
t.files = ['lib/**/*.rb', *extra_docs]
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 = "supportconfig #{Supportconfig::VERSION}"
extra_docs.each { |ex| rdoc.rdoc_files.include ex }
end
end
96 changes: 96 additions & 0 deletions bin/supportconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env ruby
#
# encoding: UTF-8
#
# Copyright (c) 2016 SUSE LINUX Products GmbH
#
# Author: Klaus Kämpf <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
$:.push(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'supportconfig'
require 'highline/import'

# Set the console color scheme
ft = HighLine::ColorScheme.new do |cs|
cs[:headline] = [ :bold ]
cs[:horizontal_line] = [ :bold, :white ]
cs[:even_row] = [ :green ]
cs[:odd_row] = [ :magenta ]
cs[:error] = [ :red ]
end

HighLine.color_scheme = ft
# Our 'terminal' object
t = HighLine.new

# Scan all installed pluggable commands
Dir.glob(File.join(File.dirname(__FILE__), '..', 'lib', 'bicho', 'cli', 'commands', '*.rb')).each do |cmd|
load cmd
end

# Setup a logger and connect it with stupid libraries
# that can't use a logger
Bicho::Logging.logger = Logger.new(STDERR)
# Don't show by default anything
Bicho::Logging.logger.level = Logger::FATAL

ret = 0
begin
# create subcommands automatically from the available
# symbols in BzConsole module
SUB_COMMANDS = Bicho::CLI::Commands.constants.sort.map(&:to_s).map(&:downcase)

global_opts = Trollop::options do
banner <<-EOS
Usage: #{File.basename(__FILE__)} [global options] <command> ...
Bugzilla url can be given as https://bugs.kde.org or bko
EOS
opt :config, "Read FILE as configuration file.", :type => :io
opt :debug, "Show debug messages", :default => false
opt :bugzilla, "Bugzilla URL or alias", :default => 'bnz'
stop_on SUB_COMMANDS
end

Bicho::Logging.logger.level = Logger::DEBUG if global_opts[:debug]

# get the subcommand
cmd = ARGV.shift rescue nil

if (!cmd || !SUB_COMMANDS.include?(cmd))
Trollop.die "available subcommands: #{SUB_COMMANDS.join(" ")}"
end

# Create an instance for the command
mod = Bicho::CLI::Commands
cmd_class = mod.const_get(cmd.capitalize)
cmd_instance = cmd_class.new
opts = cmd_instance.parse_options

ret = cmd_instance.do(global_opts, opts, ARGV)
rescue Exception => e
Bicho::Logging.logger.error e.message
Bicho::Logging.logger.error e.backtrace
t.say("#{t.color('ERROR: ', :error)} #{t.color(e.message, :bold)}")
ret = 1
end
exit ret
33 changes: 33 additions & 0 deletions lib/supportconfig.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#--
# Copyright (c) 2016 SUSE LINUX Products GmbH
#
# Author: Klaus Kämpf <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
require 'rubygems'
require 'logger'
require 'supportconfig/version'
require 'supportconfig/logging'
require 'supportconfig/supportconfig'

module Supportconfig

end
43 changes: 43 additions & 0 deletions lib/supportconfig/logging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#--
# Copyright (c) 2016 SUSE LINUX Products GmbH
#
# Author: Klaus Kämpf <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
require 'logger'

module Supportconfig
module Logging

def self.logger=(logger)
@logger = logger
end

def self.logger
@logger ||= Logger.new('/dev/null')
end

def logger
Logging.logger
end

end
end
78 changes: 78 additions & 0 deletions lib/supportconfig/supportconfig.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
module Supportconfig

#
# class Supportconfig
# base class
#
# contains generic file parser
#

class Supportconfig
def initialize client, dir, fname
@client = client
@fname = fname
parse File.join(dir, fname)
end
private
#
# generic parser for supportconfig .txt files
#
# .txt files have multiple section, every section
# is named and starting with
# #==[ <name> ]====...
# following is content until EOF or the next section
#
# this parser splits files into sections and assembles
# the section content as array of lines
#
# the section name is used as a callback name

def parse file
File.open(file) do |f|
content = []
section = nil
f.each do |l|
l.chomp!
next if l.empty?
if l =~ /#==\[ (.*) \]===/
# new section start
if section
# old section present
self.send section, content
section = nil
content = []
end
section = $1.downcase.tr(" ", "_")
elsif section
content << l
else
# skip header
end
end
# send final section
self.send section, content if section
self.close
end
end
public
#
# Example callback
#
#
# section:
# #==[ Command ]======================================#
#
def command content
# empty - derive from Supportconfig and implement there
end

#
# close file (eof reached)
#
def close
STDERR.puts "#{self.class}.close not implemented !"
end

end # class

end # module
3 changes: 3 additions & 0 deletions lib/supportconfig/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Supportconfig
VERSION = "0.0.1"
end
22 changes: 22 additions & 0 deletions supportconfig.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "supportconfig/version"

Gem::Specification.new do |s|
s.name = "supportconfig"
s.version = Supportconfig::VERSION
s.authors = ["Klaus Kämpf"]
s.email = ["[email protected]"]
s.homepage = "http://github.com/kkaempf/supportconfig"
s.summary = %q{Library to access SUSE supportconfig data}
s.description = %q{Library to access SUSE supportconfig data}

s.add_dependency("highline", ["~> 1.7.8"])

s.rubyforge_project = "supportconfig"

s.files = `git ls-files`.split("\n")
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"]
end
9 changes: 9 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$: << File.join(File.dirname(__FILE__), "..", "lib")
require 'test/unit'
require 'supportconfig'

if ENV["DEBUG"]
Supportconfig::Logging.logger = Logger.new(STDERR)
Supportconfig::Logging.logger.level = Logger::DEBUG
end

Loading

0 comments on commit 9d9a1a5

Please sign in to comment.