LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / coreplugin / authorsdialog.py
blobc5fe0c73609c61ddd9d4f9e24412cc39c8135e7f
1 #!/usr/bin/env python
3 # Helper function to generate a QML list of contributors
5 # (c) 2013, The OpenPilot Team, http://www.openpilot.org
6 # See also: The GNU Public License (GPL) Version 3
9 import optparse
10 import sys
12 def create_qml_file(args):
13 """This function reads input and template files and writes output QML file"""
15 assert args.infile is not None
16 assert args.outfile is not None
17 assert args.template is not None
19 with open(args.infile, "rt") as input_file:
20 names = input_file.readlines()
22 names_list = ""
23 for name in names:
24 if name.strip():
25 names_list += " ListElement { name: \"" + name.strip() + "\" }\r\n"
27 with open(args.template, "rb") as template_file:
28 template = template_file.read()
30 with open(args.outfile, "wb") as output_file:
31 output_file.write(template.replace("${LIST_ELEMENTS}", names_list.rstrip()))
33 return 0
35 def main():
36 """Helper function to generate a QML list of contributors"""
38 parser = optparse.OptionParser(description = main.__doc__);
40 parser.add_option('--infile', action='store',
41 help='name of input file, one name per line');
42 parser.add_option('--outfile', action='store',
43 help='name of output QML file');
44 parser.add_option('--template', action='store',
45 help='name of QML template file');
46 (args, positional_args) = parser.parse_args()
48 if (len(positional_args) != 0) or (len(sys.argv) == 1):
49 parser.error("incorrect number of arguments, try --help for help")
51 return create_qml_file(args)
53 if __name__ == "__main__":
54 sys.exit(main())