cv-tool 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b4ea67b5e07754ecf8e767310d84e604378ff05d32c3e2ef8084a369a3127ae
4
- data.tar.gz: 72f397c82a4180513710d6c1059e537f2f7d461feea56ab7cc373e1dd6d38433
3
+ metadata.gz: 881853b9f0c1d49fc0519368b4a11e3ba66487480fef286e13c435a4d925ad33
4
+ data.tar.gz: d1dad9c2a656c647cae30dbd67df8530f82f6e6709b73a5e4495b3e0cd5314be
5
5
  SHA512:
6
- metadata.gz: 2b814fb52649dc7fae5ea6acd9a9776822e654189fe930808a158c5b283c79de4c0e65a2646ec072c7d3f61717724fab5705ec50c5083d44d47e7fec04646dce
7
- data.tar.gz: 2a2b26d733e9349b02f83de36838a89ea6c2a74e8e5cd3f148b406177aa1f7c74e1ca682f66da0b71696d011d9dad362b3eaaac3ce8fe5d69702e6c87c6beeb8
6
+ metadata.gz: 953457a042e3126791e2f6c03470b647970a76da3b973e8ab5aa95356d7f20ce94ba36367de4c4e6d314fa5c2c75a99c62f2aea121ead7c30aff0428f2cbcc5c
7
+ data.tar.gz: d5030140d9394f794cd4e51b8d7d1a5b9ed5027e1b670cb7150f36b9a2a3f00b266e01f407da8caf776703ec5f58880cfbe891f19aa57d19ebd1fae0dd61f0a0
data/app/arguments.rb CHANGED
@@ -6,6 +6,7 @@ require 'option_parser'
6
6
  endpoint: nil,
7
7
  request_body: nil,
8
8
  generate_db: nil,
9
+ setup_db: nil,
9
10
  },
10
11
  gt_length: -1,
11
12
  api_url: nil,
@@ -64,10 +65,10 @@ OptionParser.parse do |parser|
64
65
  @options[:rest_api][:request_body] = path
65
66
  CVTool::Event.print('REQUEST-BODY', path)
66
67
  end
67
- parser.on( "-gdb PATH", "--generate-db PATH", "It creates *json* files for Projects and\n" +
68
+ parser.on( "-gdb PATH", "--generate-db PATH", "It creates JSON files for Projects and\n" +
68
69
  "Articles in the defined path (it obtains\n" +
69
70
  "the relevant data from the Rest API, which\n" +
70
- "is then sorted and saved).\n" ) do |path|
71
+ "is then sorted and saved)." ) do |path|
71
72
 
72
73
  unless path
73
74
  path = Dir.pwd
@@ -76,6 +77,16 @@ OptionParser.parse do |parser|
76
77
  @options[:rest_api][:generate_db] = path
77
78
  CVTool::Event.print('GENERATE-DB', path)
78
79
  end
80
+ parser.on( "-sdb PATH", "--setup-db PATH", "All JSON files for Articles and Projects\n" +
81
+ "are uploaded to the database." ) do |path|
82
+
83
+ unless path
84
+ path = Dir.pwd
85
+ end
86
+
87
+ @options[:rest_api][:setup_db] = path
88
+ CVTool::Event.print('SETUP-DB', path)
89
+ end
79
90
  end
80
91
  end
81
92
  parser.on( "-gt LENG", "--generate-token LENG",
data/app/configuration.rb CHANGED
@@ -2,14 +2,14 @@ require 'json'
2
2
 
3
3
  @configuration = JsonParser.new File.join(ROOT, 'config/default.json')
4
4
  @configuration.on :api_url, CVTool::Constants::API_URI
5
- @configuration.on :is_ssl, true
5
+ @configuration.on :is_ssl, false.to_s
6
6
 
7
7
  h_api_url = lambda do |_|
8
8
  return @configuration.parse(:api_url)
9
9
  end
10
10
 
11
11
  h_is_ssl = lambda do |_|
12
- return @configuration.parse(:is_ssl).to_b
12
+ return @configuration.parse(:is_ssl).to_s.to_b
13
13
  end
14
14
 
15
15
  def get_config_str()
data/app/main.rb CHANGED
@@ -82,11 +82,21 @@ def generate_db_state()
82
82
  end
83
83
  end
84
84
 
85
- if @options[:rest_api][:is_active]
86
- unless @options[:rest_api][:generate_db]
85
+ def setup_db_state()
86
+ if @options[:rest_api][:endpoint] == CVTool::Constants::ENDPOINTS[12]
87
87
  rest_api_state()
88
- else
88
+ end
89
+
90
+ CVTool.setup_db(@options[:rest_api][:setup_db])
91
+ end
92
+
93
+ if @options[:rest_api][:is_active]
94
+ if @options[:rest_api][:generate_db]
89
95
  generate_db_state()
96
+ elsif @options[:rest_api][:setup_db]
97
+ setup_db_state()
98
+ else
99
+ rest_api_state()
90
100
  end
91
101
  else
92
102
  token_state()
data/bin/cvtool CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ ROOT_FILE = __FILE__
3
4
  ROOT = File.expand_path("..", __dir__)
4
5
  $: << "#{ROOT}/lib"
5
6
  require_relative "#{ROOT}/app/main"
@@ -1,3 +1,3 @@
1
1
  module CVTool
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.2'
3
3
  end
data/lib/cv_tool.rb CHANGED
@@ -36,4 +36,30 @@ module CVTool
36
36
  CVTool::Event.print('GENERATE', absolute_path_file)
37
37
  end
38
38
  end
39
+
40
+ def setup_db(path)
41
+ dir_apath = File.join(path, '*/*.json')
42
+ json_files = Dir.glob(dir_apath)
43
+ files = {
44
+ articles: json_files.select { |e| e.index(/\/articles\//) },
45
+ projects: json_files.select { |e| e.index(/\/projects\//) },
46
+ }
47
+
48
+ h_execute_command = lambda do |symbol|
49
+ result = ""
50
+ files[symbol].each.with_index do |path, i|
51
+ result += "#{ROOT_FILE} -ra -ep post/#{symbol.to_s.sub(/s$/, '')}/add -reb #{path} &&\n"
52
+ end
53
+ return result
54
+ end
55
+
56
+ command = h_execute_command.call(:projects) + h_execute_command.call(:articles)
57
+ is_success = system(command.sub(/ &&\n$/, "\n"))
58
+
59
+ if is_success
60
+ CVTool::Event.print('SETUP-DB', "done")
61
+ else
62
+ CVTool::Event.print('SETUP-DB', "an error occurred during db setup.")
63
+ end
64
+ end
39
65
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cv-tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Filip Vrba
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-14 00:00:00.000000000 Z
11
+ date: 2023-03-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: The tool will allow communication through a Rest API, enabling the retrieval
14
14
  and transmission of data to and from the database. Additionally, it will provide