tools 0.0.1 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ require 'tools'
4
+ require 'thor'
5
+
6
+ Signal.trap("INT") {
7
+ puts "\n\tNote: You will typically use Signal.trap instead.\n".light_red
8
+ exit
9
+ }
10
+
11
+ Signal.trap("TERM") {
12
+ puts "\n\tNote: You will typically use Signal.trap instead.\n".light_red
13
+ exit
14
+ }
15
+
16
+ load Tools.files + '/requireds.rb'
17
+
18
+ class Tools_exec < Thor
19
+
20
+ desc 'help', ''
21
+ def help(command='')
22
+ puts "\tHELP will be here..... Coming soon....".light_green
23
+
24
+ end
25
+
26
+ desc 'show', ''
27
+ def show(command='')
28
+ puts "Gem_path.: #{Tools.gem_path}"
29
+ puts "Ldap_pass.: #{Tools.ldap_pass}"
30
+ puts "Ldap_user.: #{Tools.ldap_user}"
31
+ puts "User.: #{Tools.user}"
32
+ puts "Pwd.: #{Tools.pwd}"
33
+ puts "Host.: #{Tools.host}"
34
+ puts "Files: #{Tools.files}"
35
+ end
36
+
37
+ desc 'config', ''
38
+ def config
39
+ ap 'config'
40
+ # ToolsConfig.config
41
+ end
42
+
43
+
44
+ desc 'console', ''
45
+ def console
46
+ ap 'console'
47
+ #ToolsConsole.create_console
48
+ #ToolsConsole.run_console
49
+ end
50
+
51
+
52
+ def method_missing(method, *args, &block)
53
+
54
+ exit()
55
+ end
56
+
57
+ end
58
+
59
+ begin
60
+ Tools_exec.start(ARGV)
61
+ rescue SystemExit => e
62
+ puts "\tExiting tools gem... See you later...".light_green
63
+ exit(e.status)
64
+ rescue Exception => e
65
+ puts e
66
+ end
@@ -0,0 +1,207 @@
1
+ ---
2
+ pt-BR:
3
+ date:
4
+ abbr_day_names:
5
+ - Dom
6
+ - Seg
7
+ - Ter
8
+ - Qua
9
+ - Qui
10
+ - Sex
11
+ - Sáb
12
+ abbr_month_names:
13
+ -
14
+ - Jan
15
+ - Fev
16
+ - Mar
17
+ - Abr
18
+ - Mai
19
+ - Jun
20
+ - Jul
21
+ - Ago
22
+ - Set
23
+ - Out
24
+ - Nov
25
+ - Dez
26
+ day_names:
27
+ - Domingo
28
+ - Segunda-feira
29
+ - Terça-feira
30
+ - Quarta-feira
31
+ - Quinta-feira
32
+ - Sexta-feira
33
+ - Sábado
34
+ formats:
35
+ default: "%d/%m/%Y"
36
+ long: "%d de %B de %Y"
37
+ short: "%d de %B"
38
+ month_names:
39
+ -
40
+ - Janeiro
41
+ - Fevereiro
42
+ - Março
43
+ - Abril
44
+ - Maio
45
+ - Junho
46
+ - Julho
47
+ - Agosto
48
+ - Setembro
49
+ - Outubro
50
+ - Novembro
51
+ - Dezembro
52
+ order:
53
+ - :day
54
+ - :month
55
+ - :year
56
+ datetime:
57
+ distance_in_words:
58
+ about_x_hours:
59
+ one: aproximadamente 1 hora
60
+ other: aproximadamente %{count} horas
61
+ about_x_months:
62
+ one: aproximadamente 1 mês
63
+ other: aproximadamente %{count} meses
64
+ about_x_years:
65
+ one: aproximadamente 1 ano
66
+ other: aproximadamente %{count} anos
67
+ almost_x_years:
68
+ one: quase 1 ano
69
+ other: quase %{count} anos
70
+ half_a_minute: meio minuto
71
+ less_than_x_minutes:
72
+ one: menos de um minuto
73
+ other: menos de %{count} minutos
74
+ less_than_x_seconds:
75
+ one: menos de 1 segundo
76
+ other: menos de %{count} segundos
77
+ over_x_years:
78
+ one: mais de 1 ano
79
+ other: mais de %{count} anos
80
+ x_days:
81
+ one: 1 dia
82
+ other: "%{count} dias"
83
+ x_minutes:
84
+ one: 1 minuto
85
+ other: "%{count} minutos"
86
+ x_months:
87
+ one: 1 mês
88
+ other: "%{count} meses"
89
+ x_seconds:
90
+ one: 1 segundo
91
+ other: "%{count} segundos"
92
+ prompts:
93
+ day: Dia
94
+ hour: Hora
95
+ minute: Minuto
96
+ month: Mês
97
+ second: Segundo
98
+ year: Ano
99
+ errors:
100
+ format: "%{attribute} %{message}"
101
+ messages:
102
+ accepted: deve ser aceito
103
+ blank: não pode ficar em branco
104
+ present: deve ficar em branco
105
+ confirmation: não é igual a %{attribute}
106
+ empty: não pode ficar vazio
107
+ equal_to: deve ser igual a %{count}
108
+ even: deve ser par
109
+ exclusion: não está disponível
110
+ greater_than: deve ser maior que %{count}
111
+ greater_than_or_equal_to: deve ser maior ou igual a %{count}
112
+ inclusion: não está incluído na lista
113
+ invalid: não é válido
114
+ less_than: deve ser menor que %{count}
115
+ less_than_or_equal_to: deve ser menor ou igual a %{count}
116
+ not_a_number: não é um número
117
+ not_an_integer: não é um número inteiro
118
+ odd: deve ser ímpar
119
+ record_invalid: 'A validação falhou: %{errors}'
120
+ restrict_dependent_destroy:
121
+ one: Não é possível excluir o registro pois existe um %{record} dependente
122
+ many: Não é possível excluir o registro pois existem %{record} dependentes
123
+ taken: já está em uso
124
+ too_long: 'é muito longo (máximo: %{count} caracteres)'
125
+ too_short: 'é muito curto (mínimo: %{count} caracteres)'
126
+ wrong_length: não possui o tamanho esperado (%{count} caracteres)
127
+ other_than: deve ser diferente de %{count}
128
+ template:
129
+ body: 'Por favor, verifique o(s) seguinte(s) campo(s):'
130
+ header:
131
+ one: 'Não foi possível gravar %{model}: 1 erro'
132
+ other: 'Não foi possível gravar %{model}: %{count} erros.'
133
+ helpers:
134
+ select:
135
+ prompt: Por favor selecione
136
+ submit:
137
+ create: Criar %{model}
138
+ submit: Salvar %{model}
139
+ update: Atualizar %{model}
140
+ number:
141
+ currency:
142
+ format:
143
+ delimiter: "."
144
+ format: "%u %n"
145
+ precision: 2
146
+ separator: ","
147
+ significant: false
148
+ strip_insignificant_zeros: false
149
+ unit: R$
150
+ format:
151
+ delimiter: "."
152
+ precision: 3
153
+ separator: ","
154
+ significant: false
155
+ strip_insignificant_zeros: false
156
+ human:
157
+ decimal_units:
158
+ format: "%n %u"
159
+ units:
160
+ billion:
161
+ one: bilhão
162
+ other: bilhões
163
+ million:
164
+ one: milhão
165
+ other: milhões
166
+ quadrillion:
167
+ one: quatrilhão
168
+ other: quatrilhões
169
+ thousand: mil
170
+ trillion:
171
+ one: trilhão
172
+ other: trilhões
173
+ unit: ''
174
+ format:
175
+ delimiter: "."
176
+ precision: 2
177
+ significant: true
178
+ strip_insignificant_zeros: true
179
+ storage_units:
180
+ format: "%n %u"
181
+ units:
182
+ byte:
183
+ one: Byte
184
+ other: Bytes
185
+ gb: GB
186
+ kb: KB
187
+ mb: MB
188
+ tb: TB
189
+ percentage:
190
+ format:
191
+ delimiter: "."
192
+ format: "%n%"
193
+ precision:
194
+ format:
195
+ delimiter: "."
196
+ support:
197
+ array:
198
+ last_word_connector: " e "
199
+ two_words_connector: " e "
200
+ words_connector: ", "
201
+ time:
202
+ am: ''
203
+ formats:
204
+ default: "%a, %d de %B de %Y, %H:%M:%S %z"
205
+ long: "%d de %B de %Y, %H:%M"
206
+ short: "%d de %B, %H:%M"
207
+ pm: ''
@@ -0,0 +1,28 @@
1
+ require 'awesome_print'
2
+ require 'base64'
3
+ require 'colorize'
4
+ require 'dnsruby'
5
+ require 'encrypt'
6
+ require 'getoptlong'
7
+ require 'highline/import'
8
+ require 'i18n'
9
+ require 'ipaddress'
10
+ require 'ipcalc'
11
+ require 'json'
12
+ require 'logger'
13
+ require 'net/http'
14
+ require 'net/https'
15
+ require 'net/smtp'
16
+ require 'net/ssh'
17
+ require 'netaddr'
18
+ require 'prompt'
19
+ require 'public_suffix'
20
+ require 'rest_client'
21
+ require 'ruby-progressbar'
22
+ require 'rubygems'
23
+ require 'socket'
24
+ require 'tty-prompt'
25
+ require 'xmlsimple'
26
+ require 'thor'
27
+ require 'yaml'
28
+ include Dnsruby
@@ -0,0 +1,48 @@
1
+ require 'singleton'
2
+ class ToolsCache
3
+ include Singleton
4
+
5
+ def initialize(options = {})
6
+ end
7
+
8
+
9
+ # Create a cache file in work area
10
+ #
11
+ # @param arguments
12
+ # @return
13
+ def self.create_cache_file cache_name, cache_dir
14
+
15
+ unless File.exists? cache_dir
16
+ ToolsLog.tools_error "Invalid directory in new config file in '#{cache_dir}'.", :light_red
17
+ ToolsLog.tools_exit
18
+ end
19
+ unless cache_dir.end_with? '/'
20
+ cache_dir += '/'
21
+ end
22
+
23
+ cache_file = cache_dir + cache_name + '.cache'
24
+ if File.exists? cache_file
25
+ ToolsLog.tools_error "The cache file in '#{cache_file}' already exists. Leaving operation...", :light_yellow
26
+ else
27
+ ToolsFiles.create_file cache_dir, cache_name, "cache_#{cache_name}"
28
+ end
29
+
30
+ end
31
+
32
+ def self.method_missing(method, *args, &block)
33
+ #expected call format => STRING_LOGGER_TYPE + '_' + LOGGER_TYPE
34
+ # Ex.: tools_info
35
+ cache_name = method.to_s.split('_').first
36
+ cache_method = method.to_s.split('_').last
37
+ cache_file = ToolsUtil.get_variable "cache_#{cache_name}"
38
+
39
+ ap cache_name
40
+ ap cache_method
41
+ ap cache_file
42
+ ap args
43
+ ap block
44
+
45
+ end
46
+
47
+
48
+ end
@@ -0,0 +1,227 @@
1
+ require 'singleton'
2
+ class ToolsConfig
3
+ include Singleton
4
+
5
+ def initialize(options = {})
6
+ end
7
+
8
+
9
+
10
+ # Create a Config file in work area
11
+ #
12
+ # Sample
13
+ #
14
+ # ToolsConfig.create_config_file 'sample', '/myhome/tools/sample.log'
15
+ # log = ToolsUtil.get_variable "sample_config" => Logger Object
16
+ #
17
+ # ToolsConfig.create_log_file 'xyko', '/home/francisco/2018/xykotools/tools/xyko.config'
18
+ # config = ToolsConfig.xyko_load
19
+ # ToolsConfig.xyko_add {}
20
+ #
21
+ # @param logname
22
+ # @param logfile
23
+ # @return
24
+ def self.create_config_file config_name, config_file, config_type = :json
25
+ unless File.exists? config_file
26
+ case config_type
27
+ when :json
28
+ config = File.open(config_file, 'w')
29
+ data = {}
30
+ config.write JSON.pretty_generate(data)
31
+ config.close
32
+ ToolsLog.tools_info "Json config file '#{config_file}' was created!'"
33
+ return true
34
+ when :yaml
35
+ end
36
+ else
37
+ ToolsLog.tools_warn "The file #{config_file} really exist. leaving operation...."
38
+ end
39
+ ToolsUtil.set_variable "#{config_name}_config_file", config_file
40
+ ToolsUtil.set_variable "#{config_name}_config_type", config_type
41
+ end
42
+
43
+
44
+ def self.method_missing(method, *args, &block)
45
+ #expected call format => STRING_LOGGER_TYPE + '_' + LOGGER_TYPE
46
+ # Ex.: tools_info
47
+ config_name = method.to_s.split('_').first
48
+ config_method = method.to_s.split('_').last
49
+ config_file = ToolsUtil.get_variable "#{config_name}_config_file"
50
+ config_type = ToolsUtil.get_variable "#{config_name}_config_type"
51
+
52
+
53
+ end
54
+
55
+
56
+
57
+
58
+ # Create a config file in work area
59
+ #
60
+ # @param arguments
61
+ # @return
62
+ def self.create_config_file_old *arguments
63
+ directory = arguments.extract_first
64
+ file_name = arguments.extract_first
65
+
66
+ if arguments.extract_symbol :json
67
+ config_type = :json
68
+ else
69
+ if arguments.extract_symbol :yaml
70
+ config_type = :yaml
71
+ else
72
+ config_type = :default
73
+ end
74
+ end
75
+ config_type = :json if config_type.eql? :default
76
+ ToolsLog.tools_info "Setting config_type to '#{config_type}!'"
77
+ ToolsUtil.set_variable 'config_file_type', config_type
78
+
79
+ unless File.exists? directory
80
+ ToolsLog.tools_error "Invalid directory in new config file in '#{directory}'.", :light_red
81
+ ToolsLog.tools_exit
82
+ end
83
+ unless directory.end_with? '/'
84
+ directory += '/'
85
+ end
86
+ config_file_location = directory + file_name
87
+ ToolsUtil.set_variable 'config_file_location', config_file_location
88
+ ToolsLog.tools_info "Setting config_file_location to '#{config_file_location}!'"
89
+
90
+ unless File.exists? config_file_location
91
+ case config_type
92
+ when :json
93
+ config_file = File.open(config_file_location, 'w')
94
+ config = {}
95
+ config_file.write JSON.pretty_generate(config)
96
+ config_file.close
97
+ ToolsLog.tools_info "Json config file created!'"
98
+ return true
99
+ when :yaml
100
+ end
101
+ else
102
+ ToolsLog.tools_warn "The file #{config_file_location} really exist. leaving operation...."
103
+ end
104
+
105
+ end
106
+
107
+ # Test and register a config file in work area
108
+ # @param source
109
+ # @return boolean
110
+ def self.test_config_type source
111
+ file = open(source)
112
+ content = file.read
113
+ if ToolsUtil.valid_json? content
114
+ config_type = :json
115
+ else
116
+ if ToolsUtil.valid_yaml? content
117
+ config_type = :yaml
118
+ else
119
+ config_type = :invalid
120
+ ToolsLog.tools_error "Invalid format in config file in '#{source}'.", :light_red
121
+ ToolsLog.tools_exit
122
+ end
123
+ end
124
+ ToolsUtil.set_variable 'config_file_type', config_type
125
+ end
126
+
127
+
128
+ # Load a content from a config file in work area
129
+ # @param source
130
+ # @return content
131
+ def self.load_config source
132
+ test_config_type source
133
+ case ToolsUtil.get_variable 'config_file_type'
134
+ when :json
135
+ file = open(source)
136
+ json = file.read
137
+ parsed = JSON.parse(json)
138
+ ToolsUtil.set_variable 'config_data', parsed
139
+ return parsed
140
+ when :yaml
141
+ end
142
+ end
143
+
144
+ # Merge data in config file in work area
145
+ # @param source
146
+ # @return content
147
+ def self.insert_in_config source, command
148
+ test_config_type source
149
+ case ToolsUtil.get_variable 'config_file_type'
150
+ when :json
151
+ file = open(source)
152
+ json = file.read
153
+ parsed = JSON.parse(json)
154
+ parsed.rmerge!(command)
155
+ file.close
156
+ file = open(source, 'w')
157
+ file.write JSON.pretty_generate(parsed)
158
+ file.close
159
+ when :yaml
160
+ end
161
+ end
162
+
163
+
164
+
165
+ def self.validate_config
166
+ # ToolsLog.info "\t\tValidanting config file in #{Tools.home+'/.tools/config'}."
167
+ # ToolsConfig.daily_backup_config
168
+ # ToolsConfig.purge_backup_config
169
+ # file = open(Cmdapi.home+'/.tools/config')
170
+ # config = file.read
171
+ # begin
172
+ # JSON.parse(config)
173
+ # return true
174
+ # rescue Exception => e
175
+ # CMDAPIUtil.show_info "\tInvalid JSON config file in #{Cmdapi.home+'/.tools/config'}."
176
+ # CMDAPIUtil.show_info "\t Follow the instructions below to fix the problem."
177
+ # CMDAPIUtil.show_info "\t 1. Rename the config file #{Cmdapi.home+'/.tools/config'}."
178
+ # CMDAPIUtil.show_info "\t 2. Cmdapi run again. The cmdapi will create a new configuration file."
179
+ # CMDAPIUtil.show_info "\t 3. Copy the keys from the previous file to the new file."
180
+ # CMDAPIUtil.show_info "\t 4. Run cmdapi again.."
181
+ # CMDAPIUtil.show_info "\t Aborting operation...."
182
+ # exit
183
+ # end
184
+ end
185
+
186
+ def self.check_config
187
+ # ToolsLog.info "\t\tChecking config file: #{Tools.home+'/.tools/config'}."
188
+ # file = open(Tools.home+'/.tools/config')
189
+ # json = file.read
190
+ # parsed = JSON.parse(json)
191
+ # file.close
192
+ end
193
+
194
+ def self.purge_backup_config # execupa o purge de todos os backup com mais de 14 dias
195
+ # ToolsLog.info "\t\tPurge backup config file: #{Tools.home+'/.tools/config'}."
196
+ # to_clean = Dir.glob(File.join(Tools.home+'/.tools/backup', '*')).select { |a|
197
+ # Time.now - File.ctime(a) > 14*24*60*60 }
198
+ # to_clean.each do |file_to_delete|
199
+ # File.delete(file_to_delete)
200
+ # end
201
+ end
202
+
203
+ def self.config_backup
204
+ # ToolsLog.info "\t\tBackuping config file in #{Tools.home+'/.tools/backup'}."
205
+ # FileUtils.cp Tools.home+'/.tools/config',
206
+ # Tolls.home+'/.tools/backup/config_' +
207
+ # (ToolsUtil.get_date '%Y%m%d-%H%M') + '.backup'
208
+ end
209
+
210
+ def self.daily_backup_config
211
+ # #captura o backup mais recente
212
+ # least = Dir.glob(File.join(Cmdapi.home+'/.cmdapi3/backup', 'config*.backup')).max { |a,b| File.ctime(a) <=> File.ctime(b) }
213
+ # unless least.nil?
214
+ # #se não houver sido feito hoje
215
+ # unless File.ctime(least).to_date == Time.now.to_date
216
+ # # ToolsLog.info "\t\tStarting config backup."
217
+ # ToolsConfig.config_backup
218
+ # end
219
+ # else
220
+ # # ToolsLog.info "\t\tStarting config backup."
221
+ # ToolsConfig.config_backup
222
+ # end
223
+ # return true
224
+ end
225
+
226
+
227
+ end