-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
executable file
·81 lines (63 loc) · 2.33 KB
/
build.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
#!/usr/bin/env python3
'''
script to build nf
'''
import os
import sys
import json
import subprocess
from pathlib import Path
print("Starting build")
templates = {}
Path("dist").mkdir( 0o760, True, True )
print("Listing templates")
template_dir="./templates/"
temp = os.listdir(template_dir)
for i in temp:
with open(f"{template_dir}{i}",'r',encoding='utf-8') as file:
print(f"Adding template {i}")
text = file.readlines()
templates[i] = text
print("Reading src/main.py")
'''Read main.py to memory'''
with open('./src/main.py','r',encoding='utf-8') as file:
data = file.readlines()
print("Reading editors")
with open('./src/editors.json','r',encoding='utf-8') as file:
editors = json.load(file)
editors.sort()
print("Sorting editors")
with open('./src/editors.json','w',encoding='utf-8') as file:
json.dump(editors, file, indent=2)
print("Reading version number")
with open('version','r',encoding='utf-8') as file:
version = float(file.readlines()[0].strip())
'''Find indexes to replace'''
print("Building...")
VersionIndex = data.index('__VERSION__=""\n')
data[VersionIndex] = f"__VERSION__ = {version}\n"
TemplateIndex = data.index('templates=[]\n')-2
for i in range(4):
data.pop(TemplateIndex)
data[TemplateIndex] = f"'''\nAutomatically generated templates.\n'''\ntemplates = {json.dumps(templates,indent=2)}\n"
editorsIndex = data.index(' #This line will get replaced by src/editors\n')+1
data[editorsIndex] = f" editors = {json.dumps(editors,indent=8)}\n"
def get_manual():
with open('docs/readme.md','r',encoding='utf-8') as file:
readme = file.read()
with open('docs/templating.md','r',encoding='utf-8') as file:
templating = file.read()
nf_help = subprocess.Popen(['python3', 'dist/nf',"--help"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout,stderr = nf_help.communicate()
return f"{readme}\n{templating}\n\nusage:\n<pre>\n{stdout.decode()}\n</pre>\n"
def write():
'''Write to file'''
with open('dist/nf', 'w', encoding='utf-8') as file:
file.writelines(data)
with open('README.md', 'w', encoding='utf-8') as file:
file.writelines(get_manual())
# print("Updating version")
# with open('version', 'w', encoding='utf-8') as file:
# file.writelines(str(version))
print("Build finished")
write()