[DRE-commits] r5903 - in trunk: . gem2tgz gem2tgz/bin gem2tgz/debian gem2tgz/debian/source gem2tgz/lib gem2tgz/test gem2tgz/test/sample gem2tgz/test/sample/simplegem gem2tgz/test/sample/simplegem/lib gem2tgz/test/sample/simplegem/pkg gemwatch
Antonio Terceiro
terceiro-guest at alioth.debian.org
Mon Oct 11 17:26:10 UTC 2010
Author: terceiro-guest
Date: 2010-10-11 17:26:07 +0000 (Mon, 11 Oct 2010)
New Revision: 5903
Added:
trunk/gem2tgz/
trunk/gem2tgz/README.pod
trunk/gem2tgz/Rakefile
trunk/gem2tgz/bin/
trunk/gem2tgz/bin/gem2tgz
trunk/gem2tgz/debian/
trunk/gem2tgz/debian/changelog
trunk/gem2tgz/debian/compat
trunk/gem2tgz/debian/control
trunk/gem2tgz/debian/copyright
trunk/gem2tgz/debian/rules
trunk/gem2tgz/debian/source/
trunk/gem2tgz/debian/source/format
trunk/gem2tgz/lib/
trunk/gem2tgz/lib/gem2tgz.rb
trunk/gem2tgz/post-distclean.rb
trunk/gem2tgz/post-setup.rb
trunk/gem2tgz/test/
trunk/gem2tgz/test/gem2tgz_test.rb
trunk/gem2tgz/test/helper.rb
trunk/gem2tgz/test/sample/
trunk/gem2tgz/test/sample/simplegem/
trunk/gem2tgz/test/sample/simplegem/Rakefile
trunk/gem2tgz/test/sample/simplegem/lib/
trunk/gem2tgz/test/sample/simplegem/lib/simplegem.rb
trunk/gem2tgz/test/sample/simplegem/pkg/
trunk/gem2tgz/test/sample/simplegem/pkg/simplegem-0.0.1.gem
Modified:
trunk/gemwatch/gemwatch.rb
Log:
First version of gem2tgz tool
Added: trunk/gem2tgz/README.pod
===================================================================
--- trunk/gem2tgz/README.pod (rev 0)
+++ trunk/gem2tgz/README.pod 2010-10-11 17:26:07 UTC (rev 5903)
@@ -0,0 +1,70 @@
+=head1 NAME
+
+gem2tgz - converts Rubygems' .gem file into tarballs
+
+=head1 USAGE
+
+gem2tgz [OPTIONS] GEM [TARBALL]
+
+=head1 DESCRIPTION
+
+B<gem2tgz> will convert the .gem file I<GEM> into a tarball named I<TARBALL>.
+If I<TARBALL> is omitted, B<gem2tgz> will try to guess the filename for the
+tarball by taking I<GEM> and replacing '.gem' with '.tar.gz'.
+
+=head1 OPTIONS
+
+=over
+
+=item --help
+
+Displays B<gem2tgz> usage information.
+
+=back
+
+=head1 HOW THE CONVERSION WORKS
+
+A gem named I<mygem-0.1.0.gem> is converted in a tarball with
+(approximately) the following steps:
+
+ mkdir mygem-0.1.0
+ cd mygem-0.1.0
+ tar xfm /absolute/path/to/mygem-0.1.0.gem
+ tar xzfm data.tar.gz
+ zcat metadata.gz > metadata.yml
+ rm -f data.tar.gz metadata.gz
+ cd ..
+ tar czf mygem-0.1.0.tar.gz mygem-0.1.0
+ rm -rf mygem-0.1.0
+
+The generated tarball has the following properties:
+
+=over
+
+=item Files
+
+It contains all the files the gem contains.
+
+=item Metadata
+
+It contains the gem metadata ends up in a file named ``metadata.yml`` inside the I<mygem-0.1.0> directory.
+
+=back
+
+=head1 COPYRIGHT AND AUTHORS
+
+Copyright (c) 2010, Antonio Terceiro <terceiro at softwarelivre.org>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
Added: trunk/gem2tgz/Rakefile
===================================================================
--- trunk/gem2tgz/Rakefile (rev 0)
+++ trunk/gem2tgz/Rakefile 2010-10-11 17:26:07 UTC (rev 5903)
@@ -0,0 +1,10 @@
+require 'rake/testtask'
+
+task :default => :test
+
+Rake::TestTask.new do |t|
+ t.libs << "lib"
+ t.libs << "test"
+ t.test_files = FileList['test/*_test.rb']
+ t.verbose = true
+end
Added: trunk/gem2tgz/bin/gem2tgz
===================================================================
--- trunk/gem2tgz/bin/gem2tgz (rev 0)
+++ trunk/gem2tgz/bin/gem2tgz 2010-10-11 17:26:07 UTC (rev 5903)
@@ -0,0 +1,67 @@
+#! /usr/bin/ruby1.8
+#
+# Copyright © 2010, Antonio Terceiro <terceiro at softwarelivre.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# = Synopsis
+#
+# gem2tgz - converts a Ruby gem file into a source tarball proper for being used
+# as upstream source tarball on Debian packages.
+#
+# = Usage
+#
+# gem2tgz [OPTIONS] GEM [TARBALL]
+#
+# -h, --help:
+# show help
+#
+# GEM: a valid Rubygem's .gem file
+#
+# TARBALL: destination tarball to be created. If omitted, gem2tgz will try to
+# guess based on GEM argument.
+
+require 'gem2tgz'
+require 'getoptlong'
+require 'rdoc/usage'
+
+opts = GetoptLong.new(
+ [ '--version', '-v', GetoptLong::NO_ARGUMENT ],
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ]
+)
+
+opts.each do |opt,arg|
+ case opt
+ when '--help'
+ RDoc::usage(0, 'usage')
+ when '--version'
+ puts "gem2tgz version #{Gem2Tgz::VERSION}"
+ exit(0)
+ end
+end
+
+if ARGV.length != 1 && ARGV.length != 2
+ puts "usage: gem2tgz [OPTIONS] GEM [TARBALL]"
+ exit(1)
+end
+
+gem = ARGV[0]
+if gem !~ /\.gem$/
+ puts "#{gem} does not look like a valid .gem file."
+ exit(1)
+end
+
+tarball = ARGV[1] || gem.gsub(/\.gem$/, '.tar.gz')
+
+Gem2Tgz.convert!(gem, tarball)
Added: trunk/gem2tgz/debian/changelog
===================================================================
--- trunk/gem2tgz/debian/changelog (rev 0)
+++ trunk/gem2tgz/debian/changelog 2010-10-11 17:26:07 UTC (rev 5903)
@@ -0,0 +1,5 @@
+gem2tgz (0.1.0) unstable; urgency=low
+
+ * Initial Release.
+
+ -- Antonio Terceiro <terceiro at softwarelivre.org> Sat, 09 Oct 2010 18:16:11 -0300
Added: trunk/gem2tgz/debian/compat
===================================================================
--- trunk/gem2tgz/debian/compat (rev 0)
+++ trunk/gem2tgz/debian/compat 2010-10-11 17:26:07 UTC (rev 5903)
@@ -0,0 +1 @@
+7
Added: trunk/gem2tgz/debian/control
===================================================================
--- trunk/gem2tgz/debian/control (rev 0)
+++ trunk/gem2tgz/debian/control 2010-10-11 17:26:07 UTC (rev 5903)
@@ -0,0 +1,19 @@
+Source: gem2tgz
+Section: ruby
+Priority: extra
+Maintainer: Antonio Terceiro <terceiro at softwarelivre.org>
+Build-Depends: debhelper (>= 7.0.50~), cdbs, ruby-pkg-tools
+Standards-Version: 3.9.1
+Homepage: http://wiki.debian.org/Teams/Ruby/gem2tgz
+Vcs-Browser: http://svn.debian.org/viewsvn/pkg-ruby-extras/trunk/gem2tgz/
+Vcs-Svn: svn://svn.debian.org/svn/pkg-ruby-extras/trunk/gem2tgz/
+
+Package: gem2tgz
+Architecture: any
+Depends: ruby1.8, ${shlibs:Depends}, ${misc:Depends}
+Description: converts Rubygems' .gem files into proper source tarballs
+ Most Ruby libraries are distributed in .gem format, and several of them are
+ not distributed in other form. For making Debian packages, however, it's
+ preferable to have proper source tarballs. gem2tgz converts Rubygems' .gem
+ files into tarballs suitable for use as upstream source tarballs in Debian
+ packages.
Added: trunk/gem2tgz/debian/copyright
===================================================================
--- trunk/gem2tgz/debian/copyright (rev 0)
+++ trunk/gem2tgz/debian/copyright 2010-10-11 17:26:07 UTC (rev 5903)
@@ -0,0 +1,35 @@
+This work was packaged for Debian by:
+
+ Antonio Terceiro <terceiro at softwarelivre.org> on Sat, 09 Oct 2010 18:16:11 -0300
+
+Author(s):
+
+ Antonio Terceiro <terceiro at softwarelivre.org>
+
+Copyright:
+
+ Copyright © 2010 Antonio Terceiro
+
+License:
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This package is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+On Debian systems, the complete text of the GNU General
+Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
+
+The Debian packaging is:
+
+ Copyright (C) 2010 Antonio Terceiro <terceiro at softwarelivre.org>
+
+and is licensed under the GPL version 3, see above.
Added: trunk/gem2tgz/debian/rules
===================================================================
--- trunk/gem2tgz/debian/rules (rev 0)
+++ trunk/gem2tgz/debian/rules 2010-10-11 17:26:07 UTC (rev 5903)
@@ -0,0 +1,13 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+include /usr/share/cdbs/1/rules/debhelper.mk
+include /usr/share/ruby-pkg-tools/1/class/ruby-setup-rb.mk
Property changes on: trunk/gem2tgz/debian/rules
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/gem2tgz/debian/source/format
===================================================================
--- trunk/gem2tgz/debian/source/format (rev 0)
+++ trunk/gem2tgz/debian/source/format 2010-10-11 17:26:07 UTC (rev 5903)
@@ -0,0 +1 @@
+3.0 (native)
Added: trunk/gem2tgz/lib/gem2tgz.rb
===================================================================
--- trunk/gem2tgz/lib/gem2tgz.rb (rev 0)
+++ trunk/gem2tgz/lib/gem2tgz.rb 2010-10-11 17:26:07 UTC (rev 5903)
@@ -0,0 +1,81 @@
+# Copyright © 2010, Antonio Terceiro <terceiro at softwarelivre.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+require 'fileutils'
+
+class Gem2Tgz
+
+ VERSION = '0.1.0'
+
+ class CommandFailed < Exception
+ end
+
+ def self.convert!(gem, tarball)
+ self.new(gem, tarball).convert!
+ end
+
+ attr_reader :gem, :gem_full_path
+ attr_reader :tarball, :tarball_full_path
+ attr_reader :target_dir
+
+ def initialize(gem, tarball)
+ @gem = gem
+ @gem_full_path = File.expand_path(gem)
+ @tarball = tarball
+ @tarball_full_path = File.expand_path(tarball)
+ @target_dir = tarball_full_path.gsub('.tar.gz', '')
+ end
+
+ def convert!
+ create_target_dir
+ extract_gem_contents
+ create_resulting_tarball
+ cleanup
+ end
+
+ protected
+
+ def create_target_dir
+ FileUtils.mkdir_p(target_dir)
+ end
+
+ def extract_gem_contents
+ Dir.chdir(target_dir) do
+ run "tar xfm #{gem_full_path}"
+ run 'tar xzfm data.tar.gz'
+ FileUtils.rm_f('data.tar.gz')
+ run "zcat metadata.gz > metadata.yml"
+ FileUtils.rm_f('metadata.gz')
+ end
+ end
+
+ def create_resulting_tarball
+ Dir.chdir(File.dirname(tarball_full_path)) do
+ run "tar czf #{File.basename(tarball)} #{File.basename(target_dir)}"
+ end
+ end
+
+ def cleanup
+ FileUtils.rm_rf(target_dir)
+ end
+
+ def run(cmd)
+ system(cmd)
+ if $? && ($? >> 8) > 0
+ raise Gem2Tgz::CommandFailed, "[#{cmd} failed!]"
+ end
+ end
+
+end
Added: trunk/gem2tgz/post-distclean.rb
===================================================================
--- trunk/gem2tgz/post-distclean.rb (rev 0)
+++ trunk/gem2tgz/post-distclean.rb 2010-10-11 17:26:07 UTC (rev 5903)
@@ -0,0 +1,2 @@
+require 'fileutils'
+FileUtils.rm_rf('man')
Added: trunk/gem2tgz/post-setup.rb
===================================================================
--- trunk/gem2tgz/post-setup.rb (rev 0)
+++ trunk/gem2tgz/post-setup.rb 2010-10-11 17:26:07 UTC (rev 5903)
@@ -0,0 +1,7 @@
+require 'fileutils'
+$: << 'lib'
+require 'gem2tgz'
+
+FileUtils.mkdir_p('man/man1')
+cmdline = "pod2man --name='gem2tgz' --release='#{Gem2Tgz::VERSION}' --center='gem2tgz' README.pod > man/man1/gem2tgz.1"
+system(cmdline) or raise("Command [#{cmdline}] failed")
Added: trunk/gem2tgz/test/gem2tgz_test.rb
===================================================================
--- trunk/gem2tgz/test/gem2tgz_test.rb (rev 0)
+++ trunk/gem2tgz/test/gem2tgz_test.rb 2010-10-11 17:26:07 UTC (rev 5903)
@@ -0,0 +1,53 @@
+require 'test/helper'
+require 'yaml'
+require 'rubygems'
+
+require 'gem2tgz'
+
+class Gem2TgzTest < Gem2TgzTestCase
+
+ SIMPLE_GEM = File.join(File.dirname(__FILE__), 'sample/simplegem/pkg/simplegem-0.0.1.gem')
+ SIMPLE_GEM_TARBALL = File.join(File.dirname(__FILE__), 'tmp/simplegem-0.0.1.tar.gz')
+ SIMPLE_GEM_TARGET_DIR = File.join(File.dirname(__FILE__), 'tmp/simplegem-0.0.1')
+
+ context 'converting a simple gem' do
+ setup do
+ Gem2Tgz.convert!(SIMPLE_GEM, SIMPLE_GEM_TARBALL)
+ end
+
+ should 'create tarball' do
+ assert_file_exists SIMPLE_GEM_TARBALL
+ end
+ should 'include the contents of the gem in the tarball' do
+ assert_contained_in_tarball SIMPLE_GEM_TARBALL, 'simplegem-0.0.1/lib/simplegem.rb'
+ end
+ should 'not include data.tar.gz' do
+ assert_not_contained_in_tarball SIMPLE_GEM_TARBALL, 'simplegem-0.0.1/data.tar.gz'
+ end
+ should 'not include metadata.gz' do
+ assert_not_contained_in_tarball SIMPLE_GEM_TARBALL, 'simplegem-0.0.1/metadata.gz'
+ end
+ should 'not leave temporary directory after creating tarball' do
+ assert_no_file_exists SIMPLE_GEM_TARGET_DIR
+ end
+ should 'create metadata.yml' do
+ unpack(SIMPLE_GEM_TARBALL) do
+ assert_file_exists 'simplegem-0.0.1/metadata.yml'
+ end
+ end
+ context 'looking inside metadata.yml' do
+ setup do
+ @gemspec = unpack(SIMPLE_GEM_TARBALL) do
+ YAML.load_file('simplegem-0.0.1/metadata.yml')
+ end
+ end
+ should 'be valid gemspec' do
+ assert_kind_of Gem::Specification, @gemspec
+ end
+ should "be simplegem's spec" do
+ assert_equal 'simplegem', @gemspec.name
+ end
+ end
+ end
+
+end
Added: trunk/gem2tgz/test/helper.rb
===================================================================
--- trunk/gem2tgz/test/helper.rb (rev 0)
+++ trunk/gem2tgz/test/helper.rb 2010-10-11 17:26:07 UTC (rev 5903)
@@ -0,0 +1,53 @@
+require 'test/unit'
+require 'shoulda'
+require 'fileutils'
+
+class Gem2TgzTestCase < Test::Unit::TestCase
+
+ TMP_DIR = File.join(File.dirname(__FILE__), 'tmp')
+
+ def setup
+ FileUtils.mkdir_p(TMP_DIR)
+ end
+
+ def teardown
+ FileUtils.rm_rf(TMP_DIR)
+ end
+
+ def run(runner)
+ return if @method_name.to_s == 'default_test'
+ super
+ end
+
+ protected
+
+ def unpack(tarball)
+ Dir.chdir(File.dirname(tarball)) do
+ system 'tar', 'xzf', File.basename(tarball)
+ yield
+ end
+ end
+
+ def contents(tarball)
+ IO.popen("tar tzf #{tarball}").readlines.map(&:strip)
+ end
+
+ def assert_contained_in_tarball(tarball, file)
+ list = contents(tarball)
+ assert list.include?(file), "#{tarball} should contain #{file} (contents: #{list.inspect})"
+ end
+
+ def assert_not_contained_in_tarball(tarball, file)
+ list = contents(tarball)
+ assert !list.include?(file), "#{tarball} should NOT contain #{file} (contents: #{list.inspect})"
+ end
+
+ def assert_file_exists(path)
+ assert File.exist?(path), "#{path} should exist"
+ end
+
+ def assert_no_file_exists(path)
+ assert !File.exist?(path), "#{path} should NOT exist"
+ end
+
+end
Added: trunk/gem2tgz/test/sample/simplegem/Rakefile
===================================================================
--- trunk/gem2tgz/test/sample/simplegem/Rakefile (rev 0)
+++ trunk/gem2tgz/test/sample/simplegem/Rakefile 2010-10-11 17:26:07 UTC (rev 5903)
@@ -0,0 +1,21 @@
+require 'rubygems'
+require 'rake/gempackagetask'
+
+spec = Gem::Specification.new do |s|
+ s.platform = Gem::Platform::RUBY
+ s.summary = "Simple gem used to test gem2tgz."
+ s.name = 'simplegem'
+ s.version = '0.0.1'
+ s.requirements << 'none'
+ s.require_path = 'lib'
+ #s.autorequire = 'rake'
+ s.files = Dir.glob('lib/**')
+ s.description = <<EOF
+simplegem is a simple gem that is used to test gem2tgz.
+EOF
+end
+
+Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.need_zip = true
+ pkg.need_tar = true
+end
Added: trunk/gem2tgz/test/sample/simplegem/pkg/simplegem-0.0.1.gem
===================================================================
(Binary files differ)
Property changes on: trunk/gem2tgz/test/sample/simplegem/pkg/simplegem-0.0.1.gem
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: trunk/gemwatch/gemwatch.rb
===================================================================
--- trunk/gemwatch/gemwatch.rb 2010-10-11 15:01:06 UTC (rev 5902)
+++ trunk/gemwatch/gemwatch.rb 2010-10-11 17:26:07 UTC (rev 5903)
@@ -2,6 +2,7 @@
require 'haml'
require 'restclient'
require 'json'
+require 'gem2tgz'
require 'open-uri'
@@ -68,19 +69,12 @@
end
def download_and_convert!
unless File.exist?(tarball_path)
- FileUtils.rm_rf(absolute_directory)
- FileUtils.mkdir_p(absolute_directory)
- Dir.chdir(absolute_directory) do
+ FileUtils.mkdir_p(download_dir)
+ Dir.chdir(download_dir) do
download uri
- run "tar xfm #{gem}"
- run "tar xzfm data.tar.gz"
- run "zcat metadata.gz > metadata.yml"
- FileUtils.rm_f([gem, "data.tar.gz", "metadata.gz"])
+ Gem2Tgz.convert!(gem, tarball)
+ FileUtils.rm_f(gem)
end
- Dir.chdir(File.dirname(absolute_directory)) do
- run "tar czf #{tarball} #{directory}"
- FileUtils.rm_rf(directory)
- end
end
end
def directory
@@ -89,9 +83,6 @@
def download_dir
@download_dir ||= File.join(DOWNLOAD_BASE, name[0..0], name)
end
- def absolute_directory
- File.join(download_dir, directory)
- end
def tarball
"#{directory}.tar.gz"
end
More information about the Pkg-ruby-extras-commits
mailing list