Add command line arguments
parent
bd9f5049e9
commit
6e66e8ab00
|
@ -0,0 +1,5 @@
|
||||||
|
*~*
|
||||||
|
.directory
|
||||||
|
*.kate-swap
|
||||||
|
output/*
|
||||||
|
*.pyc
|
|
@ -8,3 +8,11 @@ Created by rubenwardy.
|
||||||
License: GPL 3.0 or later
|
License: GPL 3.0 or later
|
||||||
|
|
||||||
The copyright of mesecode scripts, and any resulting Lua files, remains with their author.
|
The copyright of mesecode scripts, and any resulting Lua files, remains with their author.
|
||||||
|
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
|
```
|
||||||
|
$ python mesecode.py path/to/file.mese output/directory
|
||||||
|
```
|
36
mesecode.py
36
mesecode.py
|
@ -1,4 +1,4 @@
|
||||||
import re, sys
|
import re, sys, os
|
||||||
|
|
||||||
# How many spaces in a tab.
|
# How many spaces in a tab.
|
||||||
# -1 disables support for spaces as tabs (recommended)
|
# -1 disables support for spaces as tabs (recommended)
|
||||||
|
@ -66,6 +66,10 @@ def throwParseError(msg):
|
||||||
print("\033[91mParse Error: " + msg + "\033[0m")
|
print("\033[91mParse Error: " + msg + "\033[0m")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
def checkMkDir(directory):
|
||||||
|
if not os.path.exists(directory):
|
||||||
|
os.makedirs(directory)
|
||||||
|
|
||||||
def parse_list(the_list, line):
|
def parse_list(the_list, line):
|
||||||
if line == "":
|
if line == "":
|
||||||
return
|
return
|
||||||
|
@ -164,12 +168,26 @@ class Project:
|
||||||
if curprop is None:
|
if curprop is None:
|
||||||
throwParseError("Too many levels of indentation at " + str(lineno))
|
throwParseError("Too many levels of indentation at " + str(lineno))
|
||||||
curprop.append(line)
|
curprop.append(line)
|
||||||
|
def get(self):
|
||||||
def write(self, directory):
|
retval = "-- Mod namespace: " + self.modname + "\n"
|
||||||
print("-- Mod namespace: " + self.modname)
|
retval += "-- Generated using MeseCode\n\n"
|
||||||
print("-- Generated using the Minetest Readable Modding Format\n")
|
|
||||||
for item in self.objects:
|
for item in self.objects:
|
||||||
print(item.build(self))
|
retval += item.build(self) + "\n"
|
||||||
|
print(retval)
|
||||||
|
return retval
|
||||||
Project("test.mese").write("test")
|
|
||||||
|
def write(self, directory):
|
||||||
|
if directory.endswith("/"):
|
||||||
|
directory = directory[:-1]
|
||||||
|
checkMkDir(directory)
|
||||||
|
out = open(directory + "/init.lua", "w")
|
||||||
|
out.write(self.get())
|
||||||
|
out.close()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) == 2:
|
||||||
|
Project(sys.argv[1]).write("output")
|
||||||
|
elif len(sys.argv) == 3:
|
||||||
|
Project(sys.argv[1]).write(sys.argv[2])
|
||||||
|
else:
|
||||||
|
print("Usage: mesecode.py path/to/file.mese output/directory")
|
||||||
|
|
Loading…
Reference in New Issue