lib/right_publish.rb in right_publish-0.3.0 vs lib/right_publish.rb in right_publish-0.4.0

- old
+ new

@@ -1,97 +1,35 @@ # # === Synopsis: # RightScale RightPublish (right_publish) - (c) 2013 RightScale Inc # -require 'trollop' +require 'mime/types' -require 'right_publish/profile' -require 'right_publish/repo' - module RightPublish - module Main - REPOSITORY_TYPES = RepoManager.repo_types() - SUB_COMMANDS = %w(publish fetch store) + # Combined list of MIME types that should be registered with mime-types, AND preferred + # MIME types for this application to use, in cases where a given filename extension is + # used by multiple MIME types. + MIME_TYPES = { + 'application/x-deb' => 'deb', + 'application/x-ruby-gem' => 'gem', + 'application/x-rpm' => 'rpm', + 'application/x-msi' => 'msi', + 'text/xml' => 'xml', + } +end - def self.run() - options = parse_args - - begin - profile = RightPublish::Profile.instance - profile.load(options[:profile]) - rescue LoadError => e - puts e - exit -1 - end - - # These options override profile attributes. - profile.settings[:local_storage][:cache_dir] = options[:local_cache] if options[:local_cache] - profile.settings[:verbose] = true if options[:verbose] - - # We already know this is a valid type, parse_args checked - repo = RepoManager.get_repository(REPOSITORY_TYPES[options[:repo_type]]) - begin - case options[:cmd] - when "publish" - repo.publish(options[:files], options[:dist]) - when "store" - repo.store - when "fetch" - repo.fetch - else - end - rescue RuntimeError => e - RightPublish::Profile.log("Fatal Error:\n\t#{e}", :error) - exit -1 - end - RightPublish::Profile.log("Success!") +# Register some extra MIME types that the gem may not know about. +RightPublish::MIME_TYPES.each_pair do |name, extension| + if MIME::Types[name].empty? + type = MIME::Type.new(name) do |t| + t.extensions = [extension] + t.encoding = '8bit' end - - def self.parse_args() - options = Trollop.options do - version "RightPublish alpha (c) 2013 RightScale Inc" - banner <<-EOS -RightPublish can manage a YUM/APT/RubyGem repository in remote storage, e.g. S3. - -Usage: - right_publish [global_options] <command> [file1, file2, ...] - -commands: - fetch - publish - store - -global options: -EOS - - opt :local_cache, "Local cache location", :type => String - opt :profile, "Publish profile", :type => String - opt :repo_type, "Repository type: #{REPOSITORY_TYPES.keys.inspect}", :type => String - opt :dist, "Target distribution. Required for binary packages. If unspecified for noarch and source packages, will copy to all distributions specified in profile.", :type => String - opt :verbose, "Verbose output" - - stop_on SUB_COMMANDS - end - - options[:cmd]= ARGV.shift - options[:files] = expand_argv_globs - - Trollop.die "argument --profile is required" unless options[:profile] - Trollop.die "argument --repo-type is required" unless options[:repo_type] - Trollop.die "profile does not exist: #{options[:profile]}" unless File.exist?(options[:profile]) - Trollop.die "invalid repository type: #{options[:repo_type]}" unless REPOSITORY_TYPES[options[:repo_type]] - - options - end - - def self.expand_argv_globs - files = [] - - ARGV.each do |glob| - files += Dir.glob(glob) - end - - files - end + MIME::Types.add(type) end end + +require 'right_publish/profile' +require 'right_publish/annotation' +require 'right_publish/repo' +require 'right_publish/cli'