Debian Codegraph @

bin/gem2tgz

raw
1 #!/usr/bin/ruby
2 #
3 # Copyright © 2010, Antonio Terceiro <[email protected]>
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 require 'gem2deb'
19 require 'gem2deb/gem2tgz'
20 require 'optparse'
21 require 'rubygems'
22
23
24 optparse = OptionParser.new do |opts|
25 opts.banner = "Usage: gem2tgz [OPTIONS] GEMNAME|GEMFILE [TARBALL]"
26 opts.separator "Options:"
27
28 opts.on('-h', '--help', 'show help') do
29 puts opts
30 exit
31 end
32
33 opts.on('-v', '--version', 'show version') do
34 puts "gem2tgz version #{Gem2Deb::VERSION}"
35 exit
36 end
37 end
38 optparse.parse!
39
40 if ARGV.length != 1 && ARGV.length != 2
41 puts optparse
42 exit(1)
43 end
44
45 gemfile = ARGV[0]
46 # Download gem if not available locally
47 if not File::exist?(gemfile) and gemfile !~ /.gem$/
48 puts "#{gemfile} doesn't seem to exist. Let's try to download it with 'gem fetch #{ARGV[0]}'"
49 if gemfile =~ /^rails-assets/
50 run("gem", "fetch", "--source", "https://rails-assets.org", gemfile)
51 else
52 run("gem", "fetch", gemfile)
53 end
54 versions = Dir::glob("#{gemfile}-*.gem").map do |a|
55 Gem::Version.new(a.sub(/#{gemfile}-(.+)\.gem/, '\1'))
56 end
57 # and pick the most recent one
58 last_version = versions.max
59 gemfile = "#{gemfile}-#{last_version}.gem"
60 end
61
62 Gem2Deb::Gem2Tgz.convert!(gemfile, ARGV[1] || nil)
63
64 __END__
65 =head1 NAME
66
67 gem2tgz - converts Rubygems' .gem file into tarballs
68
69 =head1 SYNOPSIS
70
71 B<gem2tgz> [I<OPTIONS>] I<GEMNAME> [I<TARBALL>] (to download the gem with I<gem fetch>)
72
73 B<gem2tgz> [I<OPTIONS>] I<GEMFILE> [I<TARBALL>] (to use a local .gem file)
74
75 =head1 DESCRIPTION
76
77 B<gem2tgz> will convert the .gem file I<GEM> into a tarball named I<TARBALL>.
78 If I<TARBALL> is omitted, B<gem2tgz> will try to guess the filename for the
79 tarball by taking I<GEM> and replacing '.gem' with '.tar.gz'.
80
81 =head1 SEE ALSO
82
83 L<B<gem2deb>>(1)
84
85 =head1 COPYRIGHT AND AUTHORS
86
87 Copyright (c) 2010, Antonio Terceiro <[email protected]>
88
89 This program is free software: you can redistribute it and/or modify
90 it under the terms of the GNU General Public License as published by
91 the Free Software Foundation, either version 3 of the License, or
92 (at your option) any later version.
93
94 This program is distributed in the hope that it will be useful,
95 but WITHOUT ANY WARRANTY; without even the implied warranty of
96 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
97 GNU General Public License for more details.
98
99 You should have received a copy of the GNU General Public License
100 along with this program. If not, see <http://www.gnu.org/licenses/>.