require 'fileutils' # Extensions to time to allow comparisons # with an early time class. This was borrowed from Rake. # -- # TODO Ultimately this might be able to be replaced # by -Infinity (see Infinity class in development folder). #++ class Time require 'singleton' # EarlyTime is a fake timestamp that occurs _before_ # any other time value. class Earlier include Comparable include Singleton def <=>(other) -1 end def to_s "" end end EARLY = Earlier.instance alias_method :rake_original_time_compare, :<=> def <=>(other) if Earlier === other - other.<=>(self) else rake_original_time_compare(other) end end end # Reap module holds the TaskUtils. module Reap # Support module for task development. module TaskUtils # Useful for populating a class. # Maybe this should have a different name --perhaps # just use Facets #set_with. def initialize( data={} ) data.each do |k,v| send( "#{k}=", v ) if respond_to?("#{k}=") end end # OpenCascade interface to teh ProjectInfo file. def master @taskutils_master ||= ProjectInfo.instance.to_opencascade end # If +name+ is a hash this will split the name => preq parameter # into [name, preq], otherwise it just return +name+. # Teh hash is expected to have only one element. def preq_from_name( name ) if Hash === name #a = [name.keys, name.values].flatten return *(name.to_a.flatten) else name end end # Output and then shellout a command. Doesn't actually # shellout if $PRETEND is set. def sh( arg ) tell arg system arg unless $PRETEND end # Convenience method for puts. Using this instead of # puts may help beautify or redirect output in # future versions. def tell( statement ) puts statement end # Conveniene method to get simple console reply. def ask( question, answers=nil ) print "#{question}" print " [#{answers}] " if answers until inp = $stdin.gets[0,1] ; sleep 1 ; end ; puts inp end # Makes sure there is a setup.rb file in the # project directory. def provide_setup_rb( trunk='.' ) setup_rb_file = File.join( trunk, 'setup.rb' ) return true if File.exists?( setup_rb_file ) if dir = Gem.gempath('reap') src = File.join( dir, 'data', 'reap', 'setup.rb' ) else src = File.join( Config::CONFIG['datadir'], 'reap', 'setup.rb' ) end if File.exists?( src ) FileUtils.cp( src, trunk ) true end end end end