pyloxi: generate all openflow class modules from a single template

common.py and message.py had small amounts of special code left which were
moved into the *_extra.py subtemplates.
diff --git a/py_gen/codegen.py b/py_gen/codegen.py
index f135f18..2c4a135 100644
--- a/py_gen/codegen.py
+++ b/py_gen/codegen.py
@@ -70,36 +70,38 @@
     util.render_template(out, 'init.py', version=version)
 
 def generate_action(out, name, version):
-    util.render_template(out, 'action.py',
+    util.render_template(out, 'module.py',
                          ofclasses=modules_by_version[version]['action'],
                          version=version)
 
 def generate_oxm(out, name, version):
-    util.render_template(out, 'oxm.py',
+    util.render_template(out, 'module.py',
                          ofclasses=modules_by_version[version]['oxm'],
                          version=version)
 
 def generate_common(out, name, version):
-    util.render_template(out, 'common.py',
+    util.render_template(out, 'module.py',
                          ofclasses=modules_by_version[version]['common'],
-                         version=version)
+                         version=version,
+                         extra_template='_common_extra.py')
 
 def generate_const(out, name, version):
     util.render_template(out, 'const.py', version=version,
                          enums=loxi_globals.ir[version].enums)
 
 def generate_instruction(out, name, version):
-    util.render_template(out, 'instruction.py',
+    util.render_template(out, 'module.py',
                          ofclasses=modules_by_version[version]['instruction'],
                          version=version)
 
 def generate_message(out, name, version):
-    util.render_template(out, 'message.py',
+    util.render_template(out, 'module.py',
                          ofclasses=modules_by_version[version]['message'],
-                         version=version)
+                         version=version,
+                         extra_template='_message_extra.py')
 
 def generate_meter_band(out, name, version):
-    util.render_template(out, 'meter_band.py',
+    util.render_template(out, 'module.py',
                          ofclasses=modules_by_version[version]['meter_band'],
                          version=version)
 
diff --git a/py_gen/templates/meter_band.py b/py_gen/templates/_common_extra.py
similarity index 79%
rename from py_gen/templates/meter_band.py
rename to py_gen/templates/_common_extra.py
index 24c1f2c..8639dc4 100644
--- a/py_gen/templates/meter_band.py
+++ b/py_gen/templates/_common_extra.py
@@ -25,23 +25,14 @@
 :: # EPL for the specific language governing permissions and limitations
 :: # under the EPL.
 ::
-:: import itertools
-:: import py_gen.util as util
-:: include('_copyright.py')
-
-:: include('_autogen.py')
-
-import struct
-import const
-import util
-import loxi.generic_util
-import loxi
-
-:: for ofclass in ofclasses:
-:: if ofclass.virtual:
-:: include('_virtual_ofclass.py', ofclass=ofclass)
-:: else:
-:: include('_ofclass.py', ofclass=ofclass)
+:: from loxi_globals import OFVersions
+:: if version == OFVersions.VERSION_1_0:
+match = match_v1
+:: elif version == OFVersions.VERSION_1_1:
+match = match_v2
+:: elif version == OFVersions.VERSION_1_2:
+match = match_v3
+:: elif version == OFVersions.VERSION_1_3:
+:: # HACK
+match = match_v3
 :: #endif
-
-:: #endfor
diff --git a/py_gen/templates/message.py b/py_gen/templates/_message_extra.py
similarity index 72%
rename from py_gen/templates/message.py
rename to py_gen/templates/_message_extra.py
index 11e302f..9fc2f5e 100644
--- a/py_gen/templates/message.py
+++ b/py_gen/templates/_message_extra.py
@@ -17,7 +17,7 @@
 :: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
 :: # a copy of the EPL at:
 :: #
-:: # http::: #www.eclipse.org/legal/epl-v10.html
+:: # http://www.eclipse.org/legal/epl-v10.html
 :: #
 :: # Unless required by applicable law or agreed to in writing, software
 :: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
@@ -25,38 +25,6 @@
 :: # EPL for the specific language governing permissions and limitations
 :: # under the EPL.
 ::
-:: import itertools
-:: from loxi_globals import OFVersions
-:: import loxi_globals
-:: import py_gen.util as util
-:: import py_gen.oftype
-:: include('_copyright.py')
-
-:: include('_autogen.py')
-
-import struct
-import loxi
-import const
-import common
-import action # for unpack_list
-:: if version >= OFVersions.VERSION_1_1:
-import instruction # for unpack_list
-:: #endif
-:: if version >= OFVersions.VERSION_1_3:
-import meter_band # for unpack_list
-:: #endif
-import util
-import loxi.generic_util
-
-:: for ofclass in ofclasses:
-:: if ofclass.virtual:
-:: include('_virtual_ofclass.py', ofclass=ofclass)
-:: else:
-:: include('_ofclass.py', ofclass=ofclass)
-:: #endif
-
-:: #endfor
-
 def parse_header(buf):
     if len(buf) < 8:
         raise loxi.ProtocolError("too short to be an OpenFlow message")
diff --git a/py_gen/templates/common.py b/py_gen/templates/common.py
deleted file mode 100644
index f222e9b..0000000
--- a/py_gen/templates/common.py
+++ /dev/null
@@ -1,70 +0,0 @@
-:: # Copyright 2013, Big Switch Networks, Inc.
-:: #
-:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
-:: # the following special exception:
-:: #
-:: # LOXI Exception
-:: #
-:: # As a special exception to the terms of the EPL, you may distribute libraries
-:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
-:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
-:: # from the LoxiGen Libraries and the notice provided below is (i) included in
-:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
-:: # documentation for the LoxiGen Libraries, if distributed in binary form.
-:: #
-:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
-:: #
-:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
-:: # a copy of the EPL at:
-:: #
-:: # http://www.eclipse.org/legal/epl-v10.html
-:: #
-:: # Unless required by applicable law or agreed to in writing, software
-:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-:: # EPL for the specific language governing permissions and limitations
-:: # under the EPL.
-::
-:: include('_copyright.py')
-:: from loxi_globals import OFVersions
-:: include('_autogen.py')
-
-import sys
-import struct
-import action
-:: if version >= OFVersions.VERSION_1_1:
-import instruction # for unpack_list
-:: #endif
-:: if version >= OFVersions.VERSION_1_3:
-import meter_band # for unpack_list
-:: #endif
-import const
-import util
-import loxi.generic_util
-
-:: if version >= OFVersions.VERSION_1_2:
-import oxm
-:: #endif
-
-# HACK make this module visible as 'common' to simplify code generation
-common = sys.modules[__name__]
-
-:: for ofclass in ofclasses:
-:: if ofclass.virtual:
-:: include('_virtual_ofclass.py', ofclass=ofclass)
-:: else:
-:: include('_ofclass.py', ofclass=ofclass)
-:: #endif
-
-:: #endfor
-
-:: if version == OFVersions.VERSION_1_0:
-match = match_v1
-:: elif version == OFVersions.VERSION_1_1:
-match = match_v2
-:: elif version == OFVersions.VERSION_1_2:
-match = match_v3
-:: elif version == OFVersions.VERSION_1_3:
-:: # HACK
-match = match_v3
-:: #endif
diff --git a/py_gen/templates/instruction.py b/py_gen/templates/instruction.py
deleted file mode 100644
index da91b76..0000000
--- a/py_gen/templates/instruction.py
+++ /dev/null
@@ -1,48 +0,0 @@
-:: # Copyright 2013, Big Switch Networks, Inc.
-:: #
-:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
-:: # the following special exception:
-:: #
-:: # LOXI Exception
-:: #
-:: # As a special exception to the terms of the EPL, you may distribute libraries
-:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
-:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
-:: # from the LoxiGen Libraries and the notice provided below is (i) included in
-:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
-:: # documentation for the LoxiGen Libraries, if distributed in binary form.
-:: #
-:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
-:: #
-:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
-:: # a copy of the EPL at:
-:: #
-:: # http://www.eclipse.org/legal/epl-v10.html
-:: #
-:: # Unless required by applicable law or agreed to in writing, software
-:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-:: # EPL for the specific language governing permissions and limitations
-:: # under the EPL.
-::
-:: import itertools
-:: import py_gen.util as util
-:: include('_copyright.py')
-
-:: include('_autogen.py')
-
-import struct
-import action
-import const
-import util
-import loxi.generic_util
-import loxi
-
-:: for ofclass in ofclasses:
-:: if ofclass.virtual:
-:: include('_virtual_ofclass.py', ofclass=ofclass)
-:: else:
-:: include('_ofclass.py', ofclass=ofclass)
-:: #endif
-
-:: #endfor
diff --git a/py_gen/templates/action.py b/py_gen/templates/module.py
similarity index 86%
rename from py_gen/templates/action.py
rename to py_gen/templates/module.py
index dfd832d..252bf0d 100644
--- a/py_gen/templates/action.py
+++ b/py_gen/templates/module.py
@@ -25,21 +25,28 @@
 :: # EPL for the specific language governing permissions and limitations
 :: # under the EPL.
 ::
-:: import itertools
 :: from loxi_globals import OFVersions
-:: import py_gen.util as util
+:: import py_gen.oftype
 :: include('_copyright.py')
 
 :: include('_autogen.py')
 
 import struct
+import loxi
 import const
+import common
+import action
+:: if version >= OFVersions.VERSION_1_1:
+import instruction
+:: #endif
+:: if version >= OFVersions.VERSION_1_2:
+import oxm
+:: #endif
+:: if version >= OFVersions.VERSION_1_3:
+import meter_band
+:: #endif
 import util
 import loxi.generic_util
-import loxi
-:: if version >= OFVersions.VERSION_1_2:
-import oxm # for unpack
-:: #endif
 
 :: for ofclass in ofclasses:
 :: if ofclass.virtual:
@@ -49,3 +56,7 @@
 :: #endif
 
 :: #endfor
+
+:: if 'extra_template' in locals():
+:: include(extra_template)
+:: #endif
diff --git a/py_gen/templates/oxm.py b/py_gen/templates/oxm.py
deleted file mode 100644
index 5de771c..0000000
--- a/py_gen/templates/oxm.py
+++ /dev/null
@@ -1,47 +0,0 @@
-:: # Copyright 2013, Big Switch Networks, Inc.
-:: #
-:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
-:: # the following special exception:
-:: #
-:: # LOXI Exception
-:: #
-:: # As a special exception to the terms of the EPL, you may distribute libraries
-:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
-:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
-:: # from the LoxiGen Libraries and the notice provided below is (i) included in
-:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
-:: # documentation for the LoxiGen Libraries, if distributed in binary form.
-:: #
-:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
-:: #
-:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
-:: # a copy of the EPL at:
-:: #
-:: # http://www.eclipse.org/legal/epl-v10.html
-:: #
-:: # Unless required by applicable law or agreed to in writing, software
-:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-:: # EPL for the specific language governing permissions and limitations
-:: # under the EPL.
-::
-:: import itertools
-:: import py_gen.oftype
-:: include('_copyright.py')
-
-:: include('_autogen.py')
-
-import struct
-import const
-import util
-import loxi.generic_util
-import loxi
-
-:: for ofclass in ofclasses:
-:: if ofclass.virtual:
-:: include('_virtual_ofclass.py', ofclass=ofclass)
-:: else:
-:: include('_ofclass.py', ofclass=ofclass)
-:: #endif
-
-:: #endfor