Class: Webdrivers::System Private

Inherits:
Object
  • Object
show all
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

Class Method Details

.bitsizeObject

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.



144
145
146
# File 'lib/webdrivers/system.rb', line 144

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.



32
33
34
35
36
37
38
# File 'lib/webdrivers/system.rb', line 32

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.



40
41
42
# File 'lib/webdrivers/system.rb', line 40

def cached_version(file_name)
  File.open("#{install_dir}/#{file_name.gsub('.exe', '')}.version", 'r', &:read)
end

.call(cmd) ⇒ 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.



148
149
150
151
# File 'lib/webdrivers/system.rb', line 148

def call(cmd)
  Webdrivers.logger.debug "making System call: #{cmd}"
  `#{cmd}`
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.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/webdrivers/system.rb', line 84

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)
  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.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/webdrivers/system.rb', line 12

def delete(file)
  max_attempts = 3
  attempts_made = 0
  delay = 0.5
  Webdrivers.logger.debug "Deleting #{file}"

  begin
    attempts_made += 1
    File.delete file if File.exist? file
  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.



51
52
53
54
55
56
57
58
59
# File 'lib/webdrivers/system.rb', line 51

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.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/webdrivers/system.rb', line 61

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.

Returns:

  • (Boolean)


78
79
80
81
82
# File 'lib/webdrivers/system.rb', line 78

def exists?(file)
  result = File.exist? file
  Webdrivers.logger.debug "#{file} is#{' not' unless result} already downloaded"
  result
end

.install_dirObject

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.



28
29
30
# File 'lib/webdrivers/system.rb', line 28

def install_dir
  Webdrivers.install_dir
end

.platformObject

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.



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/webdrivers/system.rb', line 132

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

.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.



100
101
102
103
104
# File 'lib/webdrivers/system.rb', line 100

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.



106
107
108
109
110
111
112
113
114
115
# File 'lib/webdrivers/system.rb', line 106

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) ⇒ 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.



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/webdrivers/system.rb', line 117

def unzip_file(filename)
  Webdrivers.logger.debug "Decompressing #{filename}"

  Zip::File.open(filename) do |zip_file|
    zip_file.each do |f|
      @top_path ||= f.name
      f_path = File.join(Dir.pwd, f.name)
      delete(f_path)
      FileUtils.mkdir_p(File.dirname(f_path)) unless File.exist?(File.dirname(f_path))
      zip_file.extract(f, f_path)
    end
  end
  @top_path
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.

Returns:

  • (Boolean)


44
45
46
47
48
49
# File 'lib/webdrivers/system.rb', line 44

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