PageRenderTime 29ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/path/ruby/1.9.1/gems/selenium-webdriver-0.2.0/lib/selenium/webdriver/common/platform.rb

https://github.com/tronwarrior/chapter-admin
Ruby | 154 lines | 123 code | 29 blank | 2 comment | 15 complexity | 7fcd849a381481c0cd0a10b6d352697c MD5 | raw file
  1. require "rbconfig"
  2. require "socket"
  3. module Selenium
  4. module WebDriver
  5. # @api private
  6. module Platform
  7. module_function
  8. def home
  9. # jruby has an issue with ENV['HOME'] on Windows
  10. @home ||= jruby? ? ENV_JAVA['user.home'] : ENV['HOME']
  11. end
  12. def engine
  13. @engine ||= (
  14. if defined? RUBY_ENGINE
  15. RUBY_ENGINE.to_sym
  16. else
  17. :ruby
  18. end
  19. )
  20. end
  21. def os
  22. @os ||= (
  23. host_os = RbConfig::CONFIG['host_os']
  24. case host_os
  25. when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
  26. :windows
  27. when /darwin|mac os/
  28. :macosx
  29. when /linux/
  30. :linux
  31. when /solaris|bsd/
  32. :unix
  33. else
  34. raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
  35. end
  36. )
  37. end
  38. def bitsize
  39. @bitsize ||= (
  40. if defined?(FFI::BITSIZE)
  41. FFI::BITSIZE
  42. elsif defined?(FFI)
  43. FFI.type_size(:pointer) == 4 ? 32 : 64
  44. elsif jruby?
  45. Integer(ENV_JAVA['sun.arch.data.model'])
  46. else
  47. 1.size == 4 ? 32 : 64
  48. end
  49. )
  50. end
  51. def jruby?
  52. engine == :jruby
  53. end
  54. def ironruby?
  55. engine == :ironruby
  56. end
  57. def ruby187?
  58. !!(RUBY_VERSION =~ /^1\.8\.7/)
  59. end
  60. def ruby19?
  61. !!(RUBY_VERSION =~ /^1\.9/)
  62. end
  63. def win?
  64. os == :windows
  65. end
  66. def mac?
  67. os == :macosx
  68. end
  69. def linux?
  70. os == :linux
  71. end
  72. def cygwin?
  73. !!(RUBY_PLATFORM =~ /cygwin/)
  74. end
  75. def wrap_in_quotes_if_necessary(str)
  76. win? && !cygwin? ? %{"#{str}"} : str
  77. end
  78. def cygwin_path(path, opts = {})
  79. flags = []
  80. opts.each { |k,v| flags << "--#{k}" if v }
  81. `cygpath #{flags.join ' '} "#{path}"`.strip
  82. end
  83. def make_writable(file)
  84. File.chmod 0766, file
  85. end
  86. def assert_executable(path)
  87. unless File.file? path
  88. raise Error::WebDriverError, "not a file: #{path.inspect}"
  89. end
  90. unless File.executable? path
  91. raise Error::WebDriverError, "not executable: #{path.inspect}"
  92. end
  93. end
  94. def find_binary(*binary_names)
  95. paths = ENV['PATH'].split(File::PATH_SEPARATOR)
  96. binary_names.map! { |n| "#{n}.exe" } if win?
  97. binary_names.each do |binary_name|
  98. paths.each do |path|
  99. exe = File.join(path, binary_name)
  100. return exe if File.executable?(exe)
  101. end
  102. end
  103. nil
  104. end
  105. def localhost
  106. info = Socket.getaddrinfo "localhost", 80, Socket::AF_INET, Socket::SOCK_STREAM
  107. if info.empty?
  108. raise Error::WebDriverError, "unable to translate 'localhost' for TCP+IPv6"
  109. end
  110. info[0][3]
  111. end
  112. end # Platform
  113. end # WebDriver
  114. end # Selenium
  115. if __FILE__ == $0
  116. p :engine => Selenium::WebDriver::Platform.engine,
  117. :os => Selenium::WebDriver::Platform.os,
  118. :ruby187? => Selenium::WebDriver::Platform.ruby187?,
  119. :ruby19? => Selenium::WebDriver::Platform.ruby19?,
  120. :jruby? => Selenium::WebDriver::Platform.jruby?,
  121. :win? => Selenium::WebDriver::Platform.win?,
  122. :home => Selenium::WebDriver::Platform.home,
  123. :bitsize => Selenium::WebDriver::Platform.bitsize,
  124. :localhost => Selenium::WebDriver::Platform.localhost
  125. end