onlyoffice_file_helper 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8892729d9e6ca56eea08980111b5ddf0814efd6d
4
- data.tar.gz: 9344277924e570c6cf2e4338b4bd077aa0e60fb8
2
+ SHA256:
3
+ metadata.gz: 7754ee429ce8e9954dd7c3343650bb29564dd44f762cd35c1de5b922773a2e47
4
+ data.tar.gz: 832ae50c2ea5275ef193887e88611626c7c7f365c90536711f6db3df8b1c6938
5
5
  SHA512:
6
- metadata.gz: 5dfbd4993305883658685286e98cb577189cb8612c004499b2b3ccbc9b6309cf68e462bae0cab8a25a8872c5ffc4399d6c98a1239db5fbc862ad2957a9ab84d6
7
- data.tar.gz: b78b2462ce773f0ad903ba777ef1731b4b1b5d241b69c8496a31bb04b2b2d630703914b1426f953d333681592f4ffb208c182b8b1d76ed4be7ce4d611fcf1b78
6
+ metadata.gz: 295ec48c909d4c48081f62b99d6631ae206926ef6a10a08b725ae3de3ea58e50740e260cb6e9ac9c2a4993bc0d0dbfc6dace4075f13ffc249115635c4f652a3f
7
+ data.tar.gz: fce67d533563eaba672b4346f41a779fee4861e6372d752964052f6e2c105a2151dfd4fa97918d89a6321b2d5296a4f1a48c33821015aa63055e86f14de88889
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeFileHelper
4
+ # Methods used to create something
5
+ module CreateMethods
6
+ def create_folder(path)
7
+ FileUtils.mkdir_p(path) unless File.directory?(path)
8
+ rescue Errno::EEXIST
9
+ true
10
+ end
11
+
12
+ # Create file with content
13
+ # @param file_path [String] path to created file
14
+ # @param [String] content content of file
15
+ # @return [String] path to created file
16
+ def create_file_with_content(file_path: '/tmp/temp_file.ext', content: '')
17
+ File.open(file_path, 'w') { |f| f.write(content) }
18
+ OnlyofficeLoggerHelper.log("Created file: #{file_path} with content: #{content}")
19
+ file_path
20
+ end
21
+
22
+ # Create empty file with size
23
+ # @param file_path [String] path to created file
24
+ # @param size [String] file size, may use binary indexes lik '256M', '15G'
25
+ # @return [String] path to created file
26
+ def create_file_with_size(file_path: '/tmp/temp_file.ext', size: '1G')
27
+ `fallocate -l #{size} #{file_path}`
28
+ file_path
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeFileHelper
4
+ # Methods used to work with directories
5
+ module DirectoryMethods
6
+ def delete_directory(path)
7
+ FileUtils.rm_rf(path) if Dir.exist?(path)
8
+ end
9
+
10
+ def directory_hash(path)
11
+ files = []
12
+ Dir.foreach(path).sort.each do |entry|
13
+ next if %w[.. .].include?(entry)
14
+
15
+ full_path = File.join(path, entry)
16
+ files = root_dir_hash(files, full_path)
17
+ end
18
+ files.keep_if { |current| current.end_with?('_spec.rb') }
19
+ files
20
+ end
21
+
22
+ def list_file_in_directory(directory, extension = nil)
23
+ paths = []
24
+ Find.find(directory) do |path|
25
+ next if FileTest.directory?(path)
26
+
27
+ paths << path if extension.nil? || File.extname(path) == ".#{extension}"
28
+ end
29
+ paths
30
+ rescue Errno::ENOENT
31
+ []
32
+ end
33
+
34
+ private
35
+
36
+ def root_dir_hash(files, path)
37
+ if File.directory?(path)
38
+ files += directory_hash(path)
39
+ else
40
+ files << path
41
+ end
42
+ files
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OnlyofficeFileHelper
2
4
  # Class for working with Xdotool
3
5
  # Performs actions with x-system
@@ -8,14 +10,6 @@ module OnlyofficeFileHelper
8
10
  `xdotool search '#{window_title}'`.to_i
9
11
  end
10
12
 
11
- # Close any window by it's title
12
- # @param window_title [String] title of window to close
13
- # @return [Nothing]
14
- def close_x_window(window_title)
15
- window_id = find_window_id(window_title)
16
- `xdotool windowkill #{window_id}`
17
- end
18
-
19
13
  # Send button to specific window
20
14
  # @param window_title [String] title of window to close
21
15
  # @param button [String] button to send
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'socket'
2
4
  require_relative 'linux_helper/xdotool_helper'
3
5
 
@@ -11,7 +13,7 @@ module OnlyofficeFileHelper
11
13
  end
12
14
 
13
15
  def self.kill_all(process)
14
- LoggerHelper.print_to_log("killall -9 #{process} 2>&1")
16
+ OnlyofficeLoggerHelper.log("killall -9 #{process} 2>&1")
15
17
  `killall -9 #{process} 2>&1`
16
18
  end
17
19
 
@@ -21,27 +23,26 @@ module OnlyofficeFileHelper
21
23
  kill_all('opera')
22
24
  end
23
25
 
24
- def self.get_user_name
26
+ def self.user_name
25
27
  `id -u -n`
26
28
  end
27
29
 
28
- def self.shared_folder
29
- '/mnt/data_share/'
30
- end
30
+ singleton_class.send(:alias_method, :get_user_name, :user_name)
31
31
 
32
- def self.get_computer_name(ip_to_run = nil)
33
- computer_name = if ip_to_run.nil?
34
- Socket.gethostname
35
- else
36
- ip_to_run
37
- end
32
+ def self.computer_name
33
+ computer_name = Socket.gethostname
34
+ OnlyofficeLoggerHelper.log("`LinuxHelper.get_computer_name` # #{computer_name}")
38
35
  computer_name
39
36
  end
40
37
 
41
- def self.get_clipboard
38
+ singleton_class.send(:alias_method, :get_computer_name, :computer_name)
39
+
40
+ def self.clipboard_content
42
41
  `xclip -o`
43
42
  end
44
43
 
44
+ singleton_class.send(:alias_method, :get_clipboard, :clipboard_content)
45
+
45
46
  # Get user dirs specified by `xdg-user-dir`
46
47
  # @param name [Symbol, String] name of user dir
47
48
  # @return [String] path to dir
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeFileHelper
4
+ # Methods used to read something
5
+ module ReadMethods
6
+ def read_file_to_string(file_name)
7
+ result_string = ''
8
+ raise 'File not found: ' + file_name.to_s unless File.exist?(file_name)
9
+
10
+ File.open(file_name, 'r') do |infile|
11
+ while (line = infile.gets)
12
+ result_string += line
13
+ end
14
+ end
15
+ result_string
16
+ end
17
+
18
+ def read_array_from_file(file_name)
19
+ result_array = []
20
+ return [] unless File.exist?(file_name)
21
+
22
+ File.open(file_name, 'r') do |infile|
23
+ while (line = infile.gets)
24
+ result_array << line.sub("\n", '')
25
+ end
26
+ end
27
+ result_array
28
+ end
29
+
30
+ # Get line count in file
31
+ # @param file_name [String] name of file
32
+ # @param line_number [Fixnum] line of file to get
33
+ # @return [String] line of file by number
34
+ def read_specific_line(file_name, line_number)
35
+ line = `sed '#{line_number + 1}!d' #{file_name}`
36
+ line.chop! if line[-1] == "\n"
37
+ OnlyofficeLoggerHelper.log("Lines in '#{file_name}' by number is '#{line}'")
38
+ line
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OnlyofficeFileHelper
2
4
  # Helper for Strings
3
5
  class StringHelper
@@ -6,10 +8,6 @@ module OnlyofficeFileHelper
6
8
  (0...length_string).map { (('a'..'z').to_a + ('A'..'Z').to_a)[rand(52)] }.join
7
9
  end
8
10
 
9
- def generate_array_random_string(array_length = 10, string_length = 32)
10
- (1..array_length).map { generate_random_string(string_length) }
11
- end
12
-
13
11
  def generate_random_number(value = nil)
14
12
  "#{value}: #{Time.now.nsec}"
15
13
  end
@@ -23,15 +21,10 @@ module OnlyofficeFileHelper
23
21
  if first_element.is_a?(Float) && second_element.is_a?(Float)
24
22
  difference = (first_element - second_element).abs
25
23
  difference >= accuracy ? "Difference between parameters in #{compare_parameter} is #{difference}" : ''
24
+ elsif first_element.to_s == second_element.to_s
25
+ ''
26
26
  else
27
- first_element ||= 0
28
- second_element ||= 0
29
-
30
- if first_element.to_s == second_element.to_s
31
- ''
32
- else
33
- "Difference in #{compare_parameter}. From case: #{first_element}. From result: #{second_element}"
34
- end
27
+ "Difference in #{compare_parameter}. From case: #{first_element}. From result: #{second_element}"
35
28
  end
36
29
  end
37
30
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OnlyofficeFileHelper
2
- VERSION = '0.1.0'.freeze
4
+ VERSION = '0.2.0'
3
5
  end
@@ -1,8 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'csv'
2
4
  require 'zip'
3
5
  require 'open-uri'
4
6
  require 'onlyoffice_logger_helper'
5
7
  require 'find'
8
+ require 'onlyoffice_file_helper/create_methods'
9
+ require 'onlyoffice_file_helper/directory_methods'
10
+ require 'onlyoffice_file_helper/read_methods'
6
11
  require 'onlyoffice_file_helper/version'
7
12
  require 'onlyoffice_file_helper/linux_helper'
8
13
  require 'onlyoffice_file_helper/string_helper'
@@ -10,6 +15,10 @@ require 'onlyoffice_file_helper/string_helper'
10
15
  module OnlyofficeFileHelper
11
16
  # Stuff for working with Files
12
17
  class FileHelper
18
+ extend CreateMethods
19
+ extend DirectoryMethods
20
+ extend ReadMethods
21
+
13
22
  class << self
14
23
  # Return name of file from full path
15
24
  # @param [true, false] keep_extension keep extension in result?
@@ -20,16 +29,6 @@ module OnlyofficeFileHelper
20
29
  name.to_s
21
30
  end
22
31
 
23
- def delete_directory(path)
24
- FileUtils.rm_rf(path) if Dir.exist?(path)
25
- end
26
-
27
- def create_folder(path)
28
- FileUtils.mkdir_p(path) unless File.directory?(path)
29
- rescue Errno::EEXIST
30
- true
31
- end
32
-
33
32
  def wait_file_to_download(path, timeout = 300)
34
33
  timer = 0
35
34
  OnlyofficeLoggerHelper.log("Start waiting to download file: #{path}")
@@ -37,49 +36,22 @@ module OnlyofficeFileHelper
37
36
  OnlyofficeLoggerHelper.log("Waiting for #{timer} seconds from #{timeout}")
38
37
  sleep 1
39
38
  timer += 1
40
- if timer > timeout
41
- raise "Timeout #{timeout} for downloading file #{path} is exceed"
42
- end
39
+ raise "Timeout #{timeout} for downloading file #{path} is exceed" if timer > timeout
43
40
  end
44
41
  sleep 1
45
42
  timer <= timeout
46
43
  end
47
44
 
48
- def read_file_to_string(file_name)
49
- result_string = ''
50
- raise 'File not found: ' + file_name.to_s unless File.exist?(file_name)
51
- File.open(file_name, 'r') do |infile|
52
- while (line = infile.gets)
53
- result_string += line
54
- end
55
- end
56
- result_string
57
- end
58
-
59
- def read_array_from_file(file_name)
60
- result_array = []
61
- return [] unless File.exist?(file_name)
62
- File.open(file_name, 'r') do |infile|
63
- while (line = infile.gets)
64
- result_array << line.sub("\n", '')
65
- end
66
- end
67
- result_array
68
- end
69
-
70
45
  def extract_to_folder(path_to_archive,
71
46
  path_to_extract = path_to_archive.chomp(File.basename(path_to_archive)))
72
47
  raise 'File not found: ' + path_to_archive.to_s unless wait_file_to_download(path_to_archive)
48
+
73
49
  path_to_extract += '/' unless path_to_extract[-1] == '/'
74
50
  path_to_file = path_to_extract + File.basename(path_to_archive)
75
- # unless File.exist?(path_to_file)
76
- # FileUtils.cp path_to_archive, path_to_extract
77
- # end
78
51
  Zip::File.open(path_to_file) do |zip_file|
79
52
  zip_file.each do |file|
80
53
  file_path = File.join(path_to_extract, file.name)
81
- a = File.dirname(file_path)
82
- create_folder(a)
54
+ create_folder(File.dirname(file_path))
83
55
  zip_file.extract(file, file_path)
84
56
  end
85
57
  end
@@ -91,62 +63,6 @@ module OnlyofficeFileHelper
91
63
  end
92
64
  end
93
65
 
94
- def copy_file(file_path, destination)
95
- FileUtils.mkdir_p(destination) unless File.directory?(destination)
96
- FileUtils.copy(file_path, destination)
97
- end
98
-
99
- def directory_hash(path)
100
- files = []
101
- Dir.foreach(path).sort.each do |entry|
102
- next if %w[.. .].include?(entry)
103
- full_path = File.join(path, entry)
104
- if File.directory?(full_path)
105
- files += directory_hash(full_path)
106
- else
107
- files << File.join(path, entry)
108
- end
109
- end
110
- files.keep_if do |current|
111
- current.end_with?('_spec.rb')
112
- end
113
- files
114
- end
115
-
116
- def list_file_in_directory(directory, extension = nil)
117
- paths = []
118
- Find.find(directory) do |path|
119
- next if FileTest.directory?(path)
120
- if extension.nil?
121
- paths << path
122
- elsif File.extname(path) == ".#{extension}"
123
- paths << path
124
- end
125
- end
126
- paths
127
- rescue Errno::ENOENT
128
- []
129
- end
130
-
131
- # Create file with content
132
- # @param file_path [String] path to created file
133
- # @param [String] content content of file
134
- # @return [String] path to created file
135
- def create_file_with_content(file_path: '/tmp/temp_file.ext', content: '')
136
- File.open(file_path, 'w') { |f| f.write(content) }
137
- OnlyofficeLoggerHelper.log("Created file: #{file_path} with content: #{content}")
138
- file_path
139
- end
140
-
141
- # Create empty file with size
142
- # @param file_path [String] path to created file
143
- # @param size [String] file size, may use binary indexes lik '256M', '15G'
144
- # @return [String] path to created file
145
- def create_file_with_size(file_path: '/tmp/temp_file.ext', size: '1G')
146
- `fallocate -l #{size} #{file_path}`
147
- file_path
148
- end
149
-
150
66
  # Get line count in file
151
67
  # @param file_name [String] name of file
152
68
  # @return [Fixnum] count of lines in file
@@ -155,17 +71,6 @@ module OnlyofficeFileHelper
155
71
  OnlyofficeLoggerHelper.log("Count of lines in '#{file_name}' is #{line_count}")
156
72
  line_count
157
73
  end
158
-
159
- # Get line count in file
160
- # @param file_name [String] name of file
161
- # @param line_number [Fixnum] line of file to get
162
- # @return [String] line of file by number
163
- def read_specific_line(file_name, line_number)
164
- line = `sed '#{line_number + 1}!d' #{file_name}`
165
- line.chop! if line[-1] == "\n"
166
- OnlyofficeLoggerHelper.log("Lines in '#{file_name}' by number is '#{line}'")
167
- line
168
- end
169
74
  end
170
75
  end
171
76
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onlyoffice_file_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ONLYOFFICE
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-10-11 00:00:00.000000000 Z
12
+ date: 2020-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: onlyoffice_logger_helper
@@ -29,16 +29,22 @@ dependencies:
29
29
  name: rubyzip
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '1'
35
+ - - "<"
33
36
  - !ruby/object:Gem::Version
34
- version: '1.0'
37
+ version: '3'
35
38
  type: :runtime
36
39
  prerelease: false
37
40
  version_requirements: !ruby/object:Gem::Requirement
38
41
  requirements:
39
- - - "~>"
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '1'
45
+ - - "<"
40
46
  - !ruby/object:Gem::Version
41
- version: '1.0'
47
+ version: '3'
42
48
  description: ONLYOFFICE Helper Gem for File operation. Used in QA
43
49
  email:
44
50
  - shockwavenn@gmail.com
@@ -48,8 +54,11 @@ extra_rdoc_files: []
48
54
  files:
49
55
  - README.md
50
56
  - lib/onlyoffice_file_helper.rb
57
+ - lib/onlyoffice_file_helper/create_methods.rb
58
+ - lib/onlyoffice_file_helper/directory_methods.rb
51
59
  - lib/onlyoffice_file_helper/linux_helper.rb
52
60
  - lib/onlyoffice_file_helper/linux_helper/xdotool_helper.rb
61
+ - lib/onlyoffice_file_helper/read_methods.rb
53
62
  - lib/onlyoffice_file_helper/string_helper.rb
54
63
  - lib/onlyoffice_file_helper/version.rb
55
64
  homepage: https://github.com/onlyoffice-testing-robot/onlyoffice_file_helper
@@ -71,8 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
80
  - !ruby/object:Gem::Version
72
81
  version: '0'
73
82
  requirements: []
74
- rubyforge_project:
75
- rubygems_version: 2.6.13
83
+ rubygems_version: 3.0.6
76
84
  signing_key:
77
85
  specification_version: 4
78
86
  summary: ONLYOFFICE Helper Gem for File operation