Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/susestudio/ssc into try_m…
Browse files Browse the repository at this point in the history
…erge

Conflicts:
	lib/handlers/build.rb
	lib/handlers/helper.rb
	lib/handlers/package.rb
	lib/ssc.rb
  • Loading branch information
vlewin committed Jun 13, 2012
2 parents ab55fc1 + 5148bf1 commit 44929c1
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 79 deletions.
19 changes: 19 additions & 0 deletions MIT-LICENSE
@@ -0,0 +1,19 @@
Copyright (C) 2011 by SUSE Studio

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.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.4.0
0.4.4
1 change: 1 addition & 0 deletions lib/handlers/appliance.rb
Expand Up @@ -18,6 +18,7 @@ def create(appliance_name)
appliance_dir= ApplianceDirectory.new(appliance_name, appliance_params)
appliance_dir.create
say_array(["Created: ", appliance_dir.path] + appliance_dir.files.values)
say "" # make sure terminal output starts on a new line
end

desc "appliance list", "list all appliances"
Expand Down
28 changes: 20 additions & 8 deletions lib/handlers/build.rb
Expand Up @@ -4,15 +4,15 @@ class Build < Base

default_task :build

desc "build", "build an appliance"
desc "build", "Builds an appliance.\n\nAccepted image types: oem, iso, xen, vmx"
require_appliance_id
method_option :image_type, :type => :string, :required => true
method_option :image_type, :type => :string, :default => "iso", :required => true
def build
require_appliance_directory do |appliance, files|
if appliance.status.state != "ok"
raise Thor::Error, "Appliance is not OK. Please fix before building.\n#{appliance.status.issues.join("\n")}\n"
else
build = StudioApi::RunningBuild.new(:appliance_id => appliance.id, :image_type => options.image_type)
build = StudioApi::RunningBuild.new(:appliance_id => appliance.id, :image_type => options.image_type, :force => true)
build.save
config_file= File.join(Dir.pwd, '.sscrc')
if File.exists?(config_file)
Expand All @@ -31,9 +31,9 @@ def build
require_authorization
require_build_id
def status
build = StudioApi::Build.find options.build_id
additional_info=(build.state == 'finished' ? "" : " - #{build.percent}")
say "Build Status: #{build.state}" + additional_info
build = StudioApi::RunningBuild.find options.build_id
say "Build Status: #{build.state}"
say "#{build.percent}% completed" if build.state == "running"
end

desc "list", "list builds (running or completed)"
Expand All @@ -45,12 +45,24 @@ def list
else
StudioApi::Build.find(:all, :params => {:appliance_id => options.appliance_id})
end

say "Build List:\n"
print_table([["id", "version", "state"]]+
builds.collect{|i| [i.id, "v#{i.version}", i.state]})
builds_info = builds.collect{ |i|
[i.id, "v#{i.version}", i.state, format_download_url(i)]
}

print_table([["id", "version", "state", "download link"]]+ builds_info)
end

private

def format_download_url build
if build.respond_to?(:download_url)
build.download_url
else
"n\\a"
end
end
end
end
end
1 change: 0 additions & 1 deletion lib/handlers/helper.rb
Expand Up @@ -30,7 +30,6 @@ def require_authorization
method_option :password, :type => :string, :required => true,
:default => config["password"]
end

method_option :proxy, :type => :string
method_option :timeout, :type => :string
end
Expand Down
125 changes: 70 additions & 55 deletions lib/handlers/package.rb
Expand Up @@ -50,8 +50,8 @@ def search(search_string)
require_appliance do |appliance|
params= {:all_repos => options.all_repos} if options.all_repos
software= appliance.search_software(search_string, params)
say_array software.collect do |software|
"#{software.name} v#{software.version}. Repo Id: #{software.repository_id}"
software.collect do |software|
say "#{software.name} v#{software.version}. Repo Id: #{software.repository_id}"
end
end
end
Expand Down Expand Up @@ -79,81 +79,96 @@ def list(type)
say out.to_yaml
end


