PageRenderTime 97ms CodeModel.GetById 78ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Ruby/lib/ruby/site_ruby/1.8/rubygems/commands/generate_index_command.rb

http://github.com/agross/netopenspace
Ruby | 124 lines | 98 code | 20 blank | 6 comment | 1 complexity | cfd2ab109be023f892079ef7dc423fda MD5 | raw file
  1require 'rubygems/command'
  2require 'rubygems/indexer'
  3
  4##
  5# Generates a index files for use as a gem server.
  6#
  7# See `gem help generate_index`
  8
  9class Gem::Commands::GenerateIndexCommand < Gem::Command
 10
 11  def initialize
 12    super 'generate_index',
 13          'Generates the index files for a gem server directory',
 14          :directory => '.', :build_legacy => true, :build_modern => true
 15
 16    add_option '-d', '--directory=DIRNAME',
 17               'repository base dir containing gems subdir' do |dir, options|
 18      options[:directory] = File.expand_path dir
 19    end
 20
 21    add_option '--[no-]legacy',
 22               'Generate Marshal.4.8' do |value, options|
 23      unless options[:build_modern] or value then
 24        raise OptionParser::InvalidOption, 'no indicies will be built'
 25      end
 26
 27      options[:build_legacy] = value
 28    end
 29
 30    add_option '--[no-]modern',
 31               'Generate indexes for RubyGems newer',
 32               'than 1.2.0' do |value, options|
 33      unless options[:build_legacy] or value then
 34        raise OptionParser::InvalidOption, 'no indicies will be built'
 35      end
 36
 37      options[:build_modern] = value
 38    end
 39
 40    add_option '--update',
 41               'Update modern indexes with gems added',
 42               'since the last update' do |value, options|
 43      options[:update] = value
 44    end
 45
 46    add_option :RSS, '--rss-gems-host=GEM_HOST',
 47               'Host name where gems are served from,',
 48               'used for GUID and enclosure values' do |value, options|
 49      options[:rss_gems_host] = value
 50    end
 51
 52    add_option :RSS, '--rss-host=HOST',
 53               'Host name for more gems information,',
 54               'used for RSS feed link' do |value, options|
 55      options[:rss_host] = value
 56    end
 57
 58    add_option :RSS, '--rss-title=TITLE',
 59               'Set title for RSS feed' do |value, options|
 60      options[:rss_title] = value
 61    end
 62  end
 63
 64  def defaults_str # :nodoc:
 65    "--directory . --legacy --modern"
 66  end
 67
 68  def description # :nodoc:
 69    <<-EOF
 70The generate_index command creates a set of indexes for serving gems
 71statically.  The command expects a 'gems' directory under the path given to
 72the --directory option.  The given directory will be the directory you serve
 73as the gem repository.
 74
 75For `gem generate_index --directory /path/to/repo`, expose /path/to/repo via
 76your HTTP server configuration (not /path/to/repo/gems).
 77
 78When done, it will generate a set of files like this:
 79
 80  gems/*.gem                                   # .gem files you want to
 81                                               # index
 82
 83  specs.<version>.gz                           # specs index
 84  latest_specs.<version>.gz                    # latest specs index
 85  prerelease_specs.<version>.gz                # prerelease specs index
 86  quick/Marshal.<version>/<gemname>.gemspec.rz # Marshal quick index file
 87
 88  # these files support legacy RubyGems
 89  Marshal.<version>
 90  Marshal.<version>.Z                          # Marshal full index
 91
 92The .Z and .rz extension files are compressed with the inflate algorithm.
 93The Marshal version number comes from ruby's Marshal::MAJOR_VERSION and
 94Marshal::MINOR_VERSION constants.  It is used to ensure compatibility.
 95
 96If --rss-host and --rss-gem-host are given an RSS feed will be generated at
 97index.rss containing gems released in the last two days.
 98    EOF
 99  end
100
101  def execute
102    if options[:update] and
103       (options[:rss_host] or options[:rss_gems_host]) then
104      alert_error '--update not compatible with RSS generation'
105      terminate_interaction 1
106    end
107
108    if not File.exist?(options[:directory]) or
109       not File.directory?(options[:directory]) then
110      alert_error "unknown directory name #{directory}."
111      terminate_interaction 1
112    else
113      indexer = Gem::Indexer.new options.delete(:directory), options
114
115      if options[:update] then
116        indexer.update_index
117      else
118        indexer.generate_index
119      end
120    end
121  end
122
123end
124