File: simple.py

package info (click to toggle)
template-glib 3.36.3-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 792 kB
  • sloc: ansic: 6,565; yacc: 288; lex: 237; python: 12; javascript: 11; makefile: 9
file content (26 lines) | stat: -rwxr-xr-x 573 bytes parent folder | download | duplicates (5)
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)