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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
#!/usr/bin/env python
#---------------------------------------------------------------------------
# Name: bin/make-new-etg-file.py
# Author: Kevin Ollivier
#
# Created: 24-Sept-2011
# Copyright: (c) 2015-2020 by Kevin Ollivier, Robin Dunn
# License: wxWindows License
#---------------------------------------------------------------------------
from datetime import date
from optparse import OptionParser
import os
import sys
script_dir = os.path.dirname(__file__)
root_dir = os.path.abspath(os.path.join(script_dir, ".."))
usage = "usage: %prog [options] name module"
parser = OptionParser(usage)
parser.add_option("-a", "--author", dest="author", default="Robin Dunn")
parser.add_option("-c", "--copyright", dest="copyright", default="Total Control Software")
parser.add_option("-i", "--items", dest="items", default="", help="Comma separated list of classes to wrap")
etgstub = """\
#---------------------------------------------------------------------------
# Name: etg/%(filename)s
# Author: %(author)s
#
# Created: %(date)s
# Copyright: (c) %(year)s by %(copyright)s
# License: wxWindows License
#---------------------------------------------------------------------------
import etgtools
import etgtools.tweaker_tools as tools
PACKAGE = "wx"
MODULE = "%(module)s"
NAME = "%(name)s" # Base name of the file to generate to for this script
DOCSTRING = ""
# The classes and/or the basename of the Doxygen XML files to be processed by
# this script.
ITEMS = [ %(items)s
]
#---------------------------------------------------------------------------
def run():
# Parse the XML file(s) building a collection of Extractor objects
module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING)
etgtools.parseDoxyXML(module, ITEMS)
#-----------------------------------------------------------------
# Tweak the parsed meta objects in the module object as needed for
# customizing the generated code and docstrings.
#module.addHeaderCode('#include <wx/some_header_file.h>')
#c = module.find('')
#assert isinstance(c, etgtools.ClassDef)
#-----------------------------------------------------------------
tools.doCommonTweaks(module)
tools.runGenerators(module)
#---------------------------------------------------------------------------
if __name__ == '__main__':
run()
"""
# TODO: refactor to just use make-new-unittest-file instead of duplicating it here...
unitteststub = """\
import unittest
from unittests import wtc
import wx
#---------------------------------------------------------------------------
class %(name)s_Tests(wtc.WidgetTestCase):
# TODO: Remove this test and add real ones.
def test_%(name)s1(self):
self.fail("Unit tests for %(name)s not implemented yet.")
#---------------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()
"""
def main():
(options, args) = parser.parse_args()
if not args:
parser.print_help()
return
item_str = ""
for item in options.items.split(","):
item_str += "'%s',\n" % item
values = {
"author" : options.author,
"copyright" : options.copyright,
"items" : item_str,
"year" : date.today().strftime("%Y"),
"date" : date.today().strftime("%d-%b-%Y"),
"name" : args[0],
"filename" : args[0] + ".py",
"module" : args[1],
}
writeFile(
os.path.join(root_dir, "etg", values["filename"]), etgstub, values)
writeFile(
os.path.join(root_dir, "unittests", "test_%s.py"%values["name"]),
unitteststub, values)
def writeFile(filename, stub, values):
if os.path.exists(filename):
print("'%s' already exists. Exiting." % filename)
sys.exit(1)
with open(filename, 'w') as output:
output.write(stub % values)
print("Wrote %s" % filename)
if __name__ == '__main__':
main()
|