summaryrefslogtreecommitdiffstats
path: root/third-party
diff options
context:
space:
mode:
authorYujun Zhang <zhang.yujunz@zte.com.cn>2017-02-21 16:08:42 +0800
committerYujun Zhang <zhang.yujunz@zte.com.cn>2017-02-21 16:10:19 +0800
commitaca3c1d72e7f23cd9422179e18c5d67eb73f1484 (patch)
treed64caabad34f97761b05c84297b4357fd5920c18 /third-party
parent3e443dff14a2be02b914e66f27b549d0ed4cc600 (diff)
Include third party script for license checking and amending
The following commit message are generated automatically by git-subrepo ----------------------------------------------------------------------------- git subrepo clone git@github.com:openzero-zte/License.git third-party/License subrepo: subdir: "third-party/License" merged: "61489da" upstream: origin: "git@github.com:openzero-zte/License.git" branch: "master" commit: "61489da" git-subrepo: version: "0.3.0" origin: "https://github.com/ingydotnet/git-subrepo" commit: "988f8c8" ----------------------------------------------------------------------------- Change-Id: I8eab86a8ce3f26995af3e3535f31f361b4826a8b Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
Diffstat (limited to 'third-party')
-rw-r--r--third-party/License/.gitrepo11
-rw-r--r--third-party/License/README.md10
-rwxr-xr-xthird-party/License/add_license.sh180
3 files changed, 201 insertions, 0 deletions
diff --git a/third-party/License/.gitrepo b/third-party/License/.gitrepo
new file mode 100644
index 00000000..29cd5a75
--- /dev/null
+++ b/third-party/License/.gitrepo
@@ -0,0 +1,11 @@
+; DO NOT EDIT (unless you know what you are doing)
+;
+; This subdirectory is a git "subrepo", and this file is maintained by the
+; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
+;
+[subrepo]
+ remote = git@github.com:openzero-zte/License.git
+ branch = master
+ commit = 61489dae4453b66887d0d90a2244610a30f7e53c
+ parent = 3e443dff14a2be02b914e66f27b549d0ed4cc600
+ cmdver = 0.3.0
diff --git a/third-party/License/README.md b/third-party/License/README.md
new file mode 100644
index 00000000..0232de7e
--- /dev/null
+++ b/third-party/License/README.md
@@ -0,0 +1,10 @@
+# License
+
+A script for checking and adding license header according to [OPNFV contribution guideline](https://wiki.opnfv.org/display/DEV/Contribution+Guidelines)
+
+## Quick Start
+
+```
+$ cd <project-folder>
+$ curl https://raw.githubusercontent.com/Justin-chi/License/master/add_license.sh |bash
+```
diff --git a/third-party/License/add_license.sh b/third-party/License/add_license.sh
new file mode 100755
index 00000000..9b383c62
--- /dev/null
+++ b/third-party/License/add_license.sh
@@ -0,0 +1,180 @@
+#!/bin/bash
+# Copyright justin.chigang@gmail.com
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+TMP_FILE=tmp.file
+LICENSE_TOKEN="http://www.apache.org/licenses/LICENSE-2.0"
+
+function get_first_author()
+{
+ author=$(git log --reverse --pretty=format:"%ae" $1 | head -1)
+ substring=$(git log --reverse --pretty=format:"%ae" $1 | head -1 | awk -F@ '{print $2}')
+ case $substring in
+ huawei*)
+ echo "HUAWEI TECHNOLOGIES CO.,LTD"
+ ;;
+ orange*)
+ echo "Orange"
+ ;;
+ zte*)
+ echo "ZTE Corporation"
+ ;;
+ *)
+ echo "$author"
+ ;;
+ esac
+}
+
+function get_latest_year()
+{
+ git log --pretty=format:"%ad" $1 | head -1 | awk '{print $5}'
+}
+
+function gen_c_license()
+{
+cat << EOF >$1
+/*******************************************************************************
+ * Copyright (c) $2 $3 and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Apache License, Version 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *******************************************************************************/
+
+EOF
+}
+
+function gen_xml_license()
+{
+cat << EOF >$1
+<!--
+ Copyright (c) $2 $3 and others.
+
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Apache License, Version 2.0
+ which accompanies this distribution, and is available at
+ http://www.apache.org/licenses/LICENSE-2.0
+-->
+
+EOF
+}
+
+function gen_bash_license()
+{
+cat << EOF >$1
+##############################################################################
+# Copyright (c) $2 $3 and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+EOF
+}
+
+function add_c_license()
+{
+ C_LICENSE="c_license_header.tmp"
+ author=`get_first_author "$1"`
+ year=`get_latest_year "$1"`
+ gen_c_license $C_LICENSE $year "$author"
+ cat $C_LICENSE $1 > $TMP_FILE
+ rm -f $C_LICENSE
+ mv $TMP_FILE $1
+}
+
+function add_xml_license()
+{
+ XML_LICENSE="xml_license_header.tmp"
+ author=`get_first_author "$1"`
+ year=`get_latest_year "$1"`
+ gen_xml_license $XML_LICENSE $year "$author"
+ cat $XML_LICENSE $1 > $TMP_FILE
+ rm -f $XML_LICENSE
+ mv $TMP_FILE $1
+}
+
+function add_bash_license()
+{
+ BASH_LICENSE="bash_license_header.tmp"
+ author=`get_first_author "$1"`
+ year=`get_latest_year "$1"`
+ gen_bash_license $BASH_LICENSE $year "$author"
+ cat $1 | head -1 | grep "#!" > /dev/null
+ if [ $? -eq 0 ]; then
+ #insert 2
+ sed -i "1 r $BASH_LICENSE" $1
+ else
+ #sed -i "1 R $BASH_LICENSE" $1
+ cat $BASH_LICENSE $1 > $TMP_FILE
+ mv $TMP_FILE $1
+ fi
+ rm -f $BASH_LICENSE
+}
+
+if [[ -z "$1" ]] || [[ ! -d "$1" ]]; then
+ echo "The directory is empty or not exist!"
+ echo "It will use the current directory."
+ nowdir=$(pwd)
+else
+ nowdir=$(cd $1; pwd)
+fi
+echo "$nowdir"
+
+n=0
+
+function Searchfile()
+{
+ cd $1
+
+ dirlist=$(ls)
+ for dirname in $dirlist
+ do
+ if [[ -d "$dirname" ]];then
+ n=$((n+4))
+ cd $dirname
+ for i in $( seq 0 $n );do echo -n ' ';done;echo "$dirname ..."
+ Searchfile $(pwd)
+ cd ..
+ n=$((n-4))
+ fi;
+
+ filename=$dirname
+ if [[ -f "$filename" ]]; then
+ for i in $( seq 0 $n );do echo -n ' ';done;echo " |--$filename"
+ grep -rn $LICENSE_TOKEN $filename >/dev/null
+ if [ $? -eq 1 ]; then
+ if [ "${filename##*.}" = "c" -o "${filename##*.}" = "cpp" -o "${filename##*.}" = "java" ]; then
+ add_c_license $filename
+ for i in $( seq 0 $n );do echo -n ' ';done;echo " |--add license for $filename... "
+ elif [ "${filename##*.}" = "py" -o "${filename##*.}" = "yml" -o "${filename##*.}" = "yaml" -o "${filename##*.}" = "sh" ]; then
+ add_bash_license $filename
+ for i in $( seq 0 $n );do echo -n ' ';done;echo " |--add license for $filename... "
+ elif [ "${filename##*.}" = "xml" ]; then
+ add_xml_license $filename
+ for i in $( seq 0 $n );do echo -n ' ';done;echo " |--add license for $filename... "
+ fi;
+ fi;
+ fi;
+ done;
+}
+
+Searchfile $nowdir
+
+# Revert changes of skipped files, e.g. __init__.py
+
+git checkout \*\*/__init__.py