From 20aab3448e37e3d753f582bcbd22c1cfbecad406 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Wed, 24 Oct 2012 18:22:03 +0200 Subject: [PATCH 1/6] request #157: Add first version of rubygems generator Executing share/reubygems/generate ir will create gems for OCA and CLI. The new gems will be copied to the source code root directory. Modify DEFAULTS, TEMPLATE and GEM_DESCRIPTION constants to modify or add new gems. --- share/rubygems/generate | 201 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100755 share/rubygems/generate diff --git a/share/rubygems/generate b/share/rubygems/generate new file mode 100755 index 0000000000..2c392a9e3c --- /dev/null +++ b/share/rubygems/generate @@ -0,0 +1,201 @@ +#!/usr/bin/env ruby + +require 'ap' +require 'fileutils' +require 'tmpdir' + + +DEFAULTS={ + :version => "3.8.0", + :date => Time.now.strftime("%Y-%m-%d"), + :dependencies => [] +} + +TEMPLATE=< { + :name => 'oca', + :files => [ + ['src/oca/ruby/OpenNebula.rb', '/lib'], + ['src/oca/ruby/OpenNebula/*.rb', '/lib/OpenNebula'] + ], + :summary => 'OpenNebula Client API', + :description => 'Libraries needed to talk to OpenNebula', + :dependencies => [ + 'nokogiri', + 'json' + ] + }, + + :cli => { + :name => 'cli', + :files => [ + ['src/cli/one[a-z]*', '/bin'], + ['src/cli/*.rb', '/lib'], + ['src/cli/one_helper/*.rb', '/lib/one_helper'], + ], + :summary => 'OpenNebula Client API', + :description => 'Commands used to talk to OpenNebula', + :dependencies => [ + ['opennebula-oca', "= #{DEFAULTS[:version]}"] + ] + } +} + +def sane_prefix(prefix) + return '' if !prefix or prefix.empty? + + p=prefix + + p.slice!(0) if p[0,1]=='/' + p<<'/' if p[-1,1]!='/' + + p +end + +def file_list(description) + files=Array.new + + ap description + + description[:files].each do |f, prefix| + source=Dir.glob(f) + + files+=source.map do |source| + [source, sane_prefix(prefix)+File.basename(source)] + end + end + + files +end + +def copy_files(files, source_prefix='', destination_prefix='') + files.each do |file| + source=source_prefix+file[0] + destination=destination_prefix+file[1] + + dir=File.dirname destination + + FileUtils.mkdir_p(dir) if !File.exist?(dir) + + FileUtils.cp(source, destination) + end +end + +def generate_gem_file_list(files) + files.map do |f| + " '#{f.last}'" + end.join(",\n") +end + +def generate_gem_executable_list(files) + executables=files. + select {|f| f.last.match(/^bin\//) }. + map {|f| "'#{File.basename(f.last)}'" }. + join(", ") + + if !executables.empty? + " s.executables=[#{executables}]" + else + nil + end +end + +def generate_dependencies(dependencies) + dependencies.map do |d| + line=" s.add_runtime_dependency " + if Array===d + line< Date: Wed, 24 Oct 2012 18:46:57 +0200 Subject: [PATCH 2/6] request #157: delete of debugging code --- share/rubygems/generate | 9 --------- 1 file changed, 9 deletions(-) diff --git a/share/rubygems/generate b/share/rubygems/generate index 2c392a9e3c..45c6ad6217 100755 --- a/share/rubygems/generate +++ b/share/rubygems/generate @@ -1,6 +1,5 @@ #!/usr/bin/env ruby -require 'ap' require 'fileutils' require 'tmpdir' @@ -76,8 +75,6 @@ end def file_list(description) files=Array.new - ap description - description[:files].each do |f, prefix| source=Dir.glob(f) @@ -155,7 +152,6 @@ def populate_gem_template(description, files) end def generate_gem_file(gem_file, description, files) - puts populate_gem_template(description, files) File.open(gem_file, "w") do |f| f.write(populate_gem_template(description, files)) end @@ -163,9 +159,6 @@ end def generate_gem(description) Dir.mktmpdir do |tmp| - - ap tmp - files=file_list(description) copy_files(files, '', tmp+"/") @@ -186,8 +179,6 @@ def generate_gem(description) FileUtils.cp(f, pwd) end end - - ap Dir.glob("*.gem") end end From 78b34667c59a28766f47467be1c96e3a02d2682c Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Wed, 24 Oct 2012 18:49:00 +0200 Subject: [PATCH 3/6] request #157: add copyright notice --- share/rubygems/generate | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/share/rubygems/generate b/share/rubygems/generate index 45c6ad6217..450c020ea3 100755 --- a/share/rubygems/generate +++ b/share/rubygems/generate @@ -1,5 +1,21 @@ #!/usr/bin/env ruby +# -------------------------------------------------------------------------- # +# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + require 'fileutils' require 'tmpdir' From 14211ce04d344ac4243831695b911240098b5f30 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Wed, 24 Oct 2012 19:18:48 +0200 Subject: [PATCH 4/6] request #157: add rubygems generation to scons script --- SConstruct | 6 +++++- share/rubygems/SConstruct | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 share/rubygems/SConstruct diff --git a/SConstruct b/SConstruct index b424b90a86..78485245f4 100644 --- a/SConstruct +++ b/SConstruct @@ -140,6 +140,9 @@ elif context_packages=='all': else: main_env.Append(context=context_packages.split(',')) +# Rubygem generation +main_env.Append(rubygems=ARGUMENTS.get('rubygems', 'no')) + if not main_env.GetOption('clean'): try: if mysql=='yes': @@ -226,7 +229,8 @@ build_scripts=[ 'share/man/SConstruct', 'src/sunstone/locale/languages/SConstruct', 'src/cloud/occi/lib/ui/locale/languages/SConstruct', - 'share/scripts/context-packages/Sconstruct' + 'share/scripts/context-packages/Sconstruct', + 'share/rubygems/SConstruct' ] # Testing diff --git a/share/rubygems/SConstruct b/share/rubygems/SConstruct new file mode 100644 index 0000000000..dfd637daab --- /dev/null +++ b/share/rubygems/SConstruct @@ -0,0 +1,30 @@ +# SConstruct for share/scripts/rubygems + +# -------------------------------------------------------------------------- # +# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +import os + +Import('env') + +if env['rubygems']=='yes': + print "Generating rubygems packages\n" + exit_code=os.system("./generate") + + if exit_code != 0: + print "Error generating rubygem packages\n" + exit(-1) + From 72df7a3bb74032787137dc1ef1918411f92d8691 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 19 Nov 2012 15:47:11 +0100 Subject: [PATCH 5/6] request #157: typo --- share/rubygems/generate | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/rubygems/generate b/share/rubygems/generate index 450c020ea3..131f746832 100755 --- a/share/rubygems/generate +++ b/share/rubygems/generate @@ -27,7 +27,7 @@ DEFAULTS={ } TEMPLATE=< Date: Mon, 19 Nov 2012 15:54:46 +0100 Subject: [PATCH 6/6] request #157: add NOTICE and LICENSE files --- share/rubygems/generate | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/share/rubygems/generate b/share/rubygems/generate index 131f746832..a6c17e7f7b 100755 --- a/share/rubygems/generate +++ b/share/rubygems/generate @@ -52,7 +52,9 @@ GEM_DESCRIPTION={ :name => 'oca', :files => [ ['src/oca/ruby/OpenNebula.rb', '/lib'], - ['src/oca/ruby/OpenNebula/*.rb', '/lib/OpenNebula'] + ['src/oca/ruby/OpenNebula/*.rb', '/lib/OpenNebula'], + ['NOTICE', ''], + ['LICENSE', ''] ], :summary => 'OpenNebula Client API', :description => 'Libraries needed to talk to OpenNebula', @@ -68,6 +70,8 @@ GEM_DESCRIPTION={ ['src/cli/one[a-z]*', '/bin'], ['src/cli/*.rb', '/lib'], ['src/cli/one_helper/*.rb', '/lib/one_helper'], + ['NOTICE', ''], + ['LICENSE', ''] ], :summary => 'OpenNebula Client API', :description => 'Commands used to talk to OpenNebula',