pls 1.0.1 → 1.0.2
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 +4 -4
- data/lib/pls/configurator.rb +7 -1
- data/lib/pls/pls.rb +60 -2
- data/lib/pls/reporter.rb +11 -2
- data/lib/pls/version.rb +2 -2
- data/pls-1.0.1.gem +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a55f2a42f7d5e96e9d80497133efa1ddae26ac7932ad47c8f8d699d1048ae41d
|
4
|
+
data.tar.gz: 49220cdc6ce4be829fe6d644a66843370c81f28fab6c8d41db6897cac791f21a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53141d1535df3a8223d6a231b9417b35b6155d4468b247518930bbbafef3aa98970dc2ad5c7d09c6171dd40d7ef018013115714b350a9a61e21a72506c401db1
|
7
|
+
data.tar.gz: 4df66404b9923208a8eed7c548ce11a0cf85ef9fe8889d3c0a3715b5c6bad847d3f4fc7715f2b74ff041b9dbbaee080451bf68b7384ea60801b94025317a22f6
|
data/lib/pls/configurator.rb
CHANGED
@@ -22,16 +22,22 @@ module Pls
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def initialize
|
25
|
+
ARGV << '-h' if ARGV.empty?
|
25
26
|
@options = {}
|
26
27
|
OptionParser.new do |o|
|
27
28
|
o.banner = "Usage: #{File.basename($PROGRAM_NAME)} [options]."
|
28
29
|
DIC.each { |f, p, d, t, k| o.on(f, p, t, d) { |i| @options[k] = i } }
|
29
30
|
add(o)
|
30
31
|
end.parse!
|
32
|
+
raise 'Please specify a package name with -p flag.' if pac.nil?
|
31
33
|
end
|
32
34
|
|
33
|
-
def
|
35
|
+
def pac
|
34
36
|
@options[:pac]
|
35
37
|
end
|
38
|
+
|
39
|
+
def url
|
40
|
+
'https://registry.npmjs.org'
|
41
|
+
end
|
36
42
|
end
|
37
43
|
end
|
data/lib/pls/pls.rb
CHANGED
@@ -3,19 +3,77 @@
|
|
3
3
|
# vi:ts=2 sw=2 tw=79 et lbr wrap
|
4
4
|
# Copyright 2021 by David Rabkin
|
5
5
|
|
6
|
+
require 'httparty'
|
7
|
+
require 'json'
|
6
8
|
require_relative 'configurator'
|
7
9
|
require_relative 'reporter'
|
8
10
|
|
9
11
|
module Pls
|
10
|
-
#
|
12
|
+
# Data structure is hash, key - package name, val - array of hashes:
|
13
|
+
# {
|
14
|
+
# aaa => [
|
15
|
+
# bbb => [],
|
16
|
+
# ccc => [
|
17
|
+
# ddd => [],
|
18
|
+
# eee => []
|
19
|
+
# ]
|
20
|
+
# ]
|
21
|
+
# }
|
11
22
|
class Pls
|
12
23
|
def initialize
|
13
24
|
@cfg = Configurator.new
|
14
25
|
@rep = Reporter.new
|
26
|
+
@dat = {}
|
27
|
+
@mut_dat = Mutex.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def read_http(pac)
|
31
|
+
url = "#{@cfg.url}/#{pac}/latest"
|
32
|
+
res = HTTParty.get(url)
|
33
|
+
raise "Unable to continue with #{url}." unless res.code == 200
|
34
|
+
|
35
|
+
res.body
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_dep(dep) # rubocop:disable Metrics/MethodLength
|
39
|
+
arr = []
|
40
|
+
threads = []
|
41
|
+
mut = Mutex.new
|
42
|
+
dep.each_key do |pac|
|
43
|
+
threads << Thread.new(pac, arr) do |p, a|
|
44
|
+
dat = build(p)
|
45
|
+
mut.synchronize { a << dat }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
threads.each(&:join)
|
49
|
+
arr
|
50
|
+
end
|
51
|
+
|
52
|
+
# Consider time validation for cache data.
|
53
|
+
def read_cache(pac)
|
54
|
+
arr = []
|
55
|
+
@mut_dat.synchronize { arr = @dat[pac] }
|
56
|
+
arr
|
57
|
+
end
|
58
|
+
|
59
|
+
def write_cache(pac, arr)
|
60
|
+
@mut_dat.synchronize { @dat[pac] = arr }
|
61
|
+
end
|
62
|
+
|
63
|
+
def build(pac)
|
64
|
+
arr = read_cache(pac)
|
65
|
+
if arr.to_a.empty?
|
66
|
+
str = read_http(pac)
|
67
|
+
doc = JSON.parse(str)
|
68
|
+
dep = doc['dependencies']
|
69
|
+
arr = dep.to_a.empty? ? [] : build_dep(dep)
|
70
|
+
write_cache(pac, arr)
|
71
|
+
end
|
72
|
+
{ pac => arr }
|
15
73
|
end
|
16
74
|
|
17
75
|
def do
|
18
|
-
@rep.do
|
76
|
+
@rep.do(build(@cfg.pac))
|
19
77
|
end
|
20
78
|
end
|
21
79
|
end
|
data/lib/pls/reporter.rb
CHANGED
@@ -10,8 +10,17 @@ module Pls
|
|
10
10
|
@beg = Time.now.to_i
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
13
|
+
def out(pac, del)
|
14
|
+
key = pac.keys[0]
|
15
|
+
del.times { print ' ' }
|
16
|
+
print key
|
17
|
+
puts "\n"
|
18
|
+
pac[key].each { |sub| out(sub, del + 2) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def do(dat)
|
22
|
+
out(dat, 0)
|
23
|
+
puts "Done in #{Time.now.to_i - @beg} seconds."
|
15
24
|
end
|
16
25
|
end
|
17
26
|
end
|
data/lib/pls/version.rb
CHANGED
data/pls-1.0.1.gem
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Rabkin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pidfile
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/pls/pls.rb
|
87
87
|
- lib/pls/reporter.rb
|
88
88
|
- lib/pls/version.rb
|
89
|
+
- pls-1.0.1.gem
|
89
90
|
- pls.gemspec
|
90
91
|
homepage: https://github.com/rdavid/pls
|
91
92
|
licenses:
|