-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9d9a1a5
Showing
13 changed files
with
390 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.gem | ||
.bundle | ||
Gemfile.lock | ||
pkg/* | ||
.yardoc | ||
*.rbc | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in supportconfig.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Supportconfig | ||
VERSION = "0.0.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
$: << 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 | ||
|
Oops, something went wrong.