-
Notifications
You must be signed in to change notification settings - Fork 1
/
make.py
executable file
·40 lines (35 loc) · 1.12 KB
/
make.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
#!/usr/bin/env python3
#
# Part of DEP-dialog
#
# [email protected] 2022-07-14
import sys
import os
# Variables
script = "./DEP-dialog"
if len(sys.argv) >= 2:
snippet_list_file = sys.argv[1]
script = script + "-" + snippet_list_file + ".zsh"
else:
snippet_list_file = "list.txt"
script = script + ".zsh"
snippet_directory = "./snippets"
template = "./template.zsh"
# load the list of snippets
with open(snippet_list_file) as my_file:
snippet_list = my_file.readlines()
# do our worst
with open(template, "r") as template_read, open(script, "w") as shellscript:
for line in template_read:
if "###SNIPPETS###" in line:
# write snippets
for snippet in snippet_list:
snippet = snippet.strip()
snippet_file = f"{snippet_directory}/{snippet}.json"
with open(snippet_file, "r") as snippet_txt:
shellscript.write(snippet_txt.read())
else:
# append content to second file
shellscript.write(line)
# we might want to run this script from the command line for testing
os.chmod(script, 0o755)