forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
airflow-license
executable file
·81 lines (66 loc) · 2.67 KB
/
airflow-license
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
import os
import re
import string
import slugify
# order is important
_licenses = {
'MIT': [
'Permission is hereby granted free of charge',
'The above copyright notice and this permission notice shall',
],
'BSD-3': [
'Redistributions of source code must retain the above copyright',
'Redistributions in binary form must reproduce the above copyright',
'specific prior written permission',
],
'BSD-2': [
'Redistributions of source code must retain the above copyright',
'Redistributions in binary form must reproduce the above copyright',
],
'AL': ['http://www.apache.org/licenses/LICENSE-2.0'],
}
def get_notices():
license_file = open("../LICENSE")
regex = r"\((.+?)\) (.+?) \((http.+?)\)"
return list(filter(None, [re.findall(regex, line) for line in license_file]))
def parse_license_file(project_name):
name = re.match(r"^[a-z0-9\-]+", project_name.lower())
name = slugify.slugify(name.group(0))
path = f"../licenses/LICENSE-{name}.txt"
if os.path.exists(path):
data = " ".join(line.strip() for line in open(path)).lower()
data = data.translate(string.punctuation)
for k in _licenses:
matches = 0
for v in _licenses[k]:
if v.lower() in data:
matches += 1
if matches == len(_licenses[k]):
return k
return False
if __name__ == "__main__":
print(f"{'PROJECT':<30}|{'URL':<50}||{'LICENSE TYPE DEFINED':<20}||{'DETECTED':<10}")
notices = get_notices()
for notice in notices:
notice = notice[0]
license = parse_license_file(notice[1])
print(f"{notice[1]:<30}|{notice[2][:50]:<50}||{notice[0]:<20}||{license:<10}")
file_count = len([name for name in os.listdir("../licenses")])
print(f"Defined licenses: {len(notices)} Files found: {file_count}")