add multi language support to gen-license

This commit is contained in:
zombie110year
2019-03-30 01:43:47 +08:00
parent 252fa9b7f3
commit a2fcf908b4
2 changed files with 66 additions and 10 deletions

View File

@ -1,4 +1,4 @@
from argparse import ArgumentParser from argparse import ArgumentParser, _HelpAction
from pkgutil import get_data from pkgutil import get_data
from sys import exit from sys import exit
@ -36,15 +36,38 @@ def getparser():
) )
parser.add_argument( parser.add_argument(
"--996icu", dest="icu", help="Expand LICENSE with 996ICU LICENSE", required=False, "--996icu", dest="icu", help="Expand LICENSE with 996ICU LICENSE, Choose a language vesion or default zh-cn",
action="store_true" required=False, nargs="?", const="zh-cn", default=None,
choices=["en-us", "zh-cn"]
) )
return parser return parser
def select_template(language_code):
"""choose a 996icu LICENSE template according to *language_code*
"""
map_ = {
"zh": "zh-cn",
"zh-cn": "zh-cn",
"zh-hans": "zh-cn",
"en": "en-us",
"en-us": "en-us",
}
template = get_data(
__package__,
"licenses/996.icu.template.{}.txt".format(
map_.get(language_code, "zh-cn")
)
).decode("utf-8")
return template
def main(): def main():
args = getparser().parse_args() parser = getparser()
args = parser.parse_args()
if args.list: if args.list:
for license in LICENSES: for license in LICENSES:
@ -53,16 +76,18 @@ def main():
exit(0) exit(0)
else: # main else: # main
# if no args input, show help and exit
if args.code is None:
parser.print_help()
parser.exit()
resource = get_data( resource = get_data(
__package__, __package__,
"licenses/{code}.txt".format(code=args.code) "licenses/{code}.txt".format(code=args.code)
).decode("utf-8") ).decode("utf-8")
if args.icu: # --996icu option enabled if args.icu is not None: # --996icu option enabled
template = get_data( template = select_template(args.icu)
__package__,
"licenses/996.icu.template.zh-cn.txt"
).decode("utf-8")
output = template.format( output = template.format(
other=args.code, other=args.code,
@ -70,7 +95,7 @@ def main():
).encode("utf-8") ).encode("utf-8")
else: # common license else: # common license
output = resource output = resource.encode("utf-8")
with open("LICENSE", "wb") as file: with open("LICENSE", "wb") as file:
file.write(output) file.write(output)

View File

@ -0,0 +1,31 @@
Copyright © 2019 <copyright holders>
The 996ICU License (996ICU)
996ICU License is an extented license for {other}.
This license extended {other}, and {other} will be declared at the foot of this license.
Individual who seeks authorization must fulfill the following obligations:
1. Including this authorization file in any of its copies and important parts of the software.
Organization that seeks authorization must fulfill the following obligations:
1. Including this authorization file in any of its copies and important parts of the software.
2. Not forcing any employee or temporary worker to work in excess of the legal maximum working time in any form or by any means, including but not limited to: orders, threats, implications, etc.
3. Not retaliating against any employee or temporary worker without participating in labor in excess of the legal maximum working time in any form or by any means, including but not limited to: mental assaults, personal injuries, illegal deductions of due remuneration, illegal dismissals, etc.
4. Paying economic compensation at no lower than the standards stipulated by local laws and regulations, when organizing employees or temporary workers to work overtime.
5. This organization is not in the blacklist[^1] as stipulated in the agreement.
If the authorized individual or organization fails to fulfill any of the above obligations, the authorization will be withdrawn.
The undefined behavior of this license is handled by {other}. The part of {other} that conflicts with this agreement is handled in accordance with this agreement.
* Discussion https://github.com/996icu/996.ICU/pull/15642
* 996 from https://feathub.com/LinXueyuanStdio/996.ICU
* [^1]: blacklist https://github.com/996icu/996.ICU/blob/master/blacklist/blacklist.md
{other}
--------------------------------------------------------------------------------
{content}