lib/fig/command.rb in fig-0.1.67 vs lib/fig/command.rb in fig-0.1.69

- old
+ new

@@ -1,6 +1,6 @@ -require 'rubygems' +require 'fileutils' require 'net/ftp' require 'set' require 'fig/at_exit' require 'fig/command/action' @@ -14,20 +14,22 @@ require 'fig/parser' require 'fig/repository' require 'fig/repository_error' require 'fig/runtime_environment' require 'fig/statement/configuration' +require 'fig/update_lock' require 'fig/user_input_error' require 'fig/working_directory_maintainer' module Fig; end # Main program class Fig::Command - def run_fig(argv) + def run_fig(argv, options = nil) begin - @options = Fig::Command::Options.new(argv) + @options = options || Fig::Command::Options.new() + @options.process_command_line(argv) rescue Fig::UserInputError => error $stderr.puts error.to_s # Logging isn't set up yet. return Fig::Command::Action::EXIT_FAILURE end @@ -65,11 +67,12 @@ context = ExecutionContext.new( @base_package, base_config(), @environment, @repository, - @operating_system + @operating_system, + @package_source_description ) actions.each do |action| @@ -82,29 +85,44 @@ end return Fig::Command::Action::EXIT_SUCCESS end - def run_with_exception_handling(argv) + def run_with_exception_handling(argv, options = nil) begin - return_code = run_fig(argv) - return return_code + return run_fig(argv, options) rescue Fig::URLAccessError => error urls = error.urls.join(', ') - $stderr.puts "Access to #{urls} in #{error.package}/#{error.version} not allowed." - return Fig::Command::Action::EXIT_FAILURE + $stderr.puts \ + "Access to #{urls} in #{error.package}/#{error.version} not allowed." rescue Fig::UserInputError => error log_error_message(error) - return Fig::Command::Action::EXIT_FAILURE end + + return Fig::Command::Action::EXIT_FAILURE end + def add_publish_listener(listener) + @publish_listeners << listener + + return + end + + def initialize() + @publish_listeners = [] + end + private ExecutionContext = Struct.new( - :base_package, :base_config, :environment, :repository, :operating_system + :base_package, + :base_config, + :environment, + :repository, + :operating_system, + :package_source_description ) def derive_remote_url() if remote_operation_necessary?() if ENV['FIG_REMOTE_URL'].nil? @@ -117,32 +135,48 @@ end def check_include_statements_versions?() return false if @options.suppress_warning_include_statement_missing_version? - suppressed_warnings = @configuration['suppress warnings'] + suppressed_warnings = @application_configuration['suppress warnings'] return true if not suppressed_warnings return ! suppressed_warnings.include?('include statement missing version') end def configure() + set_up_update_lock() set_up_application_configuration() Fig::Logging.initialize_post_configuration( - @options.log_config() || @configuration['log configuration'], + @options.log_config() || @application_configuration['log configuration'], @options.log_level() ) @operating_system = Fig::OperatingSystem.new(@options.login?) prepare_repository() prepare_environment() end + def set_up_update_lock() + return if not @options.update_packages + + update_lock_response = @options.update_lock_response + return if update_lock_response == :ignore + + @update_lock = Fig::UpdateLock.new(@options.home, update_lock_response) + + # *sigh* Ruby 1.8 doesn't support close_on_exec(), so we've got to ensure + # this stuff on our own. + Fig::AtExit.add { @update_lock.close } + + return + end + def set_up_application_configuration() - @configuration = Fig::FigRC.find( + @application_configuration = Fig::FigRC.find( @options.figrc(), derive_remote_url(), @options.login?, @options.home(), @options.no_figrc? @@ -153,12 +187,12 @@ def prepare_repository() @repository = Fig::Repository.new( @operating_system, @options.home(), - @configuration, - nil, # remote_user + @application_configuration, + @publish_listeners, check_include_statements_versions? ) case @options.update_packages when :unconditionally @@ -207,12 +241,13 @@ if @options.actions.all? {|action| action.base_package_can_come_from_descriptor?} @base_package = package_loader.load_package_object() else @base_package = package_loader.load_package_object_from_file() end + @package_source_description = package_loader.package_source_description() - applier = new_package_applier(package_loader.package_source_description()) + applier = new_package_applier() if retrieves_should_happen applier.activate_retrieves() end if register_base_package @@ -231,40 +266,40 @@ Fig::Package::DEFAULT_CONFIG end def new_package_loader() return Fig::Command::PackageLoader.new( - @configuration, + @application_configuration, @descriptor, @options.package_definition_file, base_config(), @repository ) end - def new_package_applier(package_source_description) + def new_package_applier() return Fig::Command::PackageApplier.new( @base_package, @environment, @options, @descriptor, base_config(), - package_source_description + @package_source_description ) end - # If the user has specified a descriptor, than any package.fig or --file - # option is ignored. Thus, in order to avoid confusing the user, we make - # specifying both an error. + # If the user has specified a descriptor and we are not publishing, than any + # package.fig or --file option is ignored. Thus, in order to avoid confusing + # the user, we make specifying both an error. def ensure_descriptor_and_file_were_not_both_specified() file = @options.package_definition_file() # If the user specified --no-file, even though it's kind of superfluous, # we'll let it slide because the user doesn't think that any file will be # processed. file_specified = ! file.nil? && file != :none - if @descriptor and file_specified + if @descriptor && file_specified raise Fig::UserInputError.new( %Q<Cannot specify both a package descriptor (#{@descriptor.original_string}) and the --file option (#{file}).> ) end