Linux altar53.supremepanel53.com 4.18.0-553.8.1.lve.el8.x86_64 #1 SMP Thu Jul 4 16:24:39 UTC 2024 x86_64
/ opt/ alt/ python27/ bin/ |
|
#!/opt/alt/python27/bin/python def render(data, kw): from mako.template import Template from mako.lookup import TemplateLookup lookup = TemplateLookup(["."]) return Template(data, lookup=lookup).render(**kw) def varsplit(var): if "=" not in var: return (var, "") return var.split("=", 1) def main(argv=None): from os.path import isfile from sys import stdin if argv is None: import sys argv = sys.argv from optparse import OptionParser parser = OptionParser("usage: %prog [FILENAME]") parser.add_option("--var", default=[], action="append", help="variable (can be used multiple times, use name=value)") opts, args = parser.parse_args(argv[1:]) if len(args) not in (0, 1): parser.error("wrong number of arguments") # Will exit if (len(args) == 0) or (args[0] == "-"): fo = stdin else: filename = args[0] if not isfile(filename): raise SystemExit("error: can't find %s" % filename) fo = open(filename) kw = dict([varsplit(var) for var in opts.var]) data = fo.read() print render(data, kw) if __name__ == "__main__": main()