mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
N°2570 Update iTop license list
This commit is contained in:
6
.make/README.md
Normal file
6
.make/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
= Make Doc =
|
||||
.make folder is meant to gather tools for releasing process. Maybe other new purposes will come as well....
|
||||
|
||||
== license ==
|
||||
- updateLicenses.php: used to update community-licenses.xml easily based on composer.json files
|
||||
- sortLicenceXml.php: used to sort licenses based on scope + product name
|
||||
84
.make/license/gen-community-license.sh
Normal file
84
.make/license/gen-community-license.sh
Normal file
@@ -0,0 +1,84 @@
|
||||
#/bin/bash
|
||||
|
||||
#git diff --name-status 2.6.2..HEAD js |grep 'A\sjs/' |awk -F/ '{printf("lib/%s/%s\n",$2,$3)}'|sort |uniq >/tmp/toto
|
||||
#git diff --name-status 2.6.2..HEAD lib |grep 'A\slib/' |awk -F/ '{printf("lib/%s/%s\n",$2,$3)}'|sort |uniq >/tmp/toto
|
||||
|
||||
function HELP(){
|
||||
echo " Syntax: bash $0 /var/www/html/iTop"
|
||||
}
|
||||
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
echo "no iTop path provided"
|
||||
HELP
|
||||
exit 1
|
||||
fi
|
||||
|
||||
iTopPath=$1
|
||||
|
||||
if [ ! -d $iTopPath ]
|
||||
then
|
||||
echo "$iTopPath is not an iTop path."
|
||||
HELP
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "<?xml version=\"1.0\"?>
|
||||
<licenses>"
|
||||
|
||||
for subfolder in lib datamodels
|
||||
do
|
||||
for l in $(find $iTopPath/$subfolder/ -name composer.json|sed 's|/composer.json||')
|
||||
do
|
||||
if [ ! -d $l ]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
|
||||
dir=$(dirname $(dirname $l))
|
||||
prod=$(echo $l| sed "s|$dir/||1")
|
||||
echo $l $subfolder
|
||||
lictype=$(cd $l && composer licenses --format json |jq .license[] |sed 's|\"||g')
|
||||
|
||||
authors=""
|
||||
if [ -f $l/composer.json ]
|
||||
then
|
||||
author_nb=$(grep -c authors $l/composer.json|sed 's| ||g')
|
||||
if [ "x$author_nb" != "x0" ]
|
||||
then
|
||||
OLDIFS=$IFS
|
||||
IFS=$'\n'
|
||||
for a in $(cat $l/composer.json |jq .authors[].name|sed 's|\"||g')
|
||||
do
|
||||
authors="$authors$a - "
|
||||
done
|
||||
authors="$authors#"
|
||||
authors=$(echo $authors |sed 's| - #||')
|
||||
IFS=$OLDIFS
|
||||
fi
|
||||
fi
|
||||
|
||||
lic=""
|
||||
for licf in $(find $l -name LICEN*)
|
||||
do
|
||||
lic=$(cat $licf)
|
||||
break
|
||||
done
|
||||
|
||||
#if [ "x$lic" == "x" ]
|
||||
#then
|
||||
# echo "============== no license found $l"
|
||||
#fi
|
||||
|
||||
echo " <license>
|
||||
<product scope=\"$subfolder\">$prod</product>
|
||||
<author>$authors</author>
|
||||
<license_type>$lictype</license_type>
|
||||
<text><![CDATA[
|
||||
$lic
|
||||
]]></text>
|
||||
</license>"
|
||||
done
|
||||
done
|
||||
|
||||
echo "</licenses>"
|
||||
64
.make/license/sortLicenceXml.php
Normal file
64
.make/license/sortLicenceXml.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* script used to sort license file (usefull for autogeneration)
|
||||
* Example:
|
||||
*/
|
||||
$iTopFolder = __DIR__ . "/../../" ;
|
||||
$xmlFilePath = $iTopFolder . "setup/licenses/community-licenses.xml";
|
||||
$dom = new DOMDocument();
|
||||
$dom->load($xmlFilePath);
|
||||
$xp = new DOMXPath($dom);
|
||||
|
||||
$licenseList = $xp->query('/licenses/license');
|
||||
$licenses = iterator_to_array($licenseList);
|
||||
|
||||
|
||||
function get_scope($product_node)
|
||||
{
|
||||
$scope = $product_node->getAttribute("scope");
|
||||
|
||||
if ($scope === "")
|
||||
{ //put iTop first
|
||||
return "aaaaaaaaa";
|
||||
}
|
||||
return $scope;
|
||||
}
|
||||
|
||||
function get_product_node($license_node)
|
||||
{
|
||||
foreach ($license_node->childNodes as $child)
|
||||
{
|
||||
if (is_a($child, 'DomElement') && $child->tagName === "product")
|
||||
{
|
||||
return $child;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function sort_by_product($a, $b)
|
||||
{
|
||||
$aProductNode = get_product_node($a);
|
||||
$bProductNode = get_product_node($b);
|
||||
|
||||
$res = strcmp(get_scope($aProductNode), get_scope($bProductNode));
|
||||
if ($res !== 0)
|
||||
{
|
||||
return $res;
|
||||
}
|
||||
//sort on node product name
|
||||
return strcmp($aProductNode->nodeValue, $bProductNode->nodeValue);
|
||||
}
|
||||
|
||||
usort($licenses, 'sort_by_product');
|
||||
|
||||
$newdom = new DOMDocument("1.0");
|
||||
$newdom->formatOutput = true;
|
||||
$root = $newdom->createElement("licenses");
|
||||
$newdom->appendChild($root);
|
||||
foreach ($licenses as $b) {
|
||||
$node = $newdom->importNode($b,true);
|
||||
$root->appendChild($newdom->importNode($b,true));
|
||||
}
|
||||
|
||||
$newdom->save($xmlFilePath);
|
||||
89
.make/license/updateLicenses.php
Normal file
89
.make/license/updateLicenses.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* script used to sort license file (usefull for autogeneration)
|
||||
* Example: php
|
||||
*/
|
||||
|
||||
$iTopFolder = __DIR__ . "/../../" ;
|
||||
$xmlFilePath = $iTopFolder . "setup/licenses/community-licenses.xml";
|
||||
|
||||
function get_scope($product_node)
|
||||
{
|
||||
$scope = $product_node->getAttribute("scope");
|
||||
|
||||
if ($scope === "")
|
||||
{ //put iTop first
|
||||
return "aaaaaaaaa";
|
||||
}
|
||||
return $scope;
|
||||
}
|
||||
|
||||
function get_product_node($license_node)
|
||||
{
|
||||
foreach ($license_node->childNodes as $child)
|
||||
{
|
||||
if (is_a($child, 'DomElement') && $child->tagName === "product")
|
||||
{
|
||||
return $child;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function sort_by_product($a, $b)
|
||||
{
|
||||
$aProductNode = get_product_node($a);
|
||||
$bProductNode = get_product_node($b);
|
||||
|
||||
$res = strcmp(get_scope($aProductNode), get_scope($bProductNode));
|
||||
if ($res !== 0)
|
||||
{
|
||||
return $res;
|
||||
}
|
||||
//sort on node product name
|
||||
return strcmp($aProductNode->nodeValue, $bProductNode->nodeValue);
|
||||
}
|
||||
|
||||
function get_license_nodes($file_path)
|
||||
{
|
||||
$dom = new DOMDocument();
|
||||
$dom->load($file_path);
|
||||
$xp = new DOMXPath($dom);
|
||||
|
||||
$licenseList = $xp->query('/licenses/license');
|
||||
$licenses = iterator_to_array($licenseList);
|
||||
|
||||
usort($licenses, 'sort_by_product');
|
||||
return $licenses;
|
||||
}
|
||||
|
||||
$old_licenses = get_license_nodes($xmlFilePath);
|
||||
|
||||
//generate file with updated licenses
|
||||
$generated_license_file_path = __DIR__."/provfile.xml";
|
||||
exec("bash " . __DIR__ . "/gen-community-license.sh $iTopFolder > ". $generated_license_file_path);
|
||||
$new_licenses = get_license_nodes($generated_license_file_path);
|
||||
exec("rm -f ". $generated_license_file_path);
|
||||
|
||||
foreach ($old_licenses as $b) {
|
||||
$aProductNode = get_product_node($b);
|
||||
|
||||
if (get_scope($aProductNode) !== "lib" && get_scope($aProductNode) !== "datamodels" )
|
||||
{
|
||||
$new_licenses[] = $b;
|
||||
}
|
||||
}
|
||||
|
||||
usort($new_licenses, 'sort_by_product');
|
||||
|
||||
$new_dom = new DOMDocument("1.0");
|
||||
$new_dom->formatOutput = true;
|
||||
$root = $new_dom->createElement("licenses");
|
||||
$new_dom->appendChild($root);
|
||||
|
||||
foreach ($new_licenses as $b) {
|
||||
$node = $new_dom->importNode($b,true);
|
||||
$root->appendChild($new_dom->importNode($b,true));
|
||||
}
|
||||
|
||||
$new_dom->save($xmlFilePath);
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user