onlyoffice_file_helper 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8892729d9e6ca56eea08980111b5ddf0814efd6d
4
+ data.tar.gz: 9344277924e570c6cf2e4338b4bd077aa0e60fb8
5
+ SHA512:
6
+ metadata.gz: 5dfbd4993305883658685286e98cb577189cb8612c004499b2b3ccbc9b6309cf68e462bae0cab8a25a8872c5ffc4399d6c98a1239db5fbc862ad2957a9ab84d6
7
+ data.tar.gz: b78b2462ce773f0ad903ba777ef1731b4b1b5d241b69c8496a31bb04b2b2d630703914b1426f953d333681592f4ffb208c182b8b1d76ed4be7ce4d611fcf1b78
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # OnlyofficeFileHelper
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/onlyoffice_file_helper`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'onlyoffice_file_helper'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install onlyoffice_file_helper
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/onlyoffice_file_helper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the OnlyofficeFileHelper project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/onlyoffice_file_helper/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,28 @@
1
+ module OnlyofficeFileHelper
2
+ # Class for working with Xdotool
3
+ # Performs actions with x-system
4
+ module XdotoolHelper
5
+ # Get window id by it's title
6
+ # @return [Fixnum] id of window
7
+ def find_window_id(window_title)
8
+ `xdotool search '#{window_title}'`.to_i
9
+ end
10
+
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
+ # Send button to specific window
20
+ # @param window_title [String] title of window to close
21
+ # @param button [String] button to send
22
+ # @return [Nothing]
23
+ def send_button_to_window(window_title, button)
24
+ window_id = find_window_id(window_title)
25
+ `xdotool key --window #{window_id} #{button}`
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,56 @@
1
+ require 'socket'
2
+ require_relative 'linux_helper/xdotool_helper'
3
+
4
+ module OnlyofficeFileHelper
5
+ # class for using Linux stuff
6
+ class LinuxHelper
7
+ extend XdotoolHelper
8
+
9
+ def self.download_file(link, full_name_file)
10
+ `wget -O #{full_name_file} #{link}`
11
+ end
12
+
13
+ def self.kill_all(process)
14
+ LoggerHelper.print_to_log("killall -9 #{process} 2>&1")
15
+ `killall -9 #{process} 2>&1`
16
+ end
17
+
18
+ def self.kill_all_browsers
19
+ kill_all('firefox')
20
+ kill_all('chrome')
21
+ kill_all('opera')
22
+ end
23
+
24
+ def self.get_user_name
25
+ `id -u -n`
26
+ end
27
+
28
+ def self.shared_folder
29
+ '/mnt/data_share/'
30
+ end
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
38
+ computer_name
39
+ end
40
+
41
+ def self.get_clipboard
42
+ `xclip -o`
43
+ end
44
+
45
+ # Get user dirs specified by `xdg-user-dir`
46
+ # @param name [Symbol, String] name of user dir
47
+ # @return [String] path to dir
48
+ def self.user_dir(name)
49
+ `xdg-user-dir #{name.to_s.upcase}`.strip
50
+ end
51
+
52
+ def self.my_external_ip
53
+ `curl "http://myexternalip.com/raw"`.chomp
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,48 @@
1
+ module OnlyofficeFileHelper
2
+ # Helper for Strings
3
+ class StringHelper
4
+ class << self
5
+ def generate_random_string(length_string = 32)
6
+ (0...length_string).map { (('a'..'z').to_a + ('A'..'Z').to_a)[rand(52)] }.join
7
+ end
8
+
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
+ def generate_random_number(value = nil)
14
+ "#{value}: #{Time.now.nsec}"
15
+ end
16
+
17
+ # Return 'Result' String of comparison of two strings
18
+ # @param [String] compare_parameter name of parameter
19
+ # @param [String] first_element 1'st element to compare
20
+ # @param [String] second_element 2'st element to compare
21
+ # @return [String] String with result of comparison
22
+ def get_result_string_of_comparison(compare_parameter, first_element, second_element, accuracy = 0.01)
23
+ if first_element.is_a?(Float) && second_element.is_a?(Float)
24
+ difference = (first_element - second_element).abs
25
+ difference >= accuracy ? "Difference between parameters in #{compare_parameter} is #{difference}" : ''
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
35
+ end
36
+ end
37
+
38
+ def to_bool(string)
39
+ str = string.to_s
40
+ if str.casecmp('false').zero?
41
+ false
42
+ elsif str.casecmp('true').zero?
43
+ true
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module OnlyofficeFileHelper
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,171 @@
1
+ require 'csv'
2
+ require 'zip'
3
+ require 'open-uri'
4
+ require 'onlyoffice_logger_helper'
5
+ require 'find'
6
+ require 'onlyoffice_file_helper/version'
7
+ require 'onlyoffice_file_helper/linux_helper'
8
+ require 'onlyoffice_file_helper/string_helper'
9
+
10
+ module OnlyofficeFileHelper
11
+ # Stuff for working with Files
12
+ class FileHelper
13
+ class << self
14
+ # Return name of file from full path
15
+ # @param [true, false] keep_extension keep extension in result?
16
+ # @return [Sting] name of file, with extension or not
17
+ def get_filename(file_path, keep_extension = true)
18
+ name = Pathname.new(file_path).basename
19
+ name = File.basename(name, File.extname(name)) unless keep_extension
20
+ name.to_s
21
+ end
22
+
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
+ def wait_file_to_download(path, timeout = 300)
34
+ timer = 0
35
+ OnlyofficeLoggerHelper.log("Start waiting to download file: #{path}")
36
+ until File.exist?(path) && !File.exist?(path + '.part')
37
+ OnlyofficeLoggerHelper.log("Waiting for #{timer} seconds from #{timeout}")
38
+ sleep 1
39
+ timer += 1
40
+ if timer > timeout
41
+ raise "Timeout #{timeout} for downloading file #{path} is exceed"
42
+ end
43
+ end
44
+ sleep 1
45
+ timer <= timeout
46
+ end
47
+
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
+ def extract_to_folder(path_to_archive,
71
+ path_to_extract = path_to_archive.chomp(File.basename(path_to_archive)))
72
+ raise 'File not found: ' + path_to_archive.to_s unless wait_file_to_download(path_to_archive)
73
+ path_to_extract += '/' unless path_to_extract[-1] == '/'
74
+ 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
+ Zip::File.open(path_to_file) do |zip_file|
79
+ zip_file.each do |file|
80
+ file_path = File.join(path_to_extract, file.name)
81
+ a = File.dirname(file_path)
82
+ create_folder(a)
83
+ zip_file.extract(file, file_path)
84
+ end
85
+ end
86
+ end
87
+
88
+ def output_string_to_file(string, file_name)
89
+ File.open(file_name, 'a+') do |f1|
90
+ f1.write(string)
91
+ end
92
+ end
93
+
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
+ # Get line count in file
151
+ # @param file_name [String] name of file
152
+ # @return [Fixnum] count of lines in file
153
+ def file_line_count(file_name)
154
+ line_count = `wc -l < #{file_name}`.to_i
155
+ OnlyofficeLoggerHelper.log("Count of lines in '#{file_name}' is #{line_count}")
156
+ line_count
157
+ 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
+ end
170
+ end
171
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: onlyoffice_file_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ONLYOFFICE
8
+ - Pavel Lobashov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-10-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: onlyoffice_logger_helper
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rubyzip
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.0'
42
+ description: ONLYOFFICE Helper Gem for File operation. Used in QA
43
+ email:
44
+ - shockwavenn@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - README.md
50
+ - lib/onlyoffice_file_helper.rb
51
+ - lib/onlyoffice_file_helper/linux_helper.rb
52
+ - lib/onlyoffice_file_helper/linux_helper/xdotool_helper.rb
53
+ - lib/onlyoffice_file_helper/string_helper.rb
54
+ - lib/onlyoffice_file_helper/version.rb
55
+ homepage: https://github.com/onlyoffice-testing-robot/onlyoffice_file_helper
56
+ licenses:
57
+ - AGPL-3.0
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.6.13
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: ONLYOFFICE Helper Gem for File operation
79
+ test_files: []