Class: Webdrivers::System Private
- Inherits:
-
Object
- Object
- Webdrivers::System
- Defined in:
- lib/webdrivers/system.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Class Method Summary collapse
- .bitsize ⇒ Object private
- .cache_version(file_name, version) ⇒ Object private
- .cached_version(file_name) ⇒ Object private
- .call(process, arg = nil) ⇒ Object private
- .decompress_file(tempfile, file_name, target) ⇒ Object private
- .delete(file) ⇒ Object private
- .download(url, target) ⇒ Object private
- .download_file(url, target) ⇒ Object private
- .exists?(file) ⇒ Boolean private
- .install_dir ⇒ Object private
- .platform ⇒ Object private
- .to_win32_path(path) ⇒ String private
- .to_wsl_path(path) ⇒ String private
- .untarbz2_file(filename) ⇒ Object private
- .untargz_file(source, target) ⇒ Object private
- .unzip_file(filename, driver_name) ⇒ Object private
- .valid_cache?(file_name) ⇒ Boolean private
- .wsl? ⇒ TrueClass, FalseClass private
Class Method Details
.bitsize ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
170 171 172 |
# File 'lib/webdrivers/system.rb', line 170 def bitsize Selenium::WebDriver::Platform.bitsize end |
.cache_version(file_name, version) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 44 45 46 47 |
# File 'lib/webdrivers/system.rb', line 41 def cache_version(file_name, version) FileUtils.mkdir_p(install_dir) unless File.exist?(install_dir) File.open("#{install_dir}/#{file_name.gsub('.exe', '')}.version", 'w+') do |file| file.print(version) end end |
.cached_version(file_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 |
# File 'lib/webdrivers/system.rb', line 49 def cached_version(file_name) File.open("#{install_dir}/#{file_name.gsub('.exe', '')}.version", 'r', &:read) end |
.call(process, arg = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/webdrivers/system.rb', line 174 def call(process, arg = nil) cmd = arg ? [process, arg] : process # Windows provides powershell command (process) only, no args. Webdrivers.logger.debug "making System call: #{cmd}" p = IO.popen(cmd) out = p.read p.close raise "Failed to make system call: #{cmd}" unless $CHILD_STATUS.success? Webdrivers.logger.debug "System call returned: #{out}" out end |
.decompress_file(tempfile, file_name, target) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/webdrivers/system.rb', line 93 def decompress_file(tempfile, file_name, target) tempfile = tempfile.to_path case tempfile when /tar\.gz$/ untargz_file(tempfile, File.basename(target)) when /tar\.bz2$/ untarbz2_file(tempfile) when /\.zip$/ unzip_file(tempfile, File.basename(target)) else Webdrivers.logger.debug 'No Decompression needed' FileUtils.cp(tempfile, File.join(Dir.pwd, file_name)) end raise "Could not decompress #{file_name} to get #{target}" unless File.exist?(File.basename(target)) end |
.delete(file) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/webdrivers/system.rb', line 19 def delete(file) max_attempts = 3 attempts_made = 0 delay = 0.5 begin attempts_made += 1 if File.exist? file Webdrivers.logger.debug "Deleting #{file}" File.delete file end rescue Errno::EACCES # Solves an intermittent file locking issue on Windows sleep(delay) retry if File.exist?(file) && attempts_made <= max_attempts raise end end |
.download(url, target) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 63 64 65 66 67 68 |
# File 'lib/webdrivers/system.rb', line 60 def download(url, target) FileUtils.mkdir_p(install_dir) unless File.exist?(install_dir) download_file(url, target) FileUtils.chmod 'ugo+rx', target Webdrivers.logger.debug "Completed download and processing of #{target}" target end |
.download_file(url, target) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/webdrivers/system.rb', line 70 def download_file(url, target) file_name = File.basename(url) Dir.chdir(install_dir) do tempfile = Tempfile.open(['', file_name], binmode: true) do |file| file.print Network.get(url) file end raise "Could not download #{url}" unless File.exist?(tempfile.to_path) Webdrivers.logger.debug "Successfully downloaded #{tempfile.to_path}" decompress_file(tempfile, file_name, target) tempfile.close! end end |
.exists?(file) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
87 88 89 90 91 |
# File 'lib/webdrivers/system.rb', line 87 def exists?(file) result = File.exist? file Webdrivers.logger.debug "#{file} is#{' not' unless result} already downloaded" result end |
.install_dir ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 |
# File 'lib/webdrivers/system.rb', line 37 def install_dir Webdrivers.install_dir end |
.platform ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/webdrivers/system.rb', line 139 def platform if Selenium::WebDriver::Platform.linux? 'linux' elsif Selenium::WebDriver::Platform.mac? 'mac' elsif Selenium::WebDriver::Platform.windows? 'win' else raise NotImplementedError, 'Your OS is not supported by webdrivers gem.' end end |
.to_win32_path(path) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
158 159 160 161 162 |
# File 'lib/webdrivers/system.rb', line 158 def to_win32_path(path) return path if /[a-z]:\\/iu.match?(path) call("wslpath -w '#{path}'").chomp end |
.to_wsl_path(path) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
166 167 168 |
# File 'lib/webdrivers/system.rb', line 166 def to_wsl_path(path) call("wslpath -u '#{path}'").chomp end |
.untarbz2_file(filename) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
109 110 111 112 113 |
# File 'lib/webdrivers/system.rb', line 109 def untarbz2_file(filename) Webdrivers.logger.debug "Decompressing #{filename}" call("tar xjf #{filename}").gsub('.tar.bz2', '') end |
.untargz_file(source, target) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/webdrivers/system.rb', line 115 def untargz_file(source, target) Webdrivers.logger.debug "Decompressing #{source}" tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(source)) File.open(target, 'w+b') do |ucf| tar_extract.each { |entry| ucf << entry.read } File.basename ucf end end |
.unzip_file(filename, driver_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/webdrivers/system.rb', line 126 def unzip_file(filename, driver_name) Webdrivers.logger.debug "Decompressing #{filename}" Zip::File.open(filename) do |zip_file| driver = zip_file.get_entry(driver_name) f_path = File.join(Dir.pwd, driver.name) delete(f_path) FileUtils.mkdir_p(File.dirname(f_path)) unless File.exist?(File.dirname(f_path)) zip_file.extract(driver, f_path) end driver_name end |
.valid_cache?(file_name) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 56 57 58 |
# File 'lib/webdrivers/system.rb', line 53 def valid_cache?(file_name) file = "#{install_dir}/#{file_name.gsub('.exe', '')}.version" return false unless File.exist?(file) Time.now - File.mtime(file) < Webdrivers.cache_time end |
.wsl? ⇒ TrueClass, FalseClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
152 153 154 |
# File 'lib/webdrivers/system.rb', line 152 def wsl? platform == 'linux' && File.open('/proc/version').read.include?('Microsoft') end |