desc 'package add NAME', 'add a package to the appliance'
desc 'package add NAMES', 'add packages to the appliance'
require_appliance_id
allow_remote_option
def add(name)
if options.remote?
require_appliance do |appliance|
response= appliance.add_package(name)
say case response['state']
when "changed"
"Package Added. State: #{response['state']}"
when "equal"
"Package Not Added."
when "broken"
"Package Added. State: #{response['state']}. Please resolve dependencies"
else
"unknown code"
def add(*names)
names.each do |name|
if options.remote?
say "#{name}"
require_appliance do |appliance|
response= appliance.add_package(name)
say case response['state']
when "changed"
"Package #{name} added. State: #{response['state']}."
when "equal"
"Package #{name} not added."
when "broken"
"Package #{name} added. State: #{response['state']}. Please resolve dependencies."
else
"unknown code"
end
end
else
package_file= PackageFile.new
package_file.push('add', name)
package_file.save
say "#{name} marked for addition"
end
else
package_file= PackageFile.new
package_file.push('add', name)
package_file.save
say "#{name} marked for addition"
end
end

desc 'package remove NAME', 'remove a package from the appliance'
desc 'package remove NAMES', 'remove packages from the appliance'
require_appliance_id
allow_remote_option
def remove(name)
if options.remote?
require_appliance do |appliance|
response= appliance.remove_package(name)
say "State: #{response['state']}"
def remove(*names)
names.each do |name|
if options.remote?
require_appliance do |appliance|
response= appliance.remove_package(name)
say case response['state']
when "changed"
"Package #{name} removed. State: #{response['state']}."
when "equal"
"Package #{name} not removed."
else
"unknown code"
end
end
else
package_file= PackageFile.new
package_file.push('remove', name)
package_file.save
say "#{name} marked for removal"
end
else
package_file= PackageFile.new
package_file.push('remove', name)
package_file.save
say "#{name} marked for removal"
end
end

desc 'package ban NAME', 'ban a package from the appliance'
desc 'package ban NAMES', 'ban packages from the appliance'
require_appliance_id
allow_remote_option
def ban(name)
if options.remote?
require_appliance do |appliance|
response= appliance.ban_package(name)
response.collect{|key, val| "#{key}: #{val}"}
def ban(*names)
names.each do |name|
if options.remote?
require_appliance do |appliance|
response= appliance.ban_package(name)
response.collect{|key, val| "#{key}: #{val}"}
end
else
package_file= PackageFile.new
package_file.push('ban', name)
package_file.save
say "#{name} marked to be banned"
end
else
package_file= PackageFile.new
package_file.push('ban', name)
package_file.save
say "#{name} marked to be banned"
end
end

desc 'package unban NAME', 'unban a package for the appliance'
desc 'package unban NAMES', 'unban packages for the appliance'
require_appliance_id
allow_remote_option
def unban(name)
if options.remote?
require_appliance do |appliance|
response= appliance.unban_package(name)
response.collect{|key, val| "#{key}: #{val}"}
def unban(*names)
names.each do |name|
if options.remote?
require_appliance do |appliance|
response= appliance.unban_package(name)
response.collect{|key, val| "#{key}: #{val}"}
end
else
package_file= PackageFile.new
package_file.push('unban', name)
package_file.save
say "#{name} marked to be unbanned"
end
else
package_file= PackageFile.new
package_file.push('unban', name)
package_file.save
say "#{name} marked to be unbanned"
end
end
end
Expand Down
13 changes: 8 additions & 5 deletions lib/handlers/repository.rb
Expand Up @@ -38,10 +38,13 @@ def search(search_string)
params= {:filter => search_string}
params= params.merge({:base_system => options.base_system}) if options.base_system
repos= StudioApi::Repository.find(:all, :params => params)
say_array(repos.collect do |repo|
"#{repo.id}.) #{repo.name}: #{repo.base_url}
#{[repo.matches.software_name].flatten.join(', ')}\n"
end)
repos.collect do |repo|
# for some reason some repos don't have a base_url
if repo.respond_to?('base_url')
say "#{repo.id}.) #{repo.name}: #{repo.base_url}
#{[repo.matches.attributes["software_name"]].flatten.join(', ')}\n"
end
end
end

desc "repository list", "list all repositories in a given appliance"
Expand Down Expand Up @@ -71,7 +74,7 @@ def add(*repo_ids)
if options.remote?
require_appliance do |appliance|
response= appliance.add_repository(repo_ids)
say "Added"+( response.collect{|repos| repos.name} ).join(", ")
say "Added "+( response.collect{|repos| repos.name} ).join(", ")
end
else
repo_file= RepositoryFile.new
Expand Down
23 changes: 17 additions & 6 deletions lib/handlers/template.rb
Expand Up @@ -5,19 +5,30 @@ class Template < Base
desc 'template list_sets', 'list all available template sets'
require_authorization
def list_sets
templates= StudioApi::TemplateSet.find(:all)
templates= get_templates
say_array templates.collect {|template| template.name}
end

desc 'template list SET_NAME', 'show details of a particular template set'
require_authorization
def list(name)
template_set= StudioApi::TemplateSet.find(name)
out = [template_set.name+' : '+template_set.description]
out += template_set.template.collect do |appliance|
"#{appliance.appliance_id}: #{appliance.name}"
template_set= get_templates.select{|t| t.name == name}[0]

if template_set.nil?
say "Template set called '#{name}' was not found."
else
out = [template_set.name+' : '+template_set.description]
out += template_set.template.collect do |appliance|
"#{appliance.appliance_id}: #{appliance.name}"
end
say_array out
end
say_array out
end

private

def get_templates
StudioApi::TemplateSet.find(:all)
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions lib/ssc.rb
@@ -1,6 +1,8 @@
module SSC
end

require 'rubygems'

require 'thor'
require 'thor/group'
require 'directory_manager'
Expand Down Expand Up @@ -105,6 +107,15 @@ def commit
end
repository_file.save

# Add, Remove, Ban and Unban Packages
package_file= PackageFile.new
["add", "remove", "ban", "unban"].each do |action|
while package= package_file.pop(action)
invoke "s_s_c:handler:package:#{action}", [package], params
end
end
package_file.save

# Add Overlay Files
file_list = FileListFile.new
while file= file_list.pop("add")
Expand Down
5 changes: 3 additions & 2 deletions ssc.gemspec
Expand Up @@ -5,11 +5,11 @@

Gem::Specification.new do |s|
s.name = %q{ssc}
s.version = "0.3.0"
s.version = "0.4.3"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Ratan Sebastian"]
s.date = %q{2011-08-28}
s.date = %q{2011-09-07}
s.default_executable = %q{ssc}
s.description = %q{Command-line client for Suse Studio}
s.email = %q{rjsvaljean@gmail.com}
Expand All @@ -20,6 +20,7 @@ Gem::Specification.new do |s|
s.files = [
"Gemfile",
"Gemfile.lock",
"MIT-LICENSE",
"README.rdoc",
"Rakefile",
"VERSION",
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_repository.rb
Expand Up @@ -21,7 +21,7 @@ class TestRepository < Test::Unit::TestCase

context "search" do
setup do
@default_mock_repo.stubs(:matches).returns(stub(:software_name => ''))
@default_mock_repo.stubs(:matches).returns(stub(:attributes => ''))
StudioApi::Repository.expects(:find).with(:all, has_entry(:params, {:filter => 'search_string'})).returns([@default_mock_repo])
end
should "search all repos" do
Expand Down

0 comments on commit 44929c1

Please sign in to comment.