license: update license metadata and generation code
This commit is contained in:
parent
da91bab5d6
commit
8d4e2dda3a
8 changed files with 1992 additions and 411 deletions
|
|
@ -47,6 +47,14 @@ Bower dependencies
|
|||
nix-shell pkgs/shell-generate.nix --command "bower2nix bower.json pkgs/bower-packages.nix"
|
||||
|
||||
|
||||
Generate license data
|
||||
=====================
|
||||
|
||||
.. code:: shell
|
||||
|
||||
nix-build pkgs/license-generate.nix -o result-license && cat result-license/licenses.json | python -m json.tool > rhodecode/config/licenses.json
|
||||
|
||||
|
||||
.. Links
|
||||
|
||||
.. _RhodeCode Enterprise CE: https://code.rhodecode.com/rhodecode-enterprise-ce
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
#
|
||||
# Usage:
|
||||
#
|
||||
# nix-build -I ~/dev license.nix -A result
|
||||
# nix-build license.nix -o result-license
|
||||
#
|
||||
# Afterwards ./result will contain the license information as JSON files.
|
||||
# Afterwards ./result-license will contain the license information as JSON files.
|
||||
#
|
||||
#
|
||||
# Overview
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
# dependencies. The results from step 1 are then limited to the ones which
|
||||
# are in this list.
|
||||
#
|
||||
# The result is then available in ./result/license.json.
|
||||
# The result is then available in ./result-license/license.json.
|
||||
#
|
||||
|
||||
|
||||
|
|
@ -32,20 +32,20 @@ let
|
|||
# Enterprise as simple as possible, goal here is just to identify the runtime
|
||||
# dependencies. Ideally we could avoid building Enterprise at all and somehow
|
||||
# figure it out without calling into nix-store.
|
||||
enterprise = import ./default.nix {
|
||||
enterprise = import ../default.nix {
|
||||
doCheck = false;
|
||||
};
|
||||
|
||||
# For a given derivation, return the list of all dependencies
|
||||
drvToDependencies = drv: nixpkgs.lib.flatten [
|
||||
drv.nativeBuildInputs or []
|
||||
drv.propagatedNativeBuildInputs or []
|
||||
drv.buildInputs or []
|
||||
drv.propagatedBuildInputs or []
|
||||
];
|
||||
|
||||
# Transform the given derivation into the meta information which we need in
|
||||
# the resulting JSON files.
|
||||
drvToMeta = drv: {
|
||||
name = drv.name or "UNNAMED";
|
||||
name = drv.name or drv;
|
||||
license = if drv ? meta.license then drv.meta.license else "UNKNOWN";
|
||||
};
|
||||
|
||||
|
|
@ -70,10 +70,8 @@ let
|
|||
rawStorePaths = nixpkgs.lib.removeSuffix "\n" (
|
||||
builtins.readFile srcPath);
|
||||
storePaths = nixpkgs.lib.splitString "\n" rawStorePaths;
|
||||
# TODO: johbo: Would be nice to use some sort of utility here to convert
|
||||
# the path to a derivation name.
|
||||
storePathPrefix = (
|
||||
builtins.stringLength "/nix/store/zwy7aavnif9ayw30rya1k6xiacafzzl6-");
|
||||
builtins.stringLength "/nix/store/afafafafafafafafafafafafafafafaf-");
|
||||
storePathToName = path:
|
||||
builtins.substring storePathPrefix (builtins.stringLength path) path;
|
||||
in (map storePathToName storePaths);
|
||||
|
|
@ -147,6 +145,7 @@ in rec {
|
|||
cat > build/licenses.json <<EOF
|
||||
${builtins.toJSON enterpriseRuntimeLicenses}
|
||||
EOF
|
||||
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
|
|
@ -488,14 +488,30 @@ class TestLabsSettings(object):
|
|||
class TestOpenSourceLicenses(object):
|
||||
|
||||
def test_records_are_displayed(self, autologin_user):
|
||||
sample_licenses = {
|
||||
"python2.7-pytest-2.7.1": {
|
||||
"UNKNOWN": None
|
||||
sample_licenses = [
|
||||
{
|
||||
"license": [
|
||||
{
|
||||
"fullName": "BSD 4-clause \"Original\" or \"Old\" License",
|
||||
"shortName": "bsdOriginal",
|
||||
"spdxId": "BSD-4-Clause",
|
||||
"url": "http://spdx.org/licenses/BSD-4-Clause.html"
|
||||
}
|
||||
],
|
||||
"name": "python2.7-coverage-3.7.1"
|
||||
},
|
||||
"python2.7-Markdown-2.6.2": {
|
||||
"BSD-3-Clause": "http://spdx.org/licenses/BSD-3-Clause"
|
||||
}
|
||||
}
|
||||
{
|
||||
"license": [
|
||||
{
|
||||
"fullName": "MIT License",
|
||||
"shortName": "mit",
|
||||
"spdxId": "MIT",
|
||||
"url": "http://spdx.org/licenses/MIT.html"
|
||||
}
|
||||
],
|
||||
"name": "python2.7-bootstrapped-pip-9.0.1"
|
||||
},
|
||||
]
|
||||
read_licenses_patch = mock.patch(
|
||||
'rhodecode.apps.admin.views.open_source_licenses.read_opensource_licenses',
|
||||
return_value=sample_licenses)
|
||||
|
|
@ -506,10 +522,9 @@ class TestOpenSourceLicenses(object):
|
|||
assert_response = AssertResponse(response)
|
||||
assert_response.element_contains(
|
||||
'.panel-heading', 'Licenses of Third Party Packages')
|
||||
for name in sample_licenses:
|
||||
response.mustcontain(name)
|
||||
for license in sample_licenses[name]:
|
||||
assert_response.element_contains('.panel-body', license)
|
||||
for license_data in sample_licenses:
|
||||
response.mustcontain(license_data["license"][0]["spdxId"])
|
||||
assert_response.element_contains('.panel-body', license_data["name"])
|
||||
|
||||
def test_records_can_be_read(self, autologin_user):
|
||||
response = self.app.get(
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ class OpenSourceLicensesAdminSettingsView(BaseAppView):
|
|||
|
||||
def load_default_context(self):
|
||||
c = self._get_local_tmpl_context()
|
||||
|
||||
return c
|
||||
|
||||
@LoginRequired()
|
||||
|
|
@ -47,7 +46,6 @@ class OpenSourceLicensesAdminSettingsView(BaseAppView):
|
|||
c = self.load_default_context()
|
||||
c.active = 'open_source'
|
||||
c.navlist = navigation_list(self.request)
|
||||
items = sorted(read_opensource_licenses().items(), key=lambda t: t[0])
|
||||
c.opensource_licenses = collections.OrderedDict(items)
|
||||
|
||||
c.opensource_licenses = sorted(
|
||||
read_opensource_licenses(), key=lambda d: d["name"])
|
||||
return self._get_template_context(c)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -372,6 +372,7 @@ table.keyboard-mappings {
|
|||
table.rctable.dl-settings {
|
||||
td {
|
||||
border: none;
|
||||
vertical-align: baseline;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,11 @@
|
|||
<%def name="show_license(license_data)">
|
||||
% if isinstance(license_data, dict):
|
||||
<a href="${license_data.get('url', "#noUrl")}">${license_data.get('spdxId') or license_data.get('fullName')}</a>
|
||||
% else:
|
||||
${license_data}
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">${_('Licenses of Third Party Packages')}</h3>
|
||||
|
|
@ -7,24 +15,29 @@
|
|||
RhodeCode Enterprise uses various third party packages, many of them
|
||||
provided by the open source community.
|
||||
</p>
|
||||
|
||||
% if c.opensource_licenses:
|
||||
<table class="rctable dl-settings">
|
||||
<thead>
|
||||
<th>Product</th>
|
||||
<th>License</th>
|
||||
</thead>
|
||||
%for product, licenses in c.opensource_licenses.items():
|
||||
<tr>
|
||||
<td>${product}</td>
|
||||
<td>
|
||||
${h.literal(', '.join([
|
||||
'<a href="%(link)s" title="%(name)s">%(name)s</a>' % {'link':link, 'name':name}
|
||||
if link else name
|
||||
for name,link in licenses.items()]))}
|
||||
</td>
|
||||
</tr>
|
||||
%endfor
|
||||
% for lib in c.opensource_licenses:
|
||||
<tr>
|
||||
<td>${lib["name"]}</td>
|
||||
<td>
|
||||
<ol>
|
||||
% if isinstance(lib["license"], list):
|
||||
% for license_data in lib["license"]:
|
||||
<li>${show_license(license_data)}</li>
|
||||
% endfor
|
||||
% else:
|
||||
<% license_data = lib["license"] %>
|
||||
<li>${show_license(license_data)}</li>
|
||||
% endif
|
||||
</ol>
|
||||
</td>
|
||||
</tr>
|
||||
% endfor
|
||||
</table>
|
||||
% endif
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -302,7 +302,7 @@ class TestPasswordChanged(object):
|
|||
assert result is True
|
||||
|
||||
|
||||
class TestReadOpensourceLicenses(object):
|
||||
class TestReadOpenSourceLicenses(object):
|
||||
def test_success(self):
|
||||
utils._license_cache = None
|
||||
json_data = '''
|
||||
|
|
@ -343,10 +343,14 @@ class TestReadOpensourceLicenses(object):
|
|||
def test_licenses_file_contains_no_unknown_licenses(self):
|
||||
utils._license_cache = None
|
||||
result = utils.read_opensource_licenses()
|
||||
license_names = []
|
||||
for licenses in result.values():
|
||||
license_names.extend(licenses.keys())
|
||||
assert 'UNKNOWN' not in license_names
|
||||
|
||||
for license_data in result:
|
||||
if isinstance(license_data["license"], list):
|
||||
for lic_data in license_data["license"]:
|
||||
assert 'UNKNOWN' not in lic_data["fullName"]
|
||||
else:
|
||||
full_name = license_data.get("fullName") or license_data
|
||||
assert 'UNKNOWN' not in full_name
|
||||
|
||||
|
||||
class TestMakeDbConfig(object):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue