module AsProject ########################## # Custom Errors class ProjectError < StandardError; end class UsageError < ProjectError; end class BuildError < StandardError; end end RAND_CHARS = ['A','B','C','D','E','F','a','b','c','d','e','f'] def AsProject::windowize_cygwin_path2(name) expr = /\/cygdrive\/([a-z]|[A-Z])/ matched = name.match(expr) if(matched) prefix = matched.captures[0].upcase + ':' name.gsub!(expr, prefix) end name = name.split('/').join('\\') return name end def AsProject::unique_tmpdir(application='RubyApplication') rand_max = RAND_CHARS.size uniqueish_name = '' 24.times{ uniqueish_name << RAND_CHARS[rand(rand_max)] } tmp = AsProject.asproject_tmpdir app_tmp = File.join(tmp, application) if(!File.exists?(app_tmp)) Dir.mkdir(app_tmp) end tmp = File.expand_path(File.join(app_tmp, uniqueish_name)) if(File.exists?(tmp) && is_retry) raise ProjectError.new('AsProject.unique_tmpdir attempted to create a new dir over an existing dir') # else if(File.exists?(tmp)) # Try again once before failing, uniqueish names aren't too unique... # AsProject.unique_tmpdir(application, true) end Dir.mkdir(tmp) return tmp end def AsProject::asproject_tmpdir tmp = nil for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], ENV['USERPROFILE'], '/tmp'] if dir and File.directory?(dir) and File.writable?(dir) tmp = dir break end end if(tmp.nil?) raise ProjectError.new('AsProject was unable to find a valid temporary directory on this computer.') end # Has to actually CD to the dir, because # on os x, tmp == /tmp until you're in it, # then it's /private/tmp?! # TestCases are relying on this value to # Be identical when you retrieve it and # when you are 'in' it... start = Dir.pwd Dir.chdir(tmp) tmp = Dir.pwd Dir.chdir(start) return tmp end