-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
96 lines (80 loc) · 2.62 KB
/
setup.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
import sys
# Change this values according to your Project.
ModuleName = os.path.split(os.path.split(__file__)[0])[1]
ModuleDisplayName = ModuleName.replace('-', ' ')
ModuleVersion = "1.0"
ModuleVersionCode = ModuleVersion.replace('.', '')
ModuleDescription = ""
ModuleAuthorName = ""
# Github repository details. Change these values if needed.
RepositoryName = ModuleName
RepositoryOwner = ModuleAuthorName
ScriptName = os.path.split(__file__)[1]
dryRun = "--dry-run" in sys.argv
if not dryRun:
# Check name
if ' ' in ModuleName:
raise NameError("Module name have space.")
elif ModuleName == 'Magisk-Module-Template':
raise NotImplementedError()
def makeTree(source = '.'):
tree = []
for p in os.listdir(source):
if os.path.isdir(os.path.join(source, p)) and not p in ['.git', '.vs']:
for path in makeTree(os.path.join(source, p)):
tree.append(path)
elif os.path.isfile(os.path.join(source, p)) and not p in [ScriptName, 'main.yml.release']:
tree.append(os.path.join(source, p))
return tree
for f in makeTree():
with open(f, 'r') as file:
fData = file.read()
hasModified = False
# Replace template release workflow
if f.endswith('main.yml'):
with open(f + '.release', 'r') as tfile:
fData = tfile.read()
if not dryRun:
os.remove(f + '.release')
hasModified = True
# Replace module name
if '@(ModuleName)' in fData:
fData = fData.replace('@(ModuleName)', ModuleName)
hasModified = True
# Replace module display name
if '@(ModuleDisplayName)' in fData:
fData = fData.replace('@(ModuleDisplayName)', ModuleDisplayName)
hasModified = True
#Replace module description
if '@(ModuleDescription)' in fData:
fData = fData.replace('@(ModuleDescription)', ModuleDescription)
hasModified = True
# Replace module version data
if '@(ModuleVersion)' in fData:
fData = fData.replace('@(ModuleVersion)', ModuleVersion)
hasModified = True
if '@(ModuleVersionCode)' in fData:
fData = fData.replace('@(ModuleVersionCode)', ModuleVersionCode)
hasModified = True
# Replace module author name
if '@(ModuleAuthorName)' in fData:
fData = fData.replace('@(ModuleAuthorName)', ModuleAuthorName)
hasModified = True
# Replace module Github details.
if '@(RepositoryName)' in fData:
fData = fData.replace('@(RepositoryName)', RepositoryName)
hasModified = True
if '@(RepositoryOwner)' in fData:
fData = fData.replace('@(RepositoryOwner)', RepositoryOwner)
hasModified = True
if hasModified:
# Do modifications
if not dryRun:
with open(f, 'w') as file:
file.write(fData)
# Write modifications to console
else:
print('Modified file: ' + f)
print(fData)
print()