avmtrf1-tools 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/avmtrf1.rb +1 -0
- data/lib/avmtrf1/oracle.rb +10 -0
- data/lib/avmtrf1/oracle/connection.rb +12 -0
- data/lib/avmtrf1/oracle/connection/base.rb +51 -0
- data/lib/avmtrf1/oracle/connection/string_builder.rb +45 -0
- data/lib/avmtrf1/tools/runner.rb +1 -0
- data/lib/avmtrf1/tools/runner/oracle.rb +43 -0
- data/lib/avmtrf1/tools/runner/oracle/source_get.rb +53 -0
- data/lib/avmtrf1/tools/version.rb +1 -1
- metadata +10 -11
- data/bin/oracle +0 -7
- data/init.rb +0 -10
- data/lib/oracle/commands/base.rb +0 -15
- data/lib/oracle/commands/source_get.rb +0 -50
- data/lib/oracle/connection/base.rb +0 -48
- data/lib/oracle/connection/string_builder.rb +0 -43
- data/lib/oracle/runner.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23b69be00c89091457f4244306d815817987b87caa3690b02d18f6c9fe45077e
|
4
|
+
data.tar.gz: 000f384ddec2ba3b349bb3fab9fb2900c547c99ac6536ed7b1fb5c69fdab8492
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82236d3324c6971ef223ce2c05052ca2ed1d8b165e530834d26f2fbbf5a469b7ff8c515e49ac02fe07742bd3351eb5599290ef2a9fad88478fe2341213a793a0
|
7
|
+
data.tar.gz: 8ffa24e233fddef75c55692181d604a4ae6dce639730306ae8b592ab411e24c25cff765913f6eebc322f5fce53023078871c18464629ab541c5725af08c94da2
|
data/lib/avmtrf1.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oci8'
|
4
|
+
|
5
|
+
module Avmtrf1
|
6
|
+
module Oracle
|
7
|
+
module Connection
|
8
|
+
class Base
|
9
|
+
DEFAULT_PORT = 1521
|
10
|
+
|
11
|
+
def initialize(connection_string)
|
12
|
+
ENV['NLS_LANG'] = 'BRAZILIAN PORTUGUESE_BRAZIL.WE8ISO8859P1'
|
13
|
+
@connection = OCI8.new(connection_string)
|
14
|
+
end
|
15
|
+
|
16
|
+
def unique_value(sql)
|
17
|
+
connection.exec(sql) do |row|
|
18
|
+
return row.first
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def query(sql, &block)
|
23
|
+
if block
|
24
|
+
query_with_block(sql, block)
|
25
|
+
else
|
26
|
+
query_without_block(sql)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_reader :connection
|
33
|
+
|
34
|
+
def query_without_block(sql)
|
35
|
+
connection.exec(sql)
|
36
|
+
end
|
37
|
+
|
38
|
+
def query_with_block(sql, block)
|
39
|
+
cursor = query_without_block(sql)
|
40
|
+
begin
|
41
|
+
while (row = cursor.fetch_hash)
|
42
|
+
block.call(row)
|
43
|
+
end
|
44
|
+
ensure
|
45
|
+
cursor.close
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Avmtrf1
|
4
|
+
module Oracle
|
5
|
+
module Connection
|
6
|
+
class StringBuilder
|
7
|
+
DEFAULT_PORT = 1521
|
8
|
+
|
9
|
+
FIELDS = %w[user password host port service_name].freeze
|
10
|
+
|
11
|
+
attr_accessor(*FIELDS)
|
12
|
+
attr_accessor :string
|
13
|
+
|
14
|
+
def initialize(options = nil)
|
15
|
+
if options.is_a?(String)
|
16
|
+
self.string = options
|
17
|
+
elsif options.is_a?(Hash)
|
18
|
+
options.each do |k, v|
|
19
|
+
send("#{k}=", v)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def port
|
25
|
+
@port || DEFAULT_PORT
|
26
|
+
end
|
27
|
+
|
28
|
+
def build
|
29
|
+
if string
|
30
|
+
string
|
31
|
+
else
|
32
|
+
validate_fields
|
33
|
+
"#{user}/#{password}@//#{host}:#{port}/#{service_name}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def validate_fields
|
40
|
+
FIELDS.each { |f| raise "\"#{f}\" is blank" if send(f).blank? }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/avmtrf1/tools/runner.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avmtrf1/oracle/connection/base.rb'
|
4
|
+
require 'avmtrf1/oracle/connection/string_builder.rb'
|
5
|
+
require 'avmtrf1/tools/runner/oracle/source_get.rb'
|
6
|
+
|
7
|
+
module Avmtrf1
|
8
|
+
module Tools
|
9
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
10
|
+
class Oracle < ::EacRubyUtils::Console::DocoptRunner
|
11
|
+
include ::EacRubyUtils::Console::Speaker
|
12
|
+
|
13
|
+
DOC = <<~DOCOPT
|
14
|
+
Usage:
|
15
|
+
__PROGRAM__ [options] __SUBCOMMANDS__
|
16
|
+
__PROGRAM__ -h | --help
|
17
|
+
|
18
|
+
Options:
|
19
|
+
-h --help Show this screen
|
20
|
+
-H --host=<host> Host Oracle (Ex.: 172.16.3.3)
|
21
|
+
-p --port=<port> Porta Oracle (Ex.: 1521) (Padrão: 1521).
|
22
|
+
-s --service-name=<service> Serviço Oracle (Ex.: trf1.trf1.gov.br)
|
23
|
+
-u --user=<user> Usuário Oracle
|
24
|
+
-w --password=<password> Senha Oracle
|
25
|
+
DOCOPT
|
26
|
+
|
27
|
+
def connection
|
28
|
+
@connection ||= ::Avmtrf1::Oracle::Connection::Base.new(connection_string)
|
29
|
+
end
|
30
|
+
|
31
|
+
def connection_string
|
32
|
+
::Avmtrf1::Oracle::Connection::StringBuilder.new(
|
33
|
+
host: options['--host'],
|
34
|
+
port: options['--port'],
|
35
|
+
user: options['--user'],
|
36
|
+
password: options['--password'],
|
37
|
+
service_name: options['--service-name']
|
38
|
+
).build
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Avmtrf1
|
4
|
+
module Tools
|
5
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
6
|
+
class Oracle < ::EacRubyUtils::Console::DocoptRunner
|
7
|
+
class SourceGet < ::EacRubyUtils::Console::DocoptRunner
|
8
|
+
include ::EacRubyUtils::Console::Speaker
|
9
|
+
|
10
|
+
DOC = <<~DOCOPT
|
11
|
+
Usage:
|
12
|
+
__PROGRAM__ [options] <name> <type>
|
13
|
+
__PROGRAM__ -h | --help
|
14
|
+
|
15
|
+
Options:
|
16
|
+
-h --help Show this screen
|
17
|
+
DOCOPT
|
18
|
+
|
19
|
+
TABLE = 'all_source'
|
20
|
+
|
21
|
+
def name
|
22
|
+
options.fetch('<name>')
|
23
|
+
end
|
24
|
+
|
25
|
+
def type
|
26
|
+
options.fetch('<type>')
|
27
|
+
end
|
28
|
+
|
29
|
+
def run
|
30
|
+
infov('Name', name)
|
31
|
+
infov('Type', type)
|
32
|
+
infov('Found', found_count)
|
33
|
+
infov('Enconding', OCI8.encoding)
|
34
|
+
context(:connection).query(sql(false)) do |row|
|
35
|
+
out(row['TEXT'].encode('UTF-8').to_s)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def found_count
|
40
|
+
context(:connection).unique_value(sql(true)).to_i
|
41
|
+
end
|
42
|
+
|
43
|
+
def sql(count)
|
44
|
+
projection = count ? 'count(*)' : '*'
|
45
|
+
selection = "lower(name) = lower('#{name}')"
|
46
|
+
selection += " and lower(type) = lower('#{type}')" if type.present?
|
47
|
+
"select #{projection} from #{TABLE} where #{selection} order by line"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avmtrf1-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo H. Bogoni
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aranha
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: 0.74.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: 0.74.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rubocop-rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,9 +130,7 @@ extensions: []
|
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
132
|
- Gemfile
|
133
|
-
- bin/oracle
|
134
133
|
- exe/avmtrf1
|
135
|
-
- init.rb
|
136
134
|
- lib/avmtrf1.rb
|
137
135
|
- lib/avmtrf1/esosti/parsers/solicitacao/main.rb
|
138
136
|
- lib/avmtrf1/esosti/session.rb
|
@@ -143,6 +141,10 @@ files:
|
|
143
141
|
- lib/avmtrf1/esosti/session/solicitacao/main.rb
|
144
142
|
- lib/avmtrf1/ini.rb
|
145
143
|
- lib/avmtrf1/ini/profile.rb
|
144
|
+
- lib/avmtrf1/oracle.rb
|
145
|
+
- lib/avmtrf1/oracle/connection.rb
|
146
|
+
- lib/avmtrf1/oracle/connection/base.rb
|
147
|
+
- lib/avmtrf1/oracle/connection/string_builder.rb
|
146
148
|
- lib/avmtrf1/patches.rb
|
147
149
|
- lib/avmtrf1/patches/inifile.rb
|
148
150
|
- lib/avmtrf1/red.rb
|
@@ -155,13 +157,10 @@ files:
|
|
155
157
|
- lib/avmtrf1/tools.rb
|
156
158
|
- lib/avmtrf1/tools/runner.rb
|
157
159
|
- lib/avmtrf1/tools/runner/esosti.rb
|
160
|
+
- lib/avmtrf1/tools/runner/oracle.rb
|
161
|
+
- lib/avmtrf1/tools/runner/oracle/source_get.rb
|
158
162
|
- lib/avmtrf1/tools/runner/red.rb
|
159
163
|
- lib/avmtrf1/tools/version.rb
|
160
|
-
- lib/oracle/commands/base.rb
|
161
|
-
- lib/oracle/commands/source_get.rb
|
162
|
-
- lib/oracle/connection/base.rb
|
163
|
-
- lib/oracle/connection/string_builder.rb
|
164
|
-
- lib/oracle/runner.rb
|
165
164
|
homepage: http://redmine.trf1.gov.br/projects/avm-trf1
|
166
165
|
licenses: []
|
167
166
|
metadata: {}
|
data/bin/oracle
DELETED
data/init.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
ENV['BUNDLE_GEMFILE'] = ::File.join(__dir__, 'Gemfile')
|
4
|
-
ENV['NLS_LANG'] = 'BRAZILIAN PORTUGUESE_BRAZIL.WE8ISO8859P1'
|
5
|
-
require 'rubygems'
|
6
|
-
require 'bundler/setup'
|
7
|
-
require 'eac_ruby_utils'
|
8
|
-
require 'active_support/core_ext/object'
|
9
|
-
|
10
|
-
$LOAD_PATH.unshift ::File.join(__dir__, 'lib')
|
data/lib/oracle/commands/base.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'oracle/commands/base'
|
4
|
-
|
5
|
-
module Oracle
|
6
|
-
module Commands
|
7
|
-
class SourceGet < ::Oracle::Commands::Base
|
8
|
-
include ::EacRubyUtils::Console::Speaker
|
9
|
-
|
10
|
-
TABLE = 'all_source'
|
11
|
-
|
12
|
-
def initialize(connection, options)
|
13
|
-
super(connection)
|
14
|
-
@name = options[:name]
|
15
|
-
@type = options[:type]
|
16
|
-
validate
|
17
|
-
run
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
attr_reader :name, :type
|
23
|
-
|
24
|
-
def validate
|
25
|
-
raise '"name" is blank' if name.blank?
|
26
|
-
end
|
27
|
-
|
28
|
-
def run
|
29
|
-
infov('Name', name)
|
30
|
-
infov('Type', type)
|
31
|
-
infov('Found', found_count)
|
32
|
-
infov('Enconding', OCI8.encoding)
|
33
|
-
connection.query(sql(false)) do |row|
|
34
|
-
out(row['TEXT'].encode('UTF-8').to_s)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def found_count
|
39
|
-
connection.unique_value(sql(true)).to_i
|
40
|
-
end
|
41
|
-
|
42
|
-
def sql(count)
|
43
|
-
projection = count ? 'count(*)' : '*'
|
44
|
-
selection = "lower(name) = lower('#{name}')"
|
45
|
-
selection += " and lower(type) = lower('#{type}')" if type.present?
|
46
|
-
"select #{projection} from #{TABLE} where #{selection} order by line"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'oci8'
|
4
|
-
|
5
|
-
module Oracle
|
6
|
-
module Connection
|
7
|
-
class Base
|
8
|
-
DEFAULT_PORT = 1521
|
9
|
-
|
10
|
-
def initialize(connection_string)
|
11
|
-
@connection = OCI8.new(connection_string)
|
12
|
-
end
|
13
|
-
|
14
|
-
def unique_value(sql)
|
15
|
-
connection.exec(sql) do |row|
|
16
|
-
return row.first
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def query(sql, &block)
|
21
|
-
if block
|
22
|
-
query_with_block(sql, block)
|
23
|
-
else
|
24
|
-
query_without_block(sql)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
attr_reader :connection
|
31
|
-
|
32
|
-
def query_without_block(sql)
|
33
|
-
connection.exec(sql)
|
34
|
-
end
|
35
|
-
|
36
|
-
def query_with_block(sql, block)
|
37
|
-
cursor = query_without_block(sql)
|
38
|
-
begin
|
39
|
-
while (row = cursor.fetch_hash)
|
40
|
-
block.call(row)
|
41
|
-
end
|
42
|
-
ensure
|
43
|
-
cursor.close
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Oracle
|
4
|
-
module Connection
|
5
|
-
class StringBuilder
|
6
|
-
DEFAULT_PORT = 1521
|
7
|
-
|
8
|
-
FIELDS = %w[user password host port service_name].freeze
|
9
|
-
|
10
|
-
attr_accessor(*FIELDS)
|
11
|
-
attr_accessor :string
|
12
|
-
|
13
|
-
def initialize(options = nil)
|
14
|
-
if options.is_a?(String)
|
15
|
-
self.string = options
|
16
|
-
elsif options.is_a?(Hash)
|
17
|
-
options.each do |k, v|
|
18
|
-
send("#{k}=", v)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def port
|
24
|
-
@port || DEFAULT_PORT
|
25
|
-
end
|
26
|
-
|
27
|
-
def build
|
28
|
-
if string
|
29
|
-
string
|
30
|
-
else
|
31
|
-
validate_fields
|
32
|
-
"#{user}/#{password}@//#{host}:#{port}/#{service_name}"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def validate_fields
|
39
|
-
FIELDS.each { |f| raise "\"#{f}\" is blank" if send(f).blank? }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
data/lib/oracle/runner.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'oracle/connection/base.rb'
|
4
|
-
require 'oracle/connection/string_builder.rb'
|
5
|
-
require 'oracle/commands/source_get.rb'
|
6
|
-
|
7
|
-
module Oracle
|
8
|
-
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
9
|
-
include ::EacRubyUtils::Console::Speaker
|
10
|
-
|
11
|
-
DOC = <<~DOCOPT
|
12
|
-
Usage:
|
13
|
-
__PROGRAM__ [options] source:get <name> <type>
|
14
|
-
__PROGRAM__ -h | --help
|
15
|
-
|
16
|
-
Options:
|
17
|
-
-h --help Show this screen
|
18
|
-
-H --host=<host> Host Oracle (Ex.: 172.16.3.3)
|
19
|
-
-p --port=<port> Porta Oracle (Ex.: 1521) (Padrão: 1521).
|
20
|
-
-s --service-name=<service> Serviço Oracle (Ex.: trf1.trf1.gov.br)
|
21
|
-
-u --user=<user> Usuário Oracle
|
22
|
-
-w --password=<password> Senha Oracle
|
23
|
-
DOCOPT
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def run
|
28
|
-
run_source_get if options['source:get']
|
29
|
-
end
|
30
|
-
|
31
|
-
def run_source_get
|
32
|
-
Oracle::Commands::SourceGet.new(connection, name: options['<name>'], type: options['<type>'])
|
33
|
-
end
|
34
|
-
|
35
|
-
def connection
|
36
|
-
@connection ||= ::Oracle::Connection::Base.new(connection_string)
|
37
|
-
end
|
38
|
-
|
39
|
-
def connection_string
|
40
|
-
::Oracle::Connection::StringBuilder.new(
|
41
|
-
host: options['--host'],
|
42
|
-
port: options['--port'],
|
43
|
-
user: options['--user'],
|
44
|
-
password: options['--password'],
|
45
|
-
service_name: options['--service-name']
|
46
|
-
).build
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|