-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfigurator.py
97 lines (80 loc) · 4.33 KB
/
configurator.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
97
#!/usr/bin/python
import json
import re
import os
import shutil
import sys
import argparse
parser = argparse.ArgumentParser(
description='This program can guide you through the process of configuring Neutron.')
parser.add_argument("-c", "--config-file", help="File path of the config JSON generated by a past run of this program.", required=False)
parser.add_argument("-k", "--keep-build-dir", help="Don't clear the build folder.", required=False, action="store_true")
def main(args: argparse.Namespace):
if not args.config_file:
appinfo = {}
appinfo["appName"] = input("Enter the name of your application (example: Datcord):\n")
appinfo["internalAppName"] = appinfo["appName"].replace(" ", "-").lower()
appinfo["url"] = input("Please enter the URL of your application (example: https://discord.com/app):\n")
appinfo["logoSvgFilePath"] = os.path.abspath(input("Please provide a path to a SVG of the application's logo (example: ../src/datcord.svg):\n"))
while True:
try:
appinfo["platforms"] = json.loads('{"array":' + input('List of lowercase platform names to build for (example: ["linux", "appimage", "windows"]):\n') + "}")["array"]
break
except json.JSONDecodeError:
print("Please enter the platforms in the same format as the example.")
answer = input("Should any external extensions be installed? [y/n]")
if answer == ("Y" or "y"):
try:
appinfo["extensionURLs"] = json.loads('{"array":' + input('List URLs of extensions to install (example: ["https://example.com/extension.zip"]):\n') + "}")["array"]
except json.JSONDecodeError:
appinfo["extensionURLs"] = []
appinfo["version"] = input("Enter the application version (example: 1.0.0):\n")
appinfo["projectURL"] = input("Enter the URL to your project (example: https://github.com/gamingdoom/datcord):\n")
appinfo["projectHelpURL"] = input("Enter the help URL for your project (example: https://github.com/gamingdoom/datcord/issues):\n")
while True:
answer = input("Allow links to open in the default browser? [y/n]\n")
if answer == ("y" or "Y"):
appinfo["openInDefaultBrowser"] = True
if not shutil.which("web-ext"):
print("web-ext missing! It must be installed to build support for opening links in the default browser.")
exit(1)
while True:
appinfo["openInDefaultBrowserRegex"] = input("Please enter a regular expression that matches links that shouldn't open in the default browser (example: http[s]?://discord.com):\n")
try:
pattern = re.compile(appinfo["openInDefaultBrowserRegex"])
if not pattern.match(appinfo["url"]):
print("The provided pattern matched the url of the application!")
continue
break
except:
print("Invalid regular expression!")
continue
break
elif answer == ("n" or "N"):
appinfo["openInDefaultBrowser"] = False
break
while True:
answer = input("Should the app run in the background when closed? This would make it deliver notifications even when closed. [y/n]\n")
if answer == ("y" or "Y"):
appinfo["runInBackground"] = True
break
elif answer == ("n" or "N"):
appinfo["runInBackground"] = False
break
else:
with open(args.config_file, "r") as f:
appinfo = json.load(f)
if not args.keep_build_dir:
if os.path.exists("build"):
print("Clearing build folder!")
shutil.rmtree("build")
os.mkdir("build")
shutil.copyfile("src/scripts/build.py", "build/build.py")
shutil.copytree("src", "build/src", dirs_exist_ok=True)
with open("build/config.json", "w") as f:
json.dump(appinfo, f, indent=4)
print("Done! Run build.py in the build directory to build.")
return
if __name__ == "__main__":
args = parser.parse_args()
main(args)