license_auto 0.1.1.2 → 0.1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitmodules +3 -0
- data/.travis.yml +9 -2
- data/README.md +10 -8
- data/lib/license_auto/exceptions.rb +10 -0
- data/lib/license_auto/license/frequency.rb +1 -1
- data/lib/license_auto/license/readme.rb +21 -2
- data/lib/license_auto/license/similarity.rb +4 -3
- data/lib/license_auto/license_info_wrapper.rb +16 -0
- data/lib/license_auto/matcher.rb +14 -4
- data/lib/license_auto/package.rb +29 -15
- data/lib/license_auto/package_manager.rb +6 -2
- data/lib/license_auto/package_manager/bundler.rb +10 -6
- data/lib/license_auto/package_manager/gemfury.rb +2 -0
- data/lib/license_auto/package_manager/git_module.rb +73 -0
- data/lib/license_auto/package_manager/golang.rb +155 -0
- data/lib/license_auto/package_manager/gradle.rb +145 -0
- data/lib/license_auto/package_manager/maven.rb +133 -0
- data/lib/license_auto/package_manager/npm.rb +117 -1
- data/lib/license_auto/package_manager/pip.rb +8 -2
- data/lib/license_auto/repo.rb +51 -3
- data/lib/license_auto/source_code_server.rb +13 -0
- data/lib/license_auto/var/golang_std_libs.rb +160 -0
- data/lib/license_auto/version.rb +1 -1
- data/lib/license_auto/website.rb +1 -0
- data/lib/license_auto/website/cocoapods_org.rb +10 -0
- data/lib/license_auto/website/github_com.rb +43 -18
- data/lib/license_auto/website/homepage_spider.rb +56 -0
- data/lib/license_auto/website/maven_central_repository.rb +258 -0
- data/lib/license_auto/website/npm_registry.rb +178 -0
- data/lib/license_auto/website/ruby_gems_org.rb +119 -8
- data/license_auto.gemspec +1 -0
- data/package.json +30 -0
- metadata +25 -40
- data/lib/license_auto/package_manager/golang_stdlibs.rb +0 -161
- data/remove/api.rb +0 -60
- data/remove/api/bitbucket.rb +0 -142
- data/remove/api/code_google_com.rb +0 -66
- data/remove/api/excel_export.rb +0 -189
- data/remove/api/gem_data.rb +0 -30
- data/remove/api/git_kernel_org.rb +0 -59
- data/remove/api/github.rb +0 -376
- data/remove/api/go_pkg_in.rb +0 -41
- data/remove/api/golang_org.rb +0 -63
- data/remove/api/google_source_com.rb +0 -68
- data/remove/api/gradle2.rb +0 -41
- data/remove/api/helper.rb +0 -26
- data/remove/api/j_center.rb +0 -23
- data/remove/api/maven_central_repository.rb +0 -192
- data/remove/api/mq.rb +0 -30
- data/remove/api/npm_registry.rb +0 -169
- data/remove/api/pattern.rb +0 -33
- data/remove/api/remote_source_package.rb +0 -319
- data/remove/api/spider.rb +0 -47
- data/remove/cloner.rb +0 -154
- data/remove/db.rb +0 -267
- data/remove/license_auto +0 -4
- data/remove/misc.rb +0 -131
- data/remove/mq_pack.rb +0 -219
- data/remove/mq_repo.rb +0 -106
- data/remove/parser/gemfile_parser.rb +0 -221
- data/remove/parser/golang_parser.rb +0 -104
- data/remove/parser/gradle_parser.rb +0 -141
- data/remove/parser/manifest_parser.rb +0 -66
- data/remove/parser/maven_parser.rb +0 -91
- data/remove/parser/npm_parser.rb +0 -82
- data/remove/parser/pip_parser.rb +0 -1
- data/remove/parser/rebar_parser.rb +0 -61
- data/remove/recorder.rb +0 -184
- data/remove/script/apt-get.deps.sh +0 -37
- data/remove/script/debian_dpkg_list.sh +0 -2
- data/remove/script/rubygems.org.importdb.sh +0 -22
data/remove/api/mq.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'bunny'
|
2
|
-
|
3
|
-
module API
|
4
|
-
|
5
|
-
class RabbitMQ
|
6
|
-
# "amqp://guest:guest@localhost:5672"
|
7
|
-
def initialize(rabbit_mq_conn_str)
|
8
|
-
@conn = Bunny.new(rabbit_mq_conn_str)
|
9
|
-
@conn.start
|
10
|
-
@ch = @conn.create_channel
|
11
|
-
end
|
12
|
-
|
13
|
-
def publish(queue_name, message, auto_release=true, durable=true, check_exist=false)
|
14
|
-
# TODO: @Micfan, 检查队列中是否存在该消息,如果已存在或正在处理,则返回false
|
15
|
-
def queue_exist(message)
|
16
|
-
false
|
17
|
-
end
|
18
|
-
|
19
|
-
q = @ch.queue(queue_name, :auto_release => auto_release, :durable => durable)
|
20
|
-
x = @ch.default_exchange
|
21
|
-
|
22
|
-
if check_exist and not queue_exist(message)
|
23
|
-
x.publish(message, :routing_key => q.name)
|
24
|
-
else
|
25
|
-
x.publish(message, :routing_key => q.name)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
data/remove/api/npm_registry.rb
DELETED
@@ -1,169 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'open3'
|
3
|
-
require 'httparty'
|
4
|
-
|
5
|
-
require_relative '../../config/config'
|
6
|
-
require_relative '../api/pattern'
|
7
|
-
require_relative '../api/github'
|
8
|
-
|
9
|
-
module API
|
10
|
-
# I have no time to research the npm cli source code(https://github.com/npm/npm-registry-client),
|
11
|
-
# quickly write this.
|
12
|
-
class NpmRegistry
|
13
|
-
def initialize(pack_name, pack_version)
|
14
|
-
@default_registry = 'http://registry.npmjs.org/'
|
15
|
-
@pack_name = pack_name
|
16
|
-
@pack_version = pack_version
|
17
|
-
@pack_meta = nil
|
18
|
-
end
|
19
|
-
|
20
|
-
# RESTful API: http://registry.npmjs.org/:pack_name
|
21
|
-
# TEST: http://registry.npmjs.org/grunt
|
22
|
-
def get_package_meta
|
23
|
-
package_meta = nil
|
24
|
-
api_url = "#{@default_registry}#{@pack_name}"
|
25
|
-
$plog.debug(api_url)
|
26
|
-
response = HTTParty.get(api_url)
|
27
|
-
if response.code == 200
|
28
|
-
package_meta = JSON.parse(response.licenses)
|
29
|
-
elsif response.code == 404
|
30
|
-
$plog.error("!!! Npm registry API 404 Not found: #{response}")
|
31
|
-
else
|
32
|
-
$plog.error("!!! Npm registry API error response: #{response}")
|
33
|
-
end
|
34
|
-
package_meta
|
35
|
-
end
|
36
|
-
|
37
|
-
# RESTful API: http://registry.npmjs.org/grunt/?version=0.1.0
|
38
|
-
def get_package_info_by_version
|
39
|
-
package_info = nil
|
40
|
-
api_url = "#{@default_registry}#{@pack_name}/?version=#{@pack_version}"
|
41
|
-
$plog.debug(api_url)
|
42
|
-
response = HTTParty.get(api_url)
|
43
|
-
if response.code == 200
|
44
|
-
package_info = JSON.parse(response.licenses)
|
45
|
-
elsif response.code == 404
|
46
|
-
$plog.error("!!! Npm registry API 404 Not found: #{response}")
|
47
|
-
else
|
48
|
-
$plog.error("!!! Npm registry API error response: #{response}")
|
49
|
-
end
|
50
|
-
package_info
|
51
|
-
end
|
52
|
-
|
53
|
-
# DOC: https://www.npmjs.com/package/semver
|
54
|
-
# DOC: https://github.com/npm/node-semver
|
55
|
-
# sem_version_range: '~1.2.3'
|
56
|
-
def get_available_versions(sem_version_range)
|
57
|
-
available_versions = []
|
58
|
-
package_meta = get_package_meta
|
59
|
-
all_versions = package_meta['versions']
|
60
|
-
$plog.debug("sem_version_range: #{sem_version_range}")
|
61
|
-
all_versions.each_key {|version|
|
62
|
-
# node -e "var semver = require('semver'); var result = semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3'); console.log(result);"
|
63
|
-
cmd = "node -e \"var semver = require('semver'); var available = semver.satisfies('#{version}', '#{sem_version_range}'); console.log(available);\""
|
64
|
-
# $plog.debug(cmd)
|
65
|
-
Open3.popen3(cmd) {|i,o,e,t|
|
66
|
-
out = o.readlines
|
67
|
-
error = e.readlines
|
68
|
-
if error.length > 0
|
69
|
-
$plog.error(error)
|
70
|
-
raise "node -e evaluate script error: #{cmd}, #{error}"
|
71
|
-
elsif out.length > 0
|
72
|
-
available = out[0].gsub(/\n/,'')
|
73
|
-
if available == 'true'
|
74
|
-
$plog.debug("available version: #{version}")
|
75
|
-
available_versions.push(version)
|
76
|
-
end
|
77
|
-
else
|
78
|
-
raise "node -e evaluate script error: #{cmd}, #{error}"
|
79
|
-
end
|
80
|
-
}
|
81
|
-
}
|
82
|
-
available_versions
|
83
|
-
end
|
84
|
-
|
85
|
-
def chose_one_available_version(sem_version_range)
|
86
|
-
available_versions = get_available_versions(sem_version_range)
|
87
|
-
# TODO: is it right?
|
88
|
-
$plog.debug("chosed version: #{available_versions.last}")
|
89
|
-
available_versions.last
|
90
|
-
end
|
91
|
-
|
92
|
-
def get_license_info()
|
93
|
-
license = nil
|
94
|
-
license_url = nil
|
95
|
-
license_text = nil
|
96
|
-
source_url = nil
|
97
|
-
homepage = nil
|
98
|
-
|
99
|
-
pack_info = get_package_info_by_version
|
100
|
-
$plog.debug("Npm registry pack_info: #{pack_info}")
|
101
|
-
if pack_info
|
102
|
-
licenses = pack_info['licenses']
|
103
|
-
if licenses != nil
|
104
|
-
# TODO: multi licenses:
|
105
|
-
# eg. http://registry.npmjs.org/grunt/?version=0.1.0
|
106
|
-
license = licenses[0]['type']
|
107
|
-
|
108
|
-
# TODO: convert http://github.com/cowboy/grunt/blob/master/LICENSE-MIT to raw
|
109
|
-
license_url = licenses[0]['url']
|
110
|
-
if license_url =~ API::SOURCE_URL_PATTERN[:github_html_page]
|
111
|
-
license_url, license_text = API::Github.convert_htmlpage_to_raw_url(license_url)
|
112
|
-
end
|
113
|
-
else
|
114
|
-
license = pack_info['license']
|
115
|
-
end
|
116
|
-
|
117
|
-
homepage = pack_info['homepage']
|
118
|
-
repository = pack_info['repository']
|
119
|
-
if repository
|
120
|
-
url = repository['url']
|
121
|
-
if repository['type'] == 'git'
|
122
|
-
source_url =
|
123
|
-
if url =~ /^git/
|
124
|
-
url.gsub(/(git:\/\/|git\+ssh:\/\/git\@)/, 'http://').gsub(/\.git$/, '')
|
125
|
-
elsif url =~ /^http/
|
126
|
-
url.gsub(/tree.*$/, '')
|
127
|
-
end
|
128
|
-
elsif repository['type'] =~ 'http'
|
129
|
-
source_url = repository['url'].gsub(/tree.*$/, '')
|
130
|
-
else
|
131
|
-
$plog.info("repository special type: #{repository}")
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
if license_text == nil
|
136
|
-
# TODO:
|
137
|
-
end
|
138
|
-
end
|
139
|
-
{
|
140
|
-
license: license,
|
141
|
-
license_url: license_url,
|
142
|
-
license_text: license_text,
|
143
|
-
source_url: source_url,
|
144
|
-
homepage: homepage
|
145
|
-
}
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
if __FILE__ == $0
|
151
|
-
# name = 'browserify'
|
152
|
-
# version = '12.0.1'
|
153
|
-
name = 'grunt'
|
154
|
-
version = '0.1.0'
|
155
|
-
n = API::NpmRegistry.new(name, version)
|
156
|
-
pack_info = n.get_package_info_by_version
|
157
|
-
|
158
|
-
license_info = n.get_license_info
|
159
|
-
$plog.info(license_info)
|
160
|
-
|
161
|
-
# pack_meta = n.get_package_meta
|
162
|
-
# p pack_meta
|
163
|
-
# p pack_meta['versions']
|
164
|
-
|
165
|
-
# sem_ver = '>=2.5.0'
|
166
|
-
# vs = n.get_available_versions(sem_ver)
|
167
|
-
# p vs
|
168
|
-
end
|
169
|
-
|
data/remove/api/pattern.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
module API
|
2
|
-
|
3
|
-
SOURCE_URL_PATTERN = {
|
4
|
-
:github => /(?<protocol>(http[s]?|git))(:\/\/|@)(?<host>(www\.)?github\.com)(\/|:)(?<owner>.+)\/(?<repo>[^\/.]+)(?<ext>\.git)?/,
|
5
|
-
:git_kernel_org => /(?<protocol>http[s]?):\/\/(?<host>git\.kernel\.org)\/.+\/(?<owner>.+)\/(?<repo>[^\/.]+)(?<ext>\.git)?/,
|
6
|
-
# DOC: https://docs.npmjs.com/files/package.json#git-urls-as-dependencies
|
7
|
-
:npm_urls => /(?<protocol>git):\/\/(?<host>.*\..*)\/(?<owner>.+)\/(?<repo>[^\/#]+(\.git)?)(#(?<ref>.*))?/,
|
8
|
-
:bitbucket => /(?<protocol>http[s]?):\/\/(?<host>bitbucket\.org)\/(?<owner>.+)\/(?<repo>.+)(?<ext>\.git)?/,
|
9
|
-
:github_html_page => /(?<protocol>http[s]?):\/\/(?<host>(www\.)?github\.com)\/(?<owner>.+)\/(?<repo>[^\/]+)\/blob\/(?<branch>.+)\/(?<file_pathname>.+)?/,
|
10
|
-
:github_dot_com => /github\.com/,
|
11
|
-
:rubygems_org => /rubygems\.org/,
|
12
|
-
:google_source_com => /(?<protocol>http[s]?):\/\/(?<owner>.+)\.(?<host>googlesource\.com)\/(?<repo>[^\/.]+)(?<ext>\.git)?/,
|
13
|
-
:code_google_com => /(?<protocol>http[s]?):\/\/(?<host>code\.google\.com)\/(?<owner>p)\/(?<repo>[^\/.]+)?/,
|
14
|
-
:go_pkg_in => /(?<protocol>http[s]?):\/\/(?<host>gopkg\.in)\/((?<owner>[^\/.]+)\/(?<repo>[^\/.]+)\.(?<ref>.+)|(?<repo>[^\/.]+)\.(?<ref>[^\/.]+))/,
|
15
|
-
:golang_org => /(?<protocol>http[s]?):\/\/(?<host>.*golang\.org)\/(?<owner>[^\/.]+)\/(?<repo>[^\/.]+)/
|
16
|
-
}
|
17
|
-
FILE_NAME_PATTERN = {
|
18
|
-
:license_file => /(licen[sc]e|copying)+/i,
|
19
|
-
:readme_file => /readme/i,
|
20
|
-
:components_yml => /components\.yml/,
|
21
|
-
:notice_file => /(notice|copyright)/i,
|
22
|
-
:debian_copyright_file => /^[^\/]+\/debian\/copyright$/
|
23
|
-
}
|
24
|
-
FILE_TYPE_PATTERN = {
|
25
|
-
:tar_gz => /(tar\.gz|\.tgz)$/,
|
26
|
-
:tar_xz => /tar\.xz$/,
|
27
|
-
:tar_bz2 => /tar\.bz2$/
|
28
|
-
}
|
29
|
-
OS_PATTERN = {
|
30
|
-
:ubuntu => /^(?<distribution>(Ubuntu))-(?<distro_series>(Trusty))/i,
|
31
|
-
:centos => /^(?<distribution>(CentOS))-(?<distro_series>(7\.x))/i,
|
32
|
-
}
|
33
|
-
end
|
@@ -1,319 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
require 'anemone'
|
3
|
-
require 'rubygems/package'
|
4
|
-
require 'zlib'
|
5
|
-
require 'xz'
|
6
|
-
require 'open3'
|
7
|
-
|
8
|
-
require_relative '../../config/config'
|
9
|
-
require_relative '../../lib/api/helper'
|
10
|
-
require_relative '../../lib/misc'
|
11
|
-
|
12
|
-
module API
|
13
|
-
|
14
|
-
# TODO: replace this impl
|
15
|
-
# Ruby mixin's way
|
16
|
-
#
|
17
|
-
# module Person
|
18
|
-
# def self.included x
|
19
|
-
# ms = x.instance_methods(false)
|
20
|
-
# [:xx, :yy, :zz].each do |xn|
|
21
|
-
# raise "Please IMPL #{xn} Interface" unless ms.include?(xn)
|
22
|
-
# end
|
23
|
-
# end
|
24
|
-
# end
|
25
|
-
#
|
26
|
-
# class Customer
|
27
|
-
# def xx;end
|
28
|
-
# def yy;end
|
29
|
-
# def zz;end
|
30
|
-
# include Person
|
31
|
-
# end
|
32
|
-
#
|
33
|
-
# c = Customer.new
|
34
|
-
# c.xx
|
35
|
-
# c.yy
|
36
|
-
# c.zz
|
37
|
-
class RemoteSourcePackage
|
38
|
-
def initialize()
|
39
|
-
end
|
40
|
-
|
41
|
-
# OVERRIDE required
|
42
|
-
# return: homepage, download_url
|
43
|
-
def find_source_package_homepage_and_download_url()
|
44
|
-
raise 'Method must be overridden'
|
45
|
-
end
|
46
|
-
|
47
|
-
def download_source_code(source_code_url)
|
48
|
-
source_code_filename = source_code_url.split('/').last
|
49
|
-
source_code_path = "#{LAUNCHPAD_SOURCE_DIR}/#{source_code_filename}"
|
50
|
-
File.open(source_code_path, 'wb') do |f|
|
51
|
-
f.binmode
|
52
|
-
http_option = {
|
53
|
-
:timeout => HTTPARTY_DOWNLOAD_TIMEOUT
|
54
|
-
}
|
55
|
-
http_proxy = Misc.get_http_proxy
|
56
|
-
if http_proxy
|
57
|
-
http_option[:http_proxyaddr] = http_proxy[:addr]
|
58
|
-
http_option[:http_proxyport] = http_proxy[:port]
|
59
|
-
end
|
60
|
-
f.write(HTTParty.get(source_code_url, options=http_option).parsed_response)
|
61
|
-
end
|
62
|
-
|
63
|
-
return source_code_path
|
64
|
-
end
|
65
|
-
|
66
|
-
# Entry
|
67
|
-
def fetch_license_info_from_local_source()
|
68
|
-
license = nil
|
69
|
-
license_url = nil
|
70
|
-
license_text = nil
|
71
|
-
source_package_download_url = nil
|
72
|
-
|
73
|
-
# Attention, source package but binary package
|
74
|
-
source_package_homepage, source_package_download_url = find_source_package_homepage_and_download_url
|
75
|
-
$plog.debug("source_package_homepage: #{source_package_homepage}")
|
76
|
-
$plog.debug("source_package_download_url: #{source_package_download_url}")
|
77
|
-
if source_package_download_url
|
78
|
-
source_code_path = download_source_code(source_package_download_url)
|
79
|
-
$plog.debug("#{source_code_path}")
|
80
|
-
if source_code_path
|
81
|
-
reader = nil
|
82
|
-
if source_code_path =~ API::FILE_TYPE_PATTERN[:tar_gz]
|
83
|
-
reader = Zlib::GzipReader
|
84
|
-
elsif source_code_path =~ API::FILE_TYPE_PATTERN[:tar_xz]
|
85
|
-
reader = XZ::StreamReader
|
86
|
-
elsif source_code_path =~ API::FILE_TYPE_PATTERN[:tar_bz2]
|
87
|
-
# Bash script demo, MacOSX tar is not compatible
|
88
|
-
# $ tar --version
|
89
|
-
# tar (GNU tar) 1.27.1
|
90
|
-
# >>> Copyright (C) 2013 Free Software Foundation, Inc.
|
91
|
-
# >>> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
|
92
|
-
# >>> This is free software: you are free to change and redistribute it.
|
93
|
-
# >> There is NO WARRANTY, to the extent permitted by law.
|
94
|
-
# >> Written by John Gilmore and Jay Fenlason.
|
95
|
-
# $ tar -tjvf bison_3.0.2.dfsg.orig.tar.bz2 | grep -i 'license\|copying\|readme' | awk '{ print $6 }'
|
96
|
-
# $ tar -xj --file=bison_3.0.2.dfsg.orig.tar.bz2 bison-3.0.2.dfsg/COPYING
|
97
|
-
# $ tar -xjO --file=bison_3.0.2.dfsg.orig.tar.bz2 bison-3.0.2.dfsg/COPYING
|
98
|
-
# $ tar -xjO --file=bison_3.0.2.dfsg.orig.tar.bz2 bison-3.0.2.dfsg/COPYING -C /dev/null
|
99
|
-
cmd_list_content = "tar -tjvf #{source_code_path} | grep -i 'license\\|copying' | awk '{ print $6 }'"
|
100
|
-
# MacOSX
|
101
|
-
# cmd_list_content = "tar -tjvf #{source_code_path} | grep -i 'license\\|copying' | awk '{ print $9 }'"
|
102
|
-
$plog.debug(cmd_list_content)
|
103
|
-
Open3.popen3(cmd_list_content) {|i,o,e,t|
|
104
|
-
out = o.readlines
|
105
|
-
error = e.readlines
|
106
|
-
if error.length > 0
|
107
|
-
# todo: move into exception.rb
|
108
|
-
raise "decompress error: #{source_code_path}, #{error}"
|
109
|
-
elsif out.length > 0
|
110
|
-
out.each {|line|
|
111
|
-
license_file_path = line.gsub(/\n/, '')
|
112
|
-
if @root_license_only and !API::Helper.is_root_file(license_file_path)
|
113
|
-
next
|
114
|
-
end
|
115
|
-
cmd_read_content = "tar -xjO --file=#{source_code_path} #{license_file_path} -C /dev/null"
|
116
|
-
Open3.popen3(cmd_read_content) {|i,o,e,t|
|
117
|
-
out2 = o.read
|
118
|
-
error = e.readlines
|
119
|
-
if error.length > 0
|
120
|
-
raise "cmd_read_content error: #{source_code_path}, #{license_file_path}, #{error}"
|
121
|
-
elsif out2.length > 0
|
122
|
-
license_text = out2
|
123
|
-
license_url = license_file_path
|
124
|
-
$plog.debug(license_text)
|
125
|
-
break
|
126
|
-
end
|
127
|
-
}
|
128
|
-
}
|
129
|
-
end
|
130
|
-
}
|
131
|
-
else
|
132
|
-
$plog.error("source_package_download_url: #{source_package_download_url}, can NOT be uncompressed.")
|
133
|
-
return {}
|
134
|
-
end
|
135
|
-
|
136
|
-
if reader
|
137
|
-
tar_extract = Gem::Package::TarReader.new(reader.open(source_code_path))
|
138
|
-
tar_extract.rewind # The extract has to be rewinded after every iteration
|
139
|
-
tar_extract.each do |entry|
|
140
|
-
puts entry.full_name
|
141
|
-
# puts entry.directory?
|
142
|
-
# puts entry.file?
|
143
|
-
# puts entry.read
|
144
|
-
# Root dir files only
|
145
|
-
if entry.directory? or !API::Helper.is_root_file(entry.full_name)
|
146
|
-
# python-defaults-2.7.5/debian/copyright
|
147
|
-
#if API::Helper.is_debian_copyright_file(entry.full_name)
|
148
|
-
# license_url = entry.full_name
|
149
|
-
# license_text = entry.read
|
150
|
-
# break
|
151
|
-
#else
|
152
|
-
next
|
153
|
-
# end
|
154
|
-
end
|
155
|
-
|
156
|
-
if entry.file? and API::Helper.is_license_file(entry.full_name)
|
157
|
-
license_url = entry.full_name
|
158
|
-
license_text = entry.read
|
159
|
-
|
160
|
-
$plog.debug(entry.full_name)
|
161
|
-
$plog.debug(license_text)
|
162
|
-
|
163
|
-
# TODO: parser license info
|
164
|
-
break
|
165
|
-
end
|
166
|
-
|
167
|
-
# TODO:
|
168
|
-
# if entry.file? and API::Helper.is_readme_file(entry.full_name)
|
169
|
-
# puts entry.full_name
|
170
|
-
# # puts entry.read
|
171
|
-
# # TODO: readme parser license info
|
172
|
-
# break
|
173
|
-
# end
|
174
|
-
|
175
|
-
end
|
176
|
-
tar_extract.close ### to abstract out
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
if license_text
|
182
|
-
license = License_recognition.new.similarity(license_text, STD_LICENSE_DIR)
|
183
|
-
end
|
184
|
-
{
|
185
|
-
license: license,
|
186
|
-
license_url: license_url,
|
187
|
-
license_text: license_text,
|
188
|
-
source_url: source_package_download_url,
|
189
|
-
homepage: source_package_homepage
|
190
|
-
}
|
191
|
-
end
|
192
|
-
|
193
|
-
end
|
194
|
-
|
195
|
-
class Launchpad < RemoteSourcePackage
|
196
|
-
# DOC: https://launchpad.net/+apidoc/1.0.html
|
197
|
-
# The source code's license is no relation with which CPU architecture
|
198
|
-
def initialize(distribution, distro_series, binary_package_name, binary_package_version, architecture='amd64',
|
199
|
-
root_license_only=true)
|
200
|
-
@site_url = 'https://launchpad.net'
|
201
|
-
@distribution = distribution
|
202
|
-
@distro_series = distro_series
|
203
|
-
@architecture = architecture
|
204
|
-
@binary_package_name = binary_package_name
|
205
|
-
@binary_package_version = binary_package_version
|
206
|
-
@download_dir = @download_dir
|
207
|
-
|
208
|
-
@source_url = nil
|
209
|
-
@source_path = nil
|
210
|
-
@root_license_only = root_license_only
|
211
|
-
end
|
212
|
-
|
213
|
-
def binary_package_link()
|
214
|
-
binary_package_url = "#{@site_url}/#{@distribution}/#{@distro_series}/#{@architecture}/#{@binary_package_name}/#{@binary_package_version}"
|
215
|
-
end
|
216
|
-
|
217
|
-
# @OVERRIDED
|
218
|
-
def find_source_package_homepage_and_download_url()
|
219
|
-
homepage = _find_source_package_homepage
|
220
|
-
download_url = nil
|
221
|
-
if homepage
|
222
|
-
download_url = _find_source_code_download_url(homepage)
|
223
|
-
end
|
224
|
-
return homepage, download_url
|
225
|
-
end
|
226
|
-
|
227
|
-
def _find_source_package_homepage()
|
228
|
-
source_package_homepage = nil
|
229
|
-
opts = {:discard_page_bodies => true, :depth_limit => 0}
|
230
|
-
|
231
|
-
$plog.debug("binary_package_link: #{binary_package_link}")
|
232
|
-
|
233
|
-
Anemone.crawl(binary_package_link, opts) do |anemone|
|
234
|
-
anemone.on_every_page do |page|
|
235
|
-
xpath = "//dd[@id='source']/a[1]"
|
236
|
-
page.doc.xpath(xpath).each {|text|
|
237
|
-
abs_href = text.css('/@href')
|
238
|
-
if abs_href
|
239
|
-
source_package_homepage = "#{@site_url}#{abs_href}"
|
240
|
-
break
|
241
|
-
end
|
242
|
-
}
|
243
|
-
end
|
244
|
-
end
|
245
|
-
return source_package_homepage
|
246
|
-
end
|
247
|
-
|
248
|
-
def _find_source_code_download_url(source_package_homepage)
|
249
|
-
source_code_download_url = nil
|
250
|
-
|
251
|
-
opts = {:discard_page_bodies => true, :depth_limit => 0}
|
252
|
-
Anemone.crawl(source_package_homepage, opts) do |anemone|
|
253
|
-
anemone.on_every_page do |page|
|
254
|
-
xpath = "//div[@id='source-files']/table/tbody/tr/td/a[contains(@href, '.orig.')]"
|
255
|
-
target_links = page.doc.xpath(xpath)
|
256
|
-
if target_links.size == 0
|
257
|
-
# Eg. https://launchpad.net/ubuntu/+source/wireless-crda/1.16
|
258
|
-
xpath = "//div[@id='source-files']/table/tbody/tr/td/a[not(contains(@href, '.dsc'))]"
|
259
|
-
target_links = page.doc.xpath(xpath)
|
260
|
-
end
|
261
|
-
# puts target_links
|
262
|
-
target_links.each {|text|
|
263
|
-
full_href = text.attr('href')
|
264
|
-
if full_href
|
265
|
-
source_code_download_url = full_href
|
266
|
-
break
|
267
|
-
end
|
268
|
-
}
|
269
|
-
end
|
270
|
-
end
|
271
|
-
return source_code_download_url
|
272
|
-
end
|
273
|
-
|
274
|
-
# def make_up_license_url()
|
275
|
-
# license_url = 'http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/vivid/anacron/vivid/view/head:/COPYING'
|
276
|
-
# end
|
277
|
-
|
278
|
-
end
|
279
|
-
|
280
|
-
class ManifestPackage < RemoteSourcePackage
|
281
|
-
def initialize(source_code_download_url, root_license_only=true)
|
282
|
-
@download_url = source_code_download_url
|
283
|
-
@root_license_only = root_license_only
|
284
|
-
end
|
285
|
-
|
286
|
-
def find_source_package_homepage_and_download_url
|
287
|
-
homepage = nil
|
288
|
-
return homepage, @download_url
|
289
|
-
end
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
if __FILE__ == $0
|
294
|
-
distribution = 'ubuntu'
|
295
|
-
distro_series = 'trusty'
|
296
|
-
name = 'anacron'
|
297
|
-
version = '2.3-20ubuntu1'
|
298
|
-
|
299
|
-
name = 'sg3-utils'
|
300
|
-
version = '1.36-1ubuntu1'
|
301
|
-
|
302
|
-
name = 'wireless-crda'
|
303
|
-
version = '1.16'
|
304
|
-
|
305
|
-
# .bz2
|
306
|
-
name = 'libpython-stdlib'
|
307
|
-
version = '2.7.5-5ubuntu3'
|
308
|
-
a = API::Launchpad.new(distribution, distro_series, name, version)
|
309
|
-
# a = API::ManifestPackage.new('https://pivotal-buildpacks.s3.amazonaws.com/python/binaries/cflinuxfs2/libmemcache.tar.gz')
|
310
|
-
license_info = a.fetch_license_info_from_local_source
|
311
|
-
p license_info
|
312
|
-
|
313
|
-
|
314
|
-
# ii anacron 2.3-20ubuntu1 amd64 cron-like program that doesn't go by time
|
315
|
-
# ii apparmor 2.8.95~2430-0ubuntu5.3 amd64 User-space parser utility for AppArmor
|
316
|
-
# ii apparmor-utils 2.8.95~2430-0ubuntu5.3 amd64 Utilities for controlling AppArmor
|
317
|
-
# ii apt 1.0.1ubuntu2.10 amd64 commandline package manager
|
318
|
-
# ii apt-utils 1.0.1ubuntu2.10 amd64 package management related utility programs
|
319
|
-
end
|