spandx 0.6.0 → 0.7.0
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/CHANGELOG.md +5 -1
- data/README.md +2 -2
- data/lib/spandx/cli/commands/index/build.rb +1 -1
- data/lib/spandx/dotnet/index.rb +59 -34
- data/lib/spandx/dotnet/nuget_gateway.rb +12 -8
- data/lib/spandx/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddd706dad19138c25501144fed49ae2148e7b5a703cdf06b9c4cd4bed4a940aa
|
4
|
+
data.tar.gz: c4596fdfa833988f80f7e3b17bce65e6fda8b8a0c059e441ff5b32583687b95d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8749463ff0bacbe4e125b9822c317d910dded8688e04122989777c42ac37b908f4c06a0419c824cde4698c7bab823934b751520fba786ca497b26ef9d266f9b7
|
7
|
+
data.tar.gz: 5229f971f6b36428ef9a09d3b91bab6f5b049f1312e12daee926bc27baf1f463e39204e30d69daa51566df3277712d901f8790871f3d272e0d353eea66dbaaa3
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Version 0.
|
1
|
+
Version 0.7.0
|
2
2
|
|
3
3
|
# Changelog
|
4
4
|
|
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
9
9
|
|
10
10
|
## [Unreleased]
|
11
11
|
|
12
|
+
## [0.7.0] - 2020-03-11
|
13
|
+
### Changed
|
14
|
+
- Improve how the `nuget` index is built.
|
15
|
+
|
12
16
|
## [0.6.0] - 2020-03-03
|
13
17
|
### Added
|
14
18
|
- Add `spandx index update` command to fetch the latest `spandx-rubygems` index.
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ Or install it yourself as:
|
|
25
25
|
To fetch the latest version of the catalogue data from [SPDX](https://spdx.org/licenses/licenses.json).
|
26
26
|
|
27
27
|
```ruby
|
28
|
-
catalogue = Spandx::Catalogue.latest
|
28
|
+
catalogue = Spandx::Spdx::Catalogue.latest
|
29
29
|
catalogue.each do |license|
|
30
30
|
puts license.inspect
|
31
31
|
end
|
@@ -35,7 +35,7 @@ To load an offline copy of the data.
|
|
35
35
|
|
36
36
|
```ruby
|
37
37
|
path = File.join(Dir.pwd, 'licenses.json')
|
38
|
-
catalogue = Spandx::Catalogue.from_file(path)
|
38
|
+
catalogue = Spandx::Spdx::Catalogue.from_file(path)
|
39
39
|
catalogue.each do |license|
|
40
40
|
puts license.inspect
|
41
41
|
end
|
data/lib/spandx/dotnet/index.rb
CHANGED
@@ -10,62 +10,87 @@ module Spandx
|
|
10
10
|
@directory = directory ? File.expand_path(directory) : DEFAULT_DIR
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
write([gateway.host, spec['id'], spec['version']], spec['licenseExpression'])
|
20
|
-
|
21
|
-
if limit
|
22
|
-
counter += 1
|
23
|
-
break if counter > limit
|
24
|
-
end
|
13
|
+
def licenses_for(name:, version:)
|
14
|
+
search_key = [name, version].join
|
15
|
+
open_data(name, mode: 'r') do |io|
|
16
|
+
found = io.readlines.bsearch { |x| search_key <=> [x[0], x[1]].join }
|
17
|
+
found ? found[2].split('-|-') : []
|
25
18
|
end
|
26
19
|
end
|
27
20
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
21
|
+
def update!(catalogue:, output: StringIO.new)
|
22
|
+
insert_latest(Spandx::Dotnet::NugetGateway.new(catalogue: catalogue)) do |page|
|
23
|
+
output.puts "Checkpoint #{page}"
|
24
|
+
checkpoint!(page)
|
25
|
+
end
|
26
|
+
sort_index!
|
34
27
|
end
|
35
28
|
|
36
|
-
|
37
|
-
return if data.nil? || data.empty?
|
29
|
+
private
|
38
30
|
|
39
|
-
|
40
|
-
|
31
|
+
def files(pattern)
|
32
|
+
Dir.glob(pattern, base: directory).sort.each do |file|
|
33
|
+
fullpath = File.join(directory, file)
|
34
|
+
yield fullpath unless File.directory?(fullpath)
|
41
35
|
end
|
42
36
|
end
|
43
37
|
|
44
|
-
|
38
|
+
def sort_index!
|
39
|
+
files('**/*') do |path|
|
40
|
+
IO.write(path, IO.readlines(path).sort.join)
|
41
|
+
end
|
42
|
+
end
|
45
43
|
|
46
44
|
def digest_for(components)
|
47
45
|
Digest::SHA1.hexdigest(Array(components).join('/'))
|
48
46
|
end
|
49
47
|
|
50
|
-
def open_data(
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
def open_data(name, mode: 'a')
|
49
|
+
data_dir = data_dir_for(name)
|
50
|
+
FileUtils.mkdir_p(data_dir)
|
51
|
+
CSV.open(data_file_for(name), mode, force_quotes: true) do |csv|
|
52
|
+
yield csv
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
57
|
-
def data_dir_for(
|
58
|
-
|
56
|
+
def data_dir_for(name)
|
57
|
+
digest = digest_for(name)
|
58
|
+
File.join(directory, digest[0...2].downcase)
|
59
59
|
end
|
60
60
|
|
61
|
-
def data_file_for(
|
62
|
-
File.join(data_dir_for(
|
61
|
+
def data_file_for(name)
|
62
|
+
File.join(data_dir_for(name), 'nuget')
|
63
63
|
end
|
64
64
|
|
65
|
-
def
|
66
|
-
|
65
|
+
def checkpoints_filepath
|
66
|
+
@checkpoints_filepath ||= File.join(directory, 'nuget.checkpoints')
|
67
|
+
end
|
67
68
|
|
68
|
-
|
69
|
+
def checkpoints
|
70
|
+
@checkpoints ||= File.exist?(checkpoints_filepath) ? JSON.parse(IO.read(checkpoints_filepath)) : {}
|
71
|
+
end
|
72
|
+
|
73
|
+
def checkpoint!(page)
|
74
|
+
checkpoints[page.to_s] = Time.now.utc
|
75
|
+
IO.write(checkpoints_filepath, JSON.pretty_generate(checkpoints))
|
76
|
+
end
|
77
|
+
|
78
|
+
def insert(id, version, license)
|
79
|
+
open_data(id) do |io|
|
80
|
+
io << [id, version, license]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def insert_latest(gateway)
|
85
|
+
current_page = nil
|
86
|
+
gateway.each do |spec, page|
|
87
|
+
next unless spec['licenseExpression']
|
88
|
+
break if checkpoints[page.to_s]
|
89
|
+
|
90
|
+
yield current_page if current_page && page != current_page
|
91
|
+
current_page = page
|
92
|
+
insert(spec['id'], spec['version'], spec['licenseExpression'])
|
93
|
+
end
|
69
94
|
end
|
70
95
|
end
|
71
96
|
end
|
@@ -21,10 +21,10 @@ module Spandx
|
|
21
21
|
guess_licenses_from(document)
|
22
22
|
end
|
23
23
|
|
24
|
-
def each
|
25
|
-
each_page do |
|
26
|
-
items_from(
|
27
|
-
yield
|
24
|
+
def each(page: Float::INFINITY)
|
25
|
+
each_page(start_page: page) do |page_json|
|
26
|
+
items_from(page_json).each do |item|
|
27
|
+
yield(fetch_json(item['@id']), page_number_from(page_json['@id']))
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -33,11 +33,11 @@ module Spandx
|
|
33
33
|
|
34
34
|
attr_reader :http, :guess
|
35
35
|
|
36
|
-
def each_page
|
36
|
+
def each_page(start_page:)
|
37
37
|
url = "https://#{host}/v3/catalog0/index.json"
|
38
|
-
items_from(fetch_json(url))
|
39
|
-
|
40
|
-
|
38
|
+
items_from(fetch_json(url))
|
39
|
+
.find_all { |page| page_number_from(page['@id']) <= start_page }
|
40
|
+
.each { |page| yield fetch_json(page['@id']) }
|
41
41
|
end
|
42
42
|
|
43
43
|
def nuspec_url_for(name, version)
|
@@ -86,6 +86,10 @@ module Spandx
|
|
86
86
|
.sort_by { |x| x['commitTimeStamp'] }
|
87
87
|
.reverse
|
88
88
|
end
|
89
|
+
|
90
|
+
def page_number_from(url)
|
91
|
+
url.match(/page(?<page_number>\d+)\.json/)[:page_number].to_i
|
92
|
+
end
|
89
93
|
end
|
90
94
|
end
|
91
95
|
end
|
data/lib/spandx/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spandx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mo khan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|