/usr/bin/ufo-mkfilter is in libufo-bin 0.13.0-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | #!/usr/bin/python
"""
This file generates GObject file templates that a filter author can use, to
implement their own nodes.
"""
import os
import sys
import re
import string
import textwrap
import argparse
import jinja2
class FilternameAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
if not re.match(r"^[A-Z][a-z]([A-Z][a-z0-9]*)*", values):
raise argparse.ArgumentTypeError('Name must be a camel-cased C identifier')
setattr(namespace, self.dest, values)
def generate_file(args, env, suffix='h'):
camelcased = args.name
hyphenated = args.name[0].lower() + args.name[1:]
for letter in string.ascii_uppercase:
hyphenated = hyphenated.replace(letter, "-" + letter.lower())
underscored = hyphenated.replace('-', '_')
uppercased = underscored.upper()
template = env.get_template('ufo-task.{0}.in'.format(suffix))
task_mode = [ 'UFO_TASK_MODE_{}'.format(args.type.upper()) ]
if args.use_gpu:
task_mode.append('UFO_TASK_MODE_GPU')
res = template.render(camelcased=camelcased,
uppercased=uppercased,
hyphenated=hyphenated,
underscored=underscored,
task_mode=task_mode,
args=args)
filename = "ufo-%s-task.%s" % (hyphenated, suffix)
with open(filename, 'w') as f:
f.writelines(res)
f.close()
print "Wrote %s" % filename
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate UfoNode skeletons')
parser.add_argument('-d', '--disable-comments',
action='store_false',
help='Do not insert comments into source files')
parser.add_argument('--use-gpu',
action='store_true',
help='The task requires a GPU')
parser.add_argument('--type', choices=['sink', 'processor', 'reductor', 'generator'],
default='processor',
help='Type of the generated task')
parser.add_argument('name', type=str,
action=FilternameAction,
help='Name of the new filter in CamelCase')
try:
args = parser.parse_args()
except argparse.ArgumentTypeError as err:
print err
sys.exit(1)
template_dir = '/usr/share/ufo/templates'
if not os.path.exists(template_dir):
template_dir = 'templates'
loader = jinja2.FileSystemLoader(template_dir)
env = jinja2.Environment(loader=loader, trim_blocks=True)
generate_file(args, env, 'h')
generate_file(args, env, 'c')
message = "If you are about to write a UFO internal filter, you should copy \
the generated files into core/filters and adapt the CMakeLists.txt file. You \
should only add the filter sources to ${ufo_SRCS} if all build dependencies are \
met for your particular plugin. Good luck!"
print ""
print textwrap.fill(message)
|