-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
79 lines (60 loc) · 2.01 KB
/
main.py
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
import os
import sys
from os import walk
class AcknowledgementGenerator():
def generate(self, SPM_CHECKOUT_DIR, FILE_NAME):
if not os.path.exists(SPM_CHECKOUT_DIR):
print("Swift Package Folder doesnt exist")
sys.exit(1)
content = []
for (dirpath, dirnames, filenames) in walk(SPM_CHECKOUT_DIR):
if 'LICENSE' in filenames:
packageName = os.path.basename(os.path.normpath(dirpath))
licensePath = os.path.join(SPM_CHECKOUT_DIR, packageName)
licensePath = os.path.join(licensePath, "LICENSE")
print("Package {}, LICENSE: {}".format(packageName, licensePath))
if not os.path.exists(licensePath):
continue
with open (licensePath, "r") as licFile:
licString = licFile.read().replace('<', '').replace('>', '')
itemTemplate = """
<dict>
<key>FooterText</key>
<string>{license}</string>
<key>Title</key>
<string>{name}</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
""".format(license=licString, name=packageName)
content.append(itemTemplate)
contentStr = ''.join(content)
template = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>FooterText</key>
<string>This App makes use of the following third party libraries</string>
<key>Title</key>
<string>Acknowledgements</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
{content}
</array>
</dict>
</plist>
""".format(content=contentStr)
print(f'::set-output name=PLAIN_TEXT::{template}')
with open(FILE_NAME, "w") as plistFile:
plistFile.write(template)
def main():
SPM_CHECKOUT_DIR = os.getenv('SPM_CHECKOUT_DIR')
FILE_NAME = os.getenv('FILE_NAME')
service = AcknowledgementGenerator()
token = service.generate(SPM_CHECKOUT_DIR, FILE_NAME)
if __name__ == "__main__":
main()