organo 0.3.5 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/anime.md +30 -8
- data/doc/readme.md +2 -2
- data/lib/organo/commands/anime/anime_add.rb +27 -24
- data/lib/organo/commands/anime/anime_find_broken_links.rb +31 -0
- data/lib/organo/commands/anime/anime_remove.rb +10 -14
- data/lib/organo/commands/anime/anime_set_sequel.rb +49 -0
- data/lib/organo/commands/anime/anime_show.rb +9 -15
- data/lib/organo/commands/anime/anime_update_image.rb +16 -35
- data/lib/organo/commands/anime/anime_update_query.rb +16 -21
- data/lib/organo/commands/api/api_get_anime.rb +3 -6
- data/lib/organo/commands/api/api_get_season.rb +3 -4
- data/lib/organo/commands/api/api_get_sequels.rb +1 -3
- data/lib/organo/commands/init.rb +30 -8
- data/lib/organo/commands/remote/remote_add.rb +6 -10
- data/lib/organo/commands/remote/remote_download.rb +5 -6
- data/lib/organo/commands/remote/remote_remove.rb +0 -2
- data/lib/organo/commands/remote/remote_upload.rb +1 -2
- data/lib/organo/commands/statistics.rb +6 -21
- data/lib/organo/query.rb +0 -1
- data/lib/organo/tools/string_utils.rb +28 -0
- data/lib/organo/tools/writer.rb +0 -5
- data/lib/organo/version.rb +1 -1
- data/lib/organo.rb +34 -43
- metadata +36 -17
- data/lib/organo/commands/anime/anime_add_sequel.rb +0 -52
- data/lib/organo/commands/anime/anime_get_broken_links.rb +0 -32
- data/lib/organo/commands/anime/anime_search.rb +0 -25
- data/lib/organo/commands/api/api_search_anime.rb +0 -29
- data/lib/organo/commands/merge.rb +0 -24
- data/lib/organo/model/search_show.rb +0 -58
- data/lib/organo/model/sequel.rb +0 -39
- data/lib/organo/model/show.rb +0 -36
- data/lib/organo/show_list.rb +0 -32
- data/lib/organo/tools/check.rb +0 -12
- data/lib/organo/tools/local_search.rb +0 -49
- data/lib/organo/tools/reader.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1babd85ffac4bb77177ade8a0a7f568ef67715df76d4ec2bf224ce016a973ba1
|
4
|
+
data.tar.gz: 967d6eafa28f342d82032a70a8452595239f01deb43525c211c56bba6f7ee6d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f7a73df4cdb8163e61a720434693a2411500d087bc4da5fcddd61c4e7272ae0c65aee956b640a79afeba3bc96c3045f97f0a476d037d584e1632036ddc0298b
|
7
|
+
data.tar.gz: 7331b6d1abf07bf24d521efd5babcc552f38d9df151108c731f4a0b1c8035c729b7267ecbe43ae4e433b1ccb65d8d90c3424017e7fed4ffedd63dff04cb535ce
|
data/doc/anime.md
CHANGED
@@ -2,27 +2,49 @@
|
|
2
2
|
|
3
3
|
## add
|
4
4
|
|
5
|
-
Add anime entry to
|
5
|
+
Add anime entry to database.
|
6
6
|
```shell
|
7
7
|
organo anime add MAL_ID
|
8
8
|
```
|
9
9
|
|
10
|
-
##
|
10
|
+
## set_sequel
|
11
11
|
|
12
|
-
|
12
|
+
Sets anime as sequel and creates a sequel entry to database.
|
13
13
|
```shell
|
14
|
-
organo anime
|
14
|
+
organo anime set_sequel PARENT_MAL_ID CHILD_MAL_ID
|
15
15
|
```
|
16
16
|
|
17
|
-
##
|
17
|
+
## find_broken_links
|
18
18
|
|
19
19
|
Get list of anime IDs that have broken links.
|
20
20
|
```shell
|
21
|
-
organo anime
|
21
|
+
organo anime find_broken_links
|
22
22
|
```
|
23
23
|
|
24
24
|
## remove
|
25
|
-
|
25
|
+
|
26
|
+
Remove anime entry from database.
|
27
|
+
```shell
|
28
|
+
organo anime remove MAL_ID
|
29
|
+
```
|
30
|
+
|
26
31
|
## show
|
32
|
+
|
33
|
+
Shows anime database entry in console.
|
34
|
+
```shell
|
35
|
+
organo anime show MAL_ID
|
36
|
+
```
|
37
|
+
|
27
38
|
## update image
|
28
|
-
|
39
|
+
|
40
|
+
Updates the `img_url` column of one or more anime to URL from the API.
|
41
|
+
```shell
|
42
|
+
organo anime update image MAL_ID [...]
|
43
|
+
```
|
44
|
+
|
45
|
+
## update query
|
46
|
+
|
47
|
+
Updates the `search_query` column of anime to specified string.
|
48
|
+
```shell
|
49
|
+
organo anime update query MAL_ID SEARCH_QUERY
|
50
|
+
```
|
data/doc/readme.md
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
The tool is broken into 4 main subcommands.
|
4
4
|
|
5
5
|
- [Anime](anime.md)
|
6
|
-
- Manage and browse the
|
6
|
+
- Manage and browse the database.
|
7
7
|
- [API](api.md)
|
8
|
-
- Get data from
|
8
|
+
- Get data from APIs.
|
9
9
|
- [Remote](remote.md)
|
10
10
|
- Add FTP remote information to push the data to the website.
|
11
11
|
- [Schedule](schedule.md)
|
@@ -1,37 +1,40 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require_relative '../../
|
4
|
-
require_relative '../../tools/
|
5
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../query'
|
4
|
+
require_relative '../../tools/string_utils'
|
5
|
+
require 'sequel'
|
6
6
|
|
7
7
|
module Organo
|
8
8
|
module CLI
|
9
9
|
module Commands
|
10
10
|
module Anime
|
11
|
-
module Add
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
class AddEntry < Dry::CLI::Command
|
13
|
+
desc 'Add anime entry'
|
14
|
+
argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
16
|
+
def call(mal_id:, **)
|
17
|
+
db = Sequel.sqlite('./dkb_edited.db')
|
18
|
+
shows = db.from(:shows).where(mal_id: mal_id)
|
19
|
+
if shows.count.zero?
|
20
|
+
show_json = Query.get_anime_by_id(mal_id)
|
21
|
+
db.from(:shows).insert(
|
22
|
+
mal_id: show_json['mal_id'].to_i,
|
23
|
+
slug: StringUtils.create_slug(show_json['title']),
|
24
|
+
title: show_json['title'],
|
25
|
+
img_url: show_json['images']['jpg']['image_url'],
|
26
|
+
search_query: show_json['title'].gsub(':', ' -'),
|
27
|
+
is_sequel: false
|
28
|
+
)
|
29
|
+
shows = db.from(:shows).where(mal_id: mal_id)
|
30
|
+
puts 'Show has been added to database'
|
31
|
+
else
|
32
|
+
puts 'This show already exists'
|
31
33
|
end
|
34
|
+
puts shows.first
|
32
35
|
end
|
33
|
-
|
34
36
|
end
|
37
|
+
|
35
38
|
end
|
36
39
|
end
|
37
40
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
require 'sequel'
|
5
|
+
|
6
|
+
module Organo
|
7
|
+
module CLI
|
8
|
+
module Commands
|
9
|
+
module Anime
|
10
|
+
|
11
|
+
class FindBrokenLinks < Dry::CLI::Command
|
12
|
+
desc 'Get list of anime IDs that have broken links'
|
13
|
+
|
14
|
+
def call(*)
|
15
|
+
db = Sequel.sqlite('dkb_edited.db')
|
16
|
+
shows = db.from(:shows)
|
17
|
+
broken_list = []
|
18
|
+
shows.each do |show|
|
19
|
+
response = HTTParty.get(show[:img_url])
|
20
|
+
next unless response.code == 404
|
21
|
+
|
22
|
+
broken_list.push(show[:mal_id])
|
23
|
+
end
|
24
|
+
puts broken_list.join(' ') unless broken_list.empty?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,28 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require_relative '../../tools/check'
|
3
|
+
require 'sequel'
|
5
4
|
|
6
5
|
module Organo
|
7
6
|
module CLI
|
8
7
|
module Commands
|
9
8
|
module Anime
|
10
|
-
|
11
|
-
class Remove < Dry::CLI::Command
|
9
|
+
class RemoveEntry < Dry::CLI::Command
|
12
10
|
desc 'Remove anime entry from files'
|
13
11
|
argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
|
14
12
|
|
15
13
|
def call(mal_id:, **)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
puts "Removed anime \"#{show.title}\" (#{mal_id})"
|
25
|
-
break
|
14
|
+
db = Sequel.sqlite('./dkb_edited.db')
|
15
|
+
shows = db.from(:shows).where(mal_id: mal_id)
|
16
|
+
if shows.count.zero?
|
17
|
+
puts 'This show doesn\'t exist.'
|
18
|
+
else
|
19
|
+
puts 'Removed show.'
|
20
|
+
puts shows.first
|
21
|
+
shows.delete
|
26
22
|
end
|
27
23
|
end
|
28
24
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sequel'
|
4
|
+
|
5
|
+
module Organo
|
6
|
+
module CLI
|
7
|
+
module Commands
|
8
|
+
module Anime
|
9
|
+
|
10
|
+
class SequelEntry < Dry::CLI::Command
|
11
|
+
desc 'Set show entry as sequel to another show'
|
12
|
+
argument :parent_id, type: :integer, required: true, desc: 'Anime MyAnimeList ID'
|
13
|
+
argument :child_id, type: :integer, required: true, desc: 'Sequel MyAnimeList ID'
|
14
|
+
argument :type, type: :string, required: false, default: 'season', values: %w[season movie ova], desc: 'Type of sequel (season, movie, ova)'
|
15
|
+
argument :type_num, type: :integer, required: false, default: 0, desc: 'The sequel type number'
|
16
|
+
argument :subtype, type: :string, required: false, default: '', values: %w[part special ova], desc: 'Type of sequel (part, special, ova)'
|
17
|
+
argument :subtype_num, type: :integer, required: false, default: 0, desc: 'The sequel subtype number'
|
18
|
+
argument :subtype_selector, type: :integer, required: false, default: -1, desc: 'The sequel subtype selector'
|
19
|
+
|
20
|
+
def call(parent_id:, child_id:, type:, type_num:, subtype:, subtype_num:, subtype_selector:, **)
|
21
|
+
db = Sequel.sqlite('dkb_edited.db')
|
22
|
+
parent_show = db.from(:shows).where(mal_id: parent_id)
|
23
|
+
child_show = db.from(:shows).where(mal_id: child_id)
|
24
|
+
if parent_show.count.positive? && child_show.count.positive?
|
25
|
+
if db.from(:sequels).where(parent_id: parent_id, child_id: child_id).count.positive?
|
26
|
+
puts 'This sequel entry already exist.'
|
27
|
+
else
|
28
|
+
db.from(:sequels).insert(
|
29
|
+
parent_id: parent_id,
|
30
|
+
child_id: child_id,
|
31
|
+
type: type,
|
32
|
+
type_num: type_num,
|
33
|
+
subtype: subtype,
|
34
|
+
subtype_num: subtype_num,
|
35
|
+
subtype_selector: subtype_selector
|
36
|
+
)
|
37
|
+
child_show.update(is_sequel: true)
|
38
|
+
puts "#{child_show.first[:title]}(#{child_show.first[:mal_id]}) is now a sequel to #{parent_show.first[:title]}(#{parent_show.first[:mal_id]})"
|
39
|
+
end
|
40
|
+
else
|
41
|
+
puts "Parent or child show doesn't exist."
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,30 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require_relative '../../tools/check'
|
3
|
+
require 'sequel'
|
5
4
|
|
6
5
|
module Organo
|
7
6
|
module CLI
|
8
7
|
module Commands
|
9
8
|
module Anime
|
10
9
|
|
11
|
-
class
|
12
|
-
desc 'Show anime entry
|
10
|
+
class ShowEntry < Dry::CLI::Command
|
11
|
+
desc 'Show anime entry'
|
13
12
|
argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
|
14
13
|
|
15
14
|
def call(mal_id:, **)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
found = true
|
24
|
-
puts show.to_json
|
25
|
-
break
|
15
|
+
db = Sequel.sqlite('dkb_edited.db')
|
16
|
+
show = db.from(:shows).where(mal_id: mal_id)
|
17
|
+
if show.count.positive?
|
18
|
+
puts show.first
|
19
|
+
else
|
20
|
+
puts "ID #{mal_id} doesn't exist in the database."
|
26
21
|
end
|
27
|
-
puts 'Entry not found.' unless found
|
28
22
|
end
|
29
23
|
end
|
30
24
|
|
@@ -1,52 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'sequel'
|
4
4
|
require_relative '../../query'
|
5
|
-
require_relative '../../tools/writer'
|
6
|
-
require_relative '../../tools/reader'
|
7
|
-
require_relative '../../tools/check'
|
8
5
|
|
9
6
|
module Organo
|
10
7
|
module CLI
|
11
8
|
module Commands
|
12
9
|
module Anime
|
13
|
-
module Update
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
class UpdateImage < Dry::CLI::Command
|
12
|
+
desc 'Update cover image for the specified anime'
|
13
|
+
argument :mal_id_list, type: :array, required: true, desc: 'MyAnimeList ID list'
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
next if show.nil?
|
32
|
-
|
33
|
-
found = true
|
34
|
-
if show.is_a?(Hash)
|
35
|
-
show['image_url'] = Query.get_anime_image(show['id'])
|
36
|
-
# puts show['image_url']
|
37
|
-
else
|
38
|
-
show.image_url = Query.get_anime_image(show.id)
|
39
|
-
# puts show.image_url
|
40
|
-
end
|
41
|
-
Writer.to_file(shows_list, file_path)
|
42
|
-
sleep(1) if mal_id_list.size > 1 && index < (mal_id.size - 1)
|
43
|
-
end
|
15
|
+
def call(mal_id_list:, **)
|
16
|
+
db = Sequel.sqlite('dkb_edited.db')
|
17
|
+
mal_id_list.each do |mal_id|
|
18
|
+
show = db.from(:shows).where(mal_id: mal_id)
|
19
|
+
api_image = Query.get_anime_image(mal_id)
|
20
|
+
if show.count.positive?
|
21
|
+
show.update(img_url: api_image)
|
22
|
+
puts "Updated image of #{show.first[:title]} (#{mal_id})"
|
23
|
+
puts api_image
|
24
|
+
else
|
25
|
+
puts "ID #{mal_id} doesn't exist in the database."
|
44
26
|
end
|
45
|
-
puts found ? 'Cover image(s) has been updated.' : 'Entry not found.'
|
46
27
|
end
|
47
28
|
end
|
48
|
-
|
49
29
|
end
|
30
|
+
|
50
31
|
end
|
51
32
|
end
|
52
33
|
end
|
@@ -1,36 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require_relative '../../tools/writer'
|
5
|
-
require_relative '../../tools/reader'
|
6
|
-
require_relative '../../tools/check'
|
3
|
+
require 'sequel'
|
7
4
|
|
8
5
|
module Organo
|
9
6
|
module CLI
|
10
7
|
module Commands
|
11
8
|
module Anime
|
12
|
-
module Update
|
13
9
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
class UpdateSearchQuery < Dry::CLI::Command
|
11
|
+
desc 'Update search query for the specified anime'
|
12
|
+
argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
|
13
|
+
argument :search_query, type: :string, required: true, desc: 'String query for Nyaa Torrents search'
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
15
|
+
def call(mal_id:, search_query:, **)
|
16
|
+
db = Sequel.sqlite('dkb_edited.db')
|
17
|
+
show = db.from(:shows).where(mal_id: mal_id)
|
18
|
+
if show.count.positive?
|
19
|
+
old_query = show.first[:search_query]
|
20
|
+
show.update(search_query: search_query)
|
21
|
+
puts "Updated search query of #{show.first[:title]} (#{mal_id})"
|
22
|
+
puts "#{old_query} --> #{search_query}"
|
23
|
+
else
|
24
|
+
puts "ID #{mal_id} doesn't exist in the database."
|
30
25
|
end
|
31
26
|
end
|
32
|
-
|
33
27
|
end
|
28
|
+
|
34
29
|
end
|
35
30
|
end
|
36
31
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative '../../query'
|
4
|
-
require_relative '../../show_list'
|
5
4
|
|
6
5
|
module Organo
|
7
6
|
module CLI
|
@@ -10,13 +9,11 @@ module Organo
|
|
10
9
|
module Get
|
11
10
|
|
12
11
|
class Anime < Dry::CLI::Command
|
13
|
-
desc
|
14
|
-
argument :mal_id, type: :integer, required: true, desc:
|
12
|
+
desc 'Get anime with specific ID from API'
|
13
|
+
argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
|
15
14
|
|
16
15
|
def call(mal_id:, **)
|
17
|
-
|
18
|
-
show = SearchShow.new(json_obj['mal_id'], json_obj['title'], json_obj['images']['jpg']['image_url'])
|
19
|
-
puts show.to_json
|
16
|
+
puts Query.get_anime_by_id(mal_id)
|
20
17
|
end
|
21
18
|
end
|
22
19
|
|
@@ -1,5 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../../query'
|
2
|
-
require_relative '../../show_list'
|
3
4
|
|
4
5
|
module Organo
|
5
6
|
module CLI
|
@@ -13,9 +14,7 @@ module Organo
|
|
13
14
|
argument :year, type: :integer, required: true, desc: 'Year'
|
14
15
|
|
15
16
|
def call(season:, year:, **)
|
16
|
-
|
17
|
-
show_list = ShowList.create_search_show_list(json_obj)
|
18
|
-
puts show_list.to_json
|
17
|
+
puts Query.get_anime_season(season, year)
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative '../../query'
|
4
|
-
require_relative '../../show_list'
|
5
4
|
|
6
5
|
module Organo
|
7
6
|
module CLI
|
@@ -14,8 +13,7 @@ module Organo
|
|
14
13
|
argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
|
15
14
|
|
16
15
|
def call(mal_id:, **)
|
17
|
-
|
18
|
-
puts sequels.to_json
|
16
|
+
puts Query.get_anime_sequel(mal_id)
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
data/lib/organo/commands/init.rb
CHANGED
@@ -1,21 +1,43 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'sequel'
|
4
|
+
|
3
5
|
module Organo
|
4
6
|
module CLI
|
5
7
|
module Commands
|
6
8
|
|
7
9
|
class Init < Dry::CLI::Command
|
8
|
-
desc 'Initialize
|
10
|
+
desc 'Initialize database'
|
9
11
|
|
10
12
|
def call(*)
|
11
13
|
Dir.mkdir './.organo' unless File.exist?('./.organo')
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
|
15
|
+
db = Sequel.sqlite('dkb_edited.db')
|
16
|
+
unless db.table_exists?(:shows)
|
17
|
+
db.create_table(:shows) do
|
18
|
+
Integer :mal_id
|
19
|
+
String :slug, unique: true, null: true
|
20
|
+
String :title
|
21
|
+
String :img_url
|
22
|
+
String :search_query, null: true
|
23
|
+
Boolean :is_sequel
|
24
|
+
primary_key %i[mal_id]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
unless db.table_exists?(:sequels)
|
29
|
+
db.create_table(:sequels) do
|
30
|
+
Integer :parent_id
|
31
|
+
Integer :child_id
|
32
|
+
String :type, default: 'season'
|
33
|
+
Integer :type_num, default: 0
|
34
|
+
String :subtype, default: ''
|
35
|
+
Integer :subtype_num, default: 0
|
36
|
+
Integer :subtype_selector, default: -1
|
37
|
+
primary_key %i[parent_id child_id]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
19
41
|
end
|
20
42
|
end
|
21
43
|
|
@@ -1,14 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative '../../config'
|
4
|
-
require_relative '../../tools/check'
|
5
4
|
|
6
5
|
module Organo
|
7
6
|
module CLI
|
8
7
|
module Commands
|
9
8
|
module Remote
|
10
9
|
|
11
|
-
class
|
10
|
+
class AddEntry < Dry::CLI::Command
|
12
11
|
desc 'Add remote FTP server to config file'
|
13
12
|
argument :env, type: :string, required: true, desc: 'Remote environment name'
|
14
13
|
argument :url, type: :string, required: true, desc: 'FTP server url'
|
@@ -17,20 +16,17 @@ module Organo
|
|
17
16
|
option :directory, type: :string, default: '', desc: 'FTP directory'
|
18
17
|
|
19
18
|
def call(env:, url:, username:, password:, directory:, **)
|
20
|
-
|
21
|
-
config = File.exist?(Config::DEFAULT_FILE) ? JSON.parse(File.read(Config::DEFAULT_FILE)) : Array.new
|
19
|
+
config = File.exist?(Config::DEFAULT_FILE) ? JSON.parse(File.read(Config::DEFAULT_FILE)) : []
|
22
20
|
section = config.find { |option| option['section'] == 'remotes' }
|
23
21
|
remote = { env: env, url: url, username: username, password: password, directory: directory }
|
24
22
|
if section.nil?
|
25
|
-
section = { section: 'remotes', entries: []}
|
23
|
+
section = { section: 'remotes', entries: [] }
|
26
24
|
config.push(section)
|
27
25
|
section[:entries].push(remote)
|
26
|
+
elsif section['entries'].find { |entry| entry['env'] == env }.nil?
|
27
|
+
section['entries'].push(remote)
|
28
28
|
else
|
29
|
-
|
30
|
-
section['entries'].push(remote)
|
31
|
-
else
|
32
|
-
puts 'Environment name is already used'
|
33
|
-
end
|
29
|
+
puts 'Environment name is already used'
|
34
30
|
end
|
35
31
|
File.write(Config::DEFAULT_FILE, JSON.pretty_generate(config))
|
36
32
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'net/ftp'
|
4
|
-
require_relative '../../
|
4
|
+
require_relative '../../config'
|
5
5
|
|
6
6
|
module Organo
|
7
7
|
module CLI
|
@@ -13,7 +13,6 @@ module Organo
|
|
13
13
|
argument :env, type: :string, required: true, desc: 'Environment'
|
14
14
|
|
15
15
|
def call(env:, **)
|
16
|
-
Check.init?
|
17
16
|
config = File.exist?(Config::DEFAULT_FILE) ? JSON.parse(File.read(Config::DEFAULT_FILE)) : nil
|
18
17
|
section = config.find { |option| option['section'] == 'remotes' }
|
19
18
|
if section.nil?
|
@@ -26,11 +25,11 @@ module Organo
|
|
26
25
|
Net::FTP.open(credentials['url']) do |ftp|
|
27
26
|
ftp.login(credentials['username'], credentials['password'])
|
28
27
|
ftp.chdir(credentials['directory'])
|
29
|
-
if File.exist?('
|
30
|
-
File.delete('
|
31
|
-
File.rename('
|
28
|
+
if File.exist?('dkb_edited.db')
|
29
|
+
File.delete('dkb_edited.db.old') if File.exist?('dkb_edited.db.old')
|
30
|
+
File.rename('dkb_edited.db', 'dkb_edited.db.old')
|
32
31
|
end
|
33
|
-
ftp.getbinaryfile('
|
32
|
+
ftp.getbinaryfile('dkb_edited.db')
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative '../../config'
|
4
|
-
require_relative '../../tools/check'
|
5
4
|
|
6
5
|
module Organo
|
7
6
|
module CLI
|
@@ -13,7 +12,6 @@ module Organo
|
|
13
12
|
argument :env, type: :string, required: true, desc: 'Remote environment name'
|
14
13
|
|
15
14
|
def call(env:, **)
|
16
|
-
Check.init?
|
17
15
|
config = File.exist?(Config::DEFAULT_FILE) ? JSON.parse(File.read(Config::DEFAULT_FILE)) : nil
|
18
16
|
unless config.nil?
|
19
17
|
section = config.find { |option| option['section'] == 'remotes' }
|