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
|
#!/usr/bin/env python3
import gi
gi.require_version('Template', '1.0')
from gi.repository import Gio
from gi.repository import Template
# Get our file to process
file = Gio.File.new_for_path('simple.tmpl')
# Create a new template and parse our input file
tmpl = Template.Template()
tmpl.parse_file(file, None)
# Create scope for expansion
scope = Template.Scope.new()
# Create and assign "title" variable in scope
title = scope.get('title')
title.assign_string('Example Title')
# Expand the template into stream
expanded = tmpl.expand_string(scope)
print(expanded)
|