medit/api/genlua.py

37 lines
927 B
Python
Raw Normal View History

2010-12-11 01:06:28 -08:00
#! /usr/bin/env python
2015-04-19 15:24:28 -07:00
import os
2010-12-11 01:06:28 -08:00
import sys
2010-12-12 02:29:20 -08:00
import optparse
2010-12-11 01:06:28 -08:00
from mpi.module import Module
from mpi.luawriter import Writer
2010-12-12 02:29:20 -08:00
op = optparse.OptionParser()
op.add_option("-i", "--import", action="append", dest="import_modules")
op.add_option("--include-header", action="append", dest="include_headers")
2015-04-19 15:24:28 -07:00
op.add_option("--output", dest="output")
2010-12-12 02:29:20 -08:00
(opts, args) = op.parse_args()
import_modules = []
if opts.import_modules:
for filename in opts.import_modules:
import_modules.append(Module.from_xml(filename))
2015-04-19 15:24:28 -07:00
if opts.output:
out_file = open(opts.output + '.tmp', 'w')
else:
out_file = sys.stdout
2010-12-12 02:29:20 -08:00
assert len(args) == 1
mod = Module.from_xml(args[0])
for im in import_modules:
mod.import_module(im)
2015-04-19 15:24:28 -07:00
Writer(out_file).write(mod, opts.include_headers)
if opts.output:
out_file.close()
if os.access(opts.output, os.F_OK):
os.remove(opts.output)
os.rename(opts.output + '.tmp', opts.output)