/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

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