license_auto 0.1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +47 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile +27 -0
- data/Gemfile.lock +103 -0
- data/LICENSE +23 -0
- data/README.md +136 -0
- data/Rakefile +20 -0
- data/examples/get_license_files_of_bundler.rb +12 -0
- data/lib/api.rb +60 -0
- data/lib/api/bitbucket.rb +142 -0
- data/lib/api/code_google_com.rb +66 -0
- data/lib/api/excel_export.rb +189 -0
- data/lib/api/gem_data.rb +30 -0
- data/lib/api/git_kernel_org.rb +59 -0
- data/lib/api/github.rb +376 -0
- data/lib/api/go_pkg_in.rb +41 -0
- data/lib/api/golang_org.rb +63 -0
- data/lib/api/google_source_com.rb +68 -0
- data/lib/api/gradle2.rb +41 -0
- data/lib/api/helper.rb +26 -0
- data/lib/api/j_center.rb +23 -0
- data/lib/api/maven_central_repository.rb +192 -0
- data/lib/api/mq.rb +30 -0
- data/lib/api/npm_registry.rb +169 -0
- data/lib/api/pattern.rb +33 -0
- data/lib/api/remote_source_package.rb +319 -0
- data/lib/api/spider.rb +47 -0
- data/lib/cloner.rb +154 -0
- data/lib/db.rb +267 -0
- data/lib/license_auto.rb +20 -0
- data/lib/license_auto/config/config.rb +52 -0
- data/lib/license_auto/errors.rb +0 -0
- data/lib/license_auto/license/frequency.rb +30 -0
- data/lib/license_auto/license/similarity.rb +247 -0
- data/lib/license_auto/license/templates/AFL2.0.txt +43 -0
- data/lib/license_auto/license/templates/AFL2.1.txt +47 -0
- data/lib/license_auto/license/templates/AFL3.0.txt +45 -0
- data/lib/license_auto/license/templates/AGPL3.0.txt +236 -0
- data/lib/license_auto/license/templates/APSL 2.0.txt +100 -0
- data/lib/license_auto/license/templates/Apache1.0.txt +18 -0
- data/lib/license_auto/license/templates/Apache1.1.txt +18 -0
- data/lib/license_auto/license/templates/Apache2.0.txt +201 -0
- data/lib/license_auto/license/templates/Artistic1.0.txt +45 -0
- data/lib/license_auto/license/templates/Artistic2.0.txt +70 -0
- data/lib/license_auto/license/templates/BSD.txt +29 -0
- data/lib/license_auto/license/templates/CDDL1.0.txt +1 -0
- data/lib/license_auto/license/templates/CDDL1.1.txt +209 -0
- data/lib/license_auto/license/templates/CPL1.0.txt +211 -0
- data/lib/license_auto/license/templates/CPOL 1.02.txt +41 -0
- data/lib/license_auto/license/templates/ClarifiedArtistic.txt +140 -0
- data/lib/license_auto/license/templates/Creative Commons1.0.txt +28 -0
- data/lib/license_auto/license/templates/EPL1.0.txt +70 -0
- data/lib/license_auto/license/templates/ERLANG1.1.txt +286 -0
- data/lib/license_auto/license/templates/GFDL1.1.txt +101 -0
- data/lib/license_auto/license/templates/GFDL1.2.txt +108 -0
- data/lib/license_auto/license/templates/GFDL1.3.txt +116 -0
- data/lib/license_auto/license/templates/GPL1.0.txt +105 -0
- data/lib/license_auto/license/templates/GPL2.0.txt +340 -0
- data/lib/license_auto/license/templates/GPL3.0.txt +220 -0
- data/lib/license_auto/license/templates/H2.txt +118 -0
- data/lib/license_auto/license/templates/IBMPublic1.0.txt +58 -0
- data/lib/license_auto/license/templates/LGPL2.0.txt +481 -0
- data/lib/license_auto/license/templates/LGPL2.1.txt +166 -0
- data/lib/license_auto/license/templates/LGPL3.0.txt +56 -0
- data/lib/license_auto/license/templates/Lucent Public License 1.02.txt +244 -0
- data/lib/license_auto/license/templates/MIT.txt +21 -0
- data/lib/license_auto/license/templates/MIT2.0.txt +11 -0
- data/lib/license_auto/license/templates/MPL 2.0.txt +373 -0
- data/lib/license_auto/license/templates/MPL1.1.txt +470 -0
- data/lib/license_auto/license/templates/MS-LPL.txt +22 -0
- data/lib/license_auto/license/templates/MS-PL.txt +20 -0
- data/lib/license_auto/license/templates/MS-RL.txt +19 -0
- data/lib/license_auto/license/templates/NPL1.0.txt +138 -0
- data/lib/license_auto/license/templates/OpenSSL.txt +127 -0
- data/lib/license_auto/license/templates/Oracle license.txt +69 -0
- data/lib/license_auto/license/templates/PublicDomain.txt +7 -0
- data/lib/license_auto/license/templates/Python.txt +15 -0
- data/lib/license_auto/license/templates/QPL1.0.txt +45 -0
- data/lib/license_auto/license/templates/RubyClause-6.txt +56 -0
- data/lib/license_auto/license/templates/SQLite Copyright.txt +33 -0
- data/lib/license_auto/license/templates/Sleepycat.txt +133 -0
- data/lib/license_auto/license/templates/SunPublic1.0.txt +183 -0
- data/lib/license_auto/license/templates/WTFPL license.txt +13 -0
- data/lib/license_auto/license_info.rb +12 -0
- data/lib/license_auto/matcher.rb +100 -0
- data/lib/license_auto/package.rb +73 -0
- data/lib/license_auto/parser/gemfile.rb +0 -0
- data/lib/license_auto/parser/golang.rb +0 -0
- data/lib/license_auto/parser/gradle.rb +0 -0
- data/lib/license_auto/version.rb +20 -0
- data/lib/license_auto/website.rb +11 -0
- data/lib/license_auto/website/github.rb +49 -0
- data/lib/license_auto/website/ruby_gems_org.rb +79 -0
- data/lib/license_auto/website/ruby_gems_org_db.rb +52 -0
- data/lib/license_auto/website/rubydoc_info.rb +12 -0
- data/lib/message.rb +5 -0
- data/lib/misc.rb +131 -0
- data/lib/parser/enums.rb +161 -0
- data/lib/parser/gemfile_parser.rb +221 -0
- data/lib/parser/golang_parser.rb +104 -0
- data/lib/parser/gradle_parser.rb +141 -0
- data/lib/parser/manifest_parser.rb +66 -0
- data/lib/parser/maven_parser.rb +91 -0
- data/lib/parser/npm_parser.rb +82 -0
- data/lib/parser/pip_parser.rb +1 -0
- data/lib/parser/rebar_parser.rb +61 -0
- data/lib/recorder.rb +184 -0
- data/lib/script/apt-get.deps.sh +37 -0
- data/lib/script/debian_dpkg_list.sh +2 -0
- data/lib/script/rubygems.org.importdb.sh +22 -0
- data/license_auto.gemspec +44 -0
- data/remove/license_auto +4 -0
- data/remove/mq_pack.rb +219 -0
- data/remove/mq_repo.rb +106 -0
- metadata +249 -0
data/lib/recorder.rb
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'csv'
|
3
|
+
require 'json'
|
4
|
+
require_relative '../config/config'
|
5
|
+
require_relative './api'
|
6
|
+
|
7
|
+
class PacksSaver
|
8
|
+
def initialize(repo_id, packs, lang, release_id)
|
9
|
+
@release_id = release_id
|
10
|
+
@repo_id = repo_id
|
11
|
+
@packs = packs
|
12
|
+
@lang = lang
|
13
|
+
end
|
14
|
+
|
15
|
+
def save()
|
16
|
+
if @lang == 'Golang'
|
17
|
+
save_golang
|
18
|
+
elsif @lang == 'Ruby'
|
19
|
+
save_ruby
|
20
|
+
elsif @lang == 'manifest.yml' or @lang == 'NodeJs' or @lang == 'Erlang'
|
21
|
+
save_manifest
|
22
|
+
elsif @lang == 'Gradle'
|
23
|
+
save_gradle
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def save_gradle
|
28
|
+
@packs.each {|pack|
|
29
|
+
begin
|
30
|
+
$plog.debug(pack)
|
31
|
+
pack_name = [pack[:group], pack[:name]].join(':')
|
32
|
+
pack_version = pack[:version]
|
33
|
+
status = 10
|
34
|
+
homepage, source_url = nil, pack['uri']
|
35
|
+
license, cmt = nil, nil
|
36
|
+
|
37
|
+
pg_result = api_add_pack(pack_name, pack_version, @lang, homepage, source_url, license, status, cmt)
|
38
|
+
enqueue_result(pg_result)
|
39
|
+
rescue Exception => _
|
40
|
+
$plog.error(_)
|
41
|
+
end
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def save_manifest
|
46
|
+
@packs.each {|pack|
|
47
|
+
begin
|
48
|
+
$plog.debug(pack)
|
49
|
+
pack_name, pack_version, status = pack['name'], pack['version'], 10
|
50
|
+
homepage, source_url = nil, pack['uri']
|
51
|
+
license, cmt = nil, nil
|
52
|
+
|
53
|
+
pg_result = api_add_pack(pack_name, pack_version, @lang, homepage, source_url, license, status, cmt)
|
54
|
+
enqueue_result(pg_result)
|
55
|
+
rescue Exception => _
|
56
|
+
$plog.error(_)
|
57
|
+
end
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
def save_ruby
|
62
|
+
def license_name_format(origin_license)
|
63
|
+
if origin_license.nil?
|
64
|
+
return nil
|
65
|
+
end
|
66
|
+
empty_pattern = /---\s\[\]\n/
|
67
|
+
license = origin_license.gsub(empty_pattern, '').gsub(/---\s\n[\.]+\n/, '').gsub(/---\n-\s/, '').gsub(/\n/, '').gsub(/['"\s]+$/, '').gsub(/^['"\s]+/, '')
|
68
|
+
if license.empty?
|
69
|
+
return nil
|
70
|
+
else
|
71
|
+
return license
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
@packs.each {|pack|
|
76
|
+
begin
|
77
|
+
pack[:license] = license_name_format(pack[:license])
|
78
|
+
# $plog.debug(pack)
|
79
|
+
pack_name, pack_version, status = pack[:pack_name], pack[:pack_version], pack[:status]
|
80
|
+
homepage, source_url = pack[:homepage], pack[:source_url]
|
81
|
+
# lang is a website in act
|
82
|
+
license, cmt, lang = pack[:license], pack[:cmt], pack[:language]
|
83
|
+
|
84
|
+
pg_result = api_add_pack(pack_name, pack_version, lang, homepage, source_url, license, status, cmt)
|
85
|
+
enqueue_result(pg_result)
|
86
|
+
rescue Exception => _
|
87
|
+
$plog.error(_)
|
88
|
+
end
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
# 处理api_add_pack()返回的结果
|
93
|
+
def enqueue_result(pg_result)
|
94
|
+
begin
|
95
|
+
if pg_result != nil
|
96
|
+
pack_id = pg_result['pack_id'].to_i
|
97
|
+
is_newbie = pg_result['is_newbie'] == 't'
|
98
|
+
api_add_product_repo_pack(@repo_id, pack_id, @release_id)
|
99
|
+
|
100
|
+
if is_newbie
|
101
|
+
queue_name = 'license_auto.pack'
|
102
|
+
$rmq.publish(queue_name, {:pack_id => pack_id}.to_json, check_exist=true)
|
103
|
+
end
|
104
|
+
$plog.debug("pack_id: #{pack_id}, is_newbie: #{is_newbie}")
|
105
|
+
else
|
106
|
+
$plog.error("#{pack_url} insert failed!")
|
107
|
+
end
|
108
|
+
rescue Exception => _
|
109
|
+
$plog.error(_)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def save_golang()
|
114
|
+
@packs.each { |pack_name, pack_url|
|
115
|
+
begin
|
116
|
+
$plog.debug("save_golange: #{pack_url}")
|
117
|
+
|
118
|
+
pack_version = 'unknown'
|
119
|
+
homepage = nil
|
120
|
+
source_url = nil
|
121
|
+
status = 10
|
122
|
+
cmt = nil
|
123
|
+
|
124
|
+
remote = API::RemoteSourceVCS.new(pack_url)
|
125
|
+
|
126
|
+
if remote.vcs == nil
|
127
|
+
status = 30
|
128
|
+
cmt = 'Unknown repo site'
|
129
|
+
pack_name = pack_name.split('/').last
|
130
|
+
else
|
131
|
+
pack_name = remote.vcs.repo
|
132
|
+
source_url = remote.vcs.repo_url
|
133
|
+
homepage = remote.get_homepage
|
134
|
+
last_commit = remote.vcs.last_commits
|
135
|
+
if last_commit
|
136
|
+
pack_version = last_commit['sha']
|
137
|
+
end
|
138
|
+
end
|
139
|
+
# $plog.debug("#{pack_version}, #{pack_url}")
|
140
|
+
license = nil
|
141
|
+
pg_result = api_add_pack(pack_name, pack_version, 'Golang', homepage, source_url, license, status, cmt)
|
142
|
+
enqueue_result(pg_result)
|
143
|
+
rescue Exception => _
|
144
|
+
$plog.error(_)
|
145
|
+
end
|
146
|
+
}
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
class PackUpdate
|
152
|
+
def initialize(pack_id, pack)
|
153
|
+
@pack_id = pack_id
|
154
|
+
@pack = pack
|
155
|
+
end
|
156
|
+
|
157
|
+
def update()
|
158
|
+
ok = api_update_pack_info(@pack_id, @pack)
|
159
|
+
end
|
160
|
+
|
161
|
+
def self.judge_pack_status(packer)
|
162
|
+
# TODO: @Micfan test it
|
163
|
+
if is_std_license(packer[:license]) and ( packer[:license_url] or packer[:license_text])
|
164
|
+
packer[:unclear_license] = nil
|
165
|
+
packer[:status] = 40
|
166
|
+
else
|
167
|
+
packer[:unclear_license] = packer[:license]
|
168
|
+
packer[:license] = nil
|
169
|
+
packer[:status] = 30
|
170
|
+
end
|
171
|
+
return packer
|
172
|
+
end
|
173
|
+
|
174
|
+
def self.is_std_license(license)
|
175
|
+
where = "where name = '#{license}'"
|
176
|
+
std_licenses = api_get_std_license_name(where)
|
177
|
+
return std_licenses.ntuples == 1
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
if __FILE__ == $0
|
183
|
+
p PackUpdate.is_std_license('MIT')
|
184
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
cat /root/.bash_profile
|
4
|
+
export license_auto_rabbit_mq="amqp://guest:guest@localhost:5672"
|
5
|
+
export github_username=Your Github Username
|
6
|
+
# https://help.github.com/articles/creating-an-access-token-for-command-line-use/
|
7
|
+
export github_password=Your Github Personal access tokens
|
8
|
+
export license_auto_proxy='proxy.foo.com:8080'
|
9
|
+
|
10
|
+
apt-get install -y rabbitmq-server \
|
11
|
+
libpq-dev build-essential \
|
12
|
+
libxml2 \
|
13
|
+
libxslt bzip2 cmake golang \
|
14
|
+
rebar gradle maven
|
15
|
+
|
16
|
+
# If mac osx
|
17
|
+
# brew install icu4c
|
18
|
+
|
19
|
+
rabbitmq-plugins enable rabbitmq_management
|
20
|
+
rabbitmqctl stop # 停止Erlang节点
|
21
|
+
service rabbitmq-server start # 启动Erlang节点
|
22
|
+
|
23
|
+
bundle install
|
24
|
+
|
25
|
+
pip install -r ../requirements.txt
|
26
|
+
cp conf/supervisord.conf /etc/supervisord.conf
|
27
|
+
supervisord
|
28
|
+
|
29
|
+
cp conf/.git-credentials ~/.git-credentials
|
30
|
+
git config --global credential.helper 'store --file ~/.git-credentials'
|
31
|
+
git config --global http.proxy http://proxy.mycompany:80
|
32
|
+
|
33
|
+
npm install -g semver
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
|
4
|
+
su postgres
|
5
|
+
cd ~
|
6
|
+
# TODO: write a Ruby spider to auto
|
7
|
+
wget https://s3-us-west-2.amazonaws.com/rubygems-dumps/production/public_postgresql/2015.09.07.21.21.02/public_postgresql.tar
|
8
|
+
|
9
|
+
tar -xvf public_postgresql.tar
|
10
|
+
gunzip public_postgresql/databases/PostgreSQL.sql.gz
|
11
|
+
|
12
|
+
rm -rf public_postgresql*
|
13
|
+
|
14
|
+
sql_filename=public_postgresql/databases/PostgreSQL.sql
|
15
|
+
|
16
|
+
dbname=gemData
|
17
|
+
dropdb $dbname
|
18
|
+
createdb $dbname
|
19
|
+
psql $dbname -c 'create extension hstore;'
|
20
|
+
|
21
|
+
psql $dbname < $sql_filename
|
22
|
+
echo 'OK'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'license_auto/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "license_auto"
|
8
|
+
spec.version = LicenseAuto::VERSION::STRING
|
9
|
+
spec.authors = ['MineWorks']
|
10
|
+
spec.email = [""]
|
11
|
+
|
12
|
+
spec.summary = %q{License Automation Toolkit}
|
13
|
+
spec.description = %q{LicenseAuto is a library for Open Source License collection job. Supported Language Package
|
14
|
+
Management including:
|
15
|
+
Ruby Gems, Java Maven Gradle, NodeJS npm, Erlang rebar, Debian launchpad.net, Golang}
|
16
|
+
|
17
|
+
spec.homepage = "https://github.com/mineworks/license_auto"
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
spec.metadata = {
|
21
|
+
'repository_url' => 'https://github.com/mineworks/license_auto.git'
|
22
|
+
}
|
23
|
+
|
24
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
25
|
+
# delete this section to allow pushing this gem to any host.
|
26
|
+
if spec.respond_to?(:metadata)
|
27
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
28
|
+
else
|
29
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
30
|
+
end
|
31
|
+
|
32
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
spec.bindir = "bin"
|
34
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
|
+
spec.require_paths = ["lib"]
|
36
|
+
|
37
|
+
spec.add_runtime_dependency "hashie"
|
38
|
+
spec.add_runtime_dependency "json"
|
39
|
+
spec.add_runtime_dependency "gems"
|
40
|
+
spec.add_runtime_dependency "github_api"
|
41
|
+
|
42
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
43
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
44
|
+
end
|
data/remove/license_auto
ADDED
data/remove/mq_pack.rb
ADDED
@@ -0,0 +1,219 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require File.expand_path('../config/environment', __FILE__)
|
5
|
+
|
6
|
+
if ENV['RACK_ENV'] == 'development'
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
require_relative '../lib/cloner'
|
12
|
+
require_relative '../lib/db'
|
13
|
+
require_relative '../lib/recorder'
|
14
|
+
require_relative '../lib/api'
|
15
|
+
require_relative '../config/config'
|
16
|
+
require_relative '../lib/api'
|
17
|
+
|
18
|
+
def fetch_license_info_by_source(packer, status=nil)
|
19
|
+
# TODO: @Micfan, simple it
|
20
|
+
source_url = packer[:source_url]
|
21
|
+
homepage = packer[:homepage]
|
22
|
+
github_pattern = API::SOURCE_URL_PATTERN[:github]
|
23
|
+
if source_url =~ github_pattern
|
24
|
+
github_url = source_url
|
25
|
+
elsif homepage =~ github_pattern
|
26
|
+
github_url = homepage
|
27
|
+
else
|
28
|
+
github_url = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
# $plog.debug("github_url: #{github_url}")
|
32
|
+
|
33
|
+
bitbucket_url = nil
|
34
|
+
bitbucket_pattern = /http[s]?:\/\/bitbucket\.org/
|
35
|
+
if source_url =~ bitbucket_pattern
|
36
|
+
bitbucket_url = source_url
|
37
|
+
elsif homepage =~ bitbucket_pattern
|
38
|
+
bitbucket_url = homepage
|
39
|
+
else
|
40
|
+
bitbucket_url = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
license_info = {:license => nil, :license_text => nil, :license_url => nil}
|
44
|
+
if github_url != nil
|
45
|
+
packer[:source_url] = github_url
|
46
|
+
|
47
|
+
# 1. find a version tag, if version tag not exists, go to default branch
|
48
|
+
# 2. if license file not found in a version tag, go to default branch
|
49
|
+
extractor = API::Github.new(github_url, db_ref=packer[:version])
|
50
|
+
license_info = extractor.get_license_info
|
51
|
+
if license_info[:license_url] == nil
|
52
|
+
default_branch, switched = extractor.switch_to_default_branch
|
53
|
+
if switched
|
54
|
+
license_info = extractor.get_license_info
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
packer = packer.merge(license_info)
|
59
|
+
elsif bitbucket_url != nil
|
60
|
+
packer[:source_url] = bitbucket_url
|
61
|
+
extractor = API::Bitbucket.new(bitbucket_url)
|
62
|
+
license_info = extractor.get_license_info
|
63
|
+
packer = packer.merge(license_info)
|
64
|
+
end
|
65
|
+
|
66
|
+
if status
|
67
|
+
packer[:status] = status
|
68
|
+
else
|
69
|
+
packer = PackUpdate.judge_pack_status(packer)
|
70
|
+
end
|
71
|
+
|
72
|
+
return packer
|
73
|
+
end
|
74
|
+
|
75
|
+
def worker(body)
|
76
|
+
begin
|
77
|
+
pack_item = JSON.parse(body)
|
78
|
+
pack_id = pack_item['pack_id']
|
79
|
+
pack = api_get_pack_by_id(pack_id)
|
80
|
+
if pack.nil?
|
81
|
+
status = 20
|
82
|
+
cmt = "Package not found, pack_id: #{pack_id}"
|
83
|
+
api_setup_pack_status(pack_id, status, cmt)
|
84
|
+
$plog.fatal(cmt)
|
85
|
+
return
|
86
|
+
else
|
87
|
+
_status = pack['status'].to_i
|
88
|
+
if _status >= 30
|
89
|
+
info = "This package(pack_id=#{pack_id}, status=#{_status}) have no permission to self run"
|
90
|
+
$plog.info(info)
|
91
|
+
return
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
$plog.debug("pack: #{pack}")
|
96
|
+
|
97
|
+
lang = pack['lang']
|
98
|
+
|
99
|
+
packer = {
|
100
|
+
:version => pack['version'],
|
101
|
+
:source_url => pack['source_url'],
|
102
|
+
:license_url => pack['license_url'],
|
103
|
+
:homepage => pack['homepage'],
|
104
|
+
:license => pack['license'],
|
105
|
+
:license_text => pack['license_text'],
|
106
|
+
# TODO: this status should rethink
|
107
|
+
:status => 30
|
108
|
+
}
|
109
|
+
packer = fetch_license_info_by_source(packer)
|
110
|
+
if packer[:status] < 40 and packer[:source_url] == nil
|
111
|
+
if lang =~ API::OS_PATTERN[:ubuntu]
|
112
|
+
ubuntu_lang_pattern = API::OS_PATTERN[:ubuntu]
|
113
|
+
lang_group = ubuntu_lang_pattern.match(lang)
|
114
|
+
launchpad = API::Launchpad.new(lang_group[:distribution].downcase, lang_group[:distro_series].downcase,
|
115
|
+
pack['name'].split(':').first, pack['version'])
|
116
|
+
license_info = launchpad.fetch_license_info_from_local_source
|
117
|
+
packer = packer.merge(license_info)
|
118
|
+
packer = PackUpdate.judge_pack_status(packer)
|
119
|
+
elsif lang =~ API::OS_PATTERN[:centos]
|
120
|
+
# *.rpm, $yum
|
121
|
+
elsif lang == 'Gradle'
|
122
|
+
gropu_id, name_id = pack['name'].split(':')
|
123
|
+
m = API::MavenCentralRepository.new(gropu_id, name_id, pack['version'])
|
124
|
+
license_info = m.get_license_info
|
125
|
+
packer = packer.merge(license_info)
|
126
|
+
if license_info[:licenses].size > 0
|
127
|
+
# TODO: multi license
|
128
|
+
packer = packer.merge(license_info[:licenses][0])
|
129
|
+
end
|
130
|
+
packer = PackUpdate.judge_pack_status(packer)
|
131
|
+
elsif lang == 'NodeJs'
|
132
|
+
registry = API::NpmRegistry.new(pack['name'], pack['version'])
|
133
|
+
license_info = registry.get_license_info
|
134
|
+
packer = packer.merge(license_info)
|
135
|
+
packer = PackUpdate.judge_pack_status(packer)
|
136
|
+
if packer[:status] < 40 and packer[:status] >= 30
|
137
|
+
source_license_info = fetch_license_info_by_source(packer)
|
138
|
+
packer = packer.merge(source_license_info)
|
139
|
+
if packer[:license].nil?
|
140
|
+
packer[:license] = license_info[:license]
|
141
|
+
end
|
142
|
+
packer = PackUpdate.judge_pack_status(packer)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
elsif lang == 'manifest.yml'
|
146
|
+
source_code_download_url = api_get_manifest_download_url(pack_id)[0]['source_url']
|
147
|
+
if source_code_download_url == nil
|
148
|
+
raise "pack_id(#{pack_id}) source_url is null"
|
149
|
+
else
|
150
|
+
manifest = API::ManifestPackage.new(source_code_download_url)
|
151
|
+
license_info = manifest.fetch_license_info_from_local_source
|
152
|
+
packer = packer.merge(license_info)
|
153
|
+
packer = PackUpdate.judge_pack_status(packer)
|
154
|
+
end
|
155
|
+
else
|
156
|
+
$plog.info("packer: #{packer}")
|
157
|
+
# TODO: def is_github_source_url
|
158
|
+
if (packer[:source_url] =~ API::SOURCE_URL_PATTERN[:github]).nil? and packer[:homepage] != nil
|
159
|
+
$plog.info("Homepage Spider working: #{packer[:homepage]}")
|
160
|
+
spider_source_url = API::Spider.new(packer[:homepage], pack['name']).find_source_url
|
161
|
+
$plog.debug("spider_source_url: #{spider_source_url}")
|
162
|
+
if spider_source_url
|
163
|
+
packer[:source_url] = spider_source_url
|
164
|
+
packer = fetch_license_info_by_source(packer, status=31)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
$plog.error("!!! Unresolved pack: #{pack}")
|
168
|
+
end
|
169
|
+
|
170
|
+
updater = PackUpdate.new(pack_id, packer)
|
171
|
+
flag = updater.update()
|
172
|
+
if flag
|
173
|
+
$plog.info("update success: pack_id: #{pack_id}, packer: #{packer}")
|
174
|
+
else
|
175
|
+
$plog.info("!!! update failed: pack_id: #{pack_id}, packer: #{packer}")
|
176
|
+
end
|
177
|
+
rescue Git::GitExecuteError => e
|
178
|
+
$plog.fatal(e)
|
179
|
+
api_setup_pack_status(pack_id, 21, e.to_s)
|
180
|
+
rescue OpenSSL::SSL::SSLError => e
|
181
|
+
$plog.fatal(e)
|
182
|
+
api_setup_pack_status(pack_id, 22, e.to_s)
|
183
|
+
rescue Exception => e
|
184
|
+
api_setup_pack_status(pack_id, 20, e.to_s)
|
185
|
+
$plog.fatal(e)
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
def main()
|
191
|
+
conn = Bunny.new
|
192
|
+
conn.start
|
193
|
+
|
194
|
+
ch = conn.create_channel
|
195
|
+
q = ch.queue("license_auto.pack", :durable => true)
|
196
|
+
|
197
|
+
ch.prefetch(1)
|
198
|
+
puts " [*] MQ-pack: Waiting for messages. To exit press CTRL+C"
|
199
|
+
|
200
|
+
begin
|
201
|
+
q.subscribe(:manual_ack => true, :block => true) do |delivery_info, properties, body|
|
202
|
+
puts " [x] MQ-pack: Received '#{body}'"
|
203
|
+
|
204
|
+
worker(body)
|
205
|
+
sleep 1.0
|
206
|
+
puts " [x] MQ-pack: Done"
|
207
|
+
ch.ack(delivery_info.delivery_tag)
|
208
|
+
end
|
209
|
+
rescue Interrupt => _
|
210
|
+
conn.close
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
if __FILE__ == $0
|
215
|
+
# pack_id = 1796
|
216
|
+
# body = '{"pack_id":' + "#{pack_id}}"
|
217
|
+
# worker(body)
|
218
|
+
main
|
219
|
+
end
|