
import sys
import re

import pybindgen
from pybindgen.typehandlers import base as typehandlers
from pybindgen import (ReturnValue, Parameter, Module, Function, FileCodeSink)
from pybindgen import (CppMethod, CppConstructor, CppClass, Enum)
from pybindgen.gccxmlparser import ModuleParser
from pybindgen.function import CustomFunctionWrapper
from pybindgen.cppmethod import CustomCppMethodWrapper

import foomodulegen_common

def my_module_gen():
    out = FileCodeSink(sys.stdout)
    pygen_file = open(sys.argv[2], "wt")
    module_parser = ModuleParser('foo2', '::')
    module = module_parser.parse([sys.argv[1]], includes=['"foo.h"'], pygen_sink=FileCodeSink(pygen_file))
    pygen_file.close()

    foomodulegen_common.customize_module(module)

    module.generate(out)


if __name__ == '__main__':
    try:
        import cProfile as profile
    except ImportError:
        my_module_gen()
    else:
        print >> sys.stderr, "** running under profiler"
        profile.run('my_module_gen()', 'foomodulegen-auto.pstat')



import sys
import re

import pybindgen
from pybindgen.typehandlers import base as typehandlers
from pybindgen import (ReturnValue, Parameter, Module, Function, FileCodeSink)
from pybindgen import (CppMethod, CppConstructor, CppClass, Enum)
from pybindgen.gccxmlparser import ModuleParser
from pybindgen.function import CustomFunctionWrapper
from pybindgen.cppmethod import CustomCppMethodWrapper

import foomodulegen_common

def my_module_gen():
    out = FileCodeSink(sys.stdout)
    pygen_file = open(sys.argv[2], "wt")
    module_parser = ModuleParser('foo2', '::')
    module = module_parser.parse([sys.argv[1]], includes=['"foo.h"'], pygen_sink=FileCodeSink(pygen_file))
    pygen_file.close()

    foomodulegen_common.customize_module(module)

    module.generate(out)


def main():
    if sys.argv[1] == '-d':
        del sys.argv[1]
        import pdb
        pdb.set_trace()
        my_module_gen()
    else:
        try:
            import cProfile as profile
        except ImportError:
            my_module_gen()
        else:
            print >> sys.stderr, "** running under profiler"
            profile.run('my_module_gen()', 'foomodulegen-auto.pstat')

if __name__ == '__main__':
    main()


Add a debug switch (-d) to enable debugger
Add a debug switch (-d) to enable debugger

  
  import sys
  import re
  
  import pybindgen
  from pybindgen.typehandlers import base as typehandlers
  from pybindgen import (ReturnValue, Parameter, Module, Function, FileCodeSink)
  from pybindgen import (CppMethod, CppConstructor, CppClass, Enum)
  from pybindgen.gccxmlparser import ModuleParser
  from pybindgen.function import CustomFunctionWrapper
  from pybindgen.cppmethod import CustomCppMethodWrapper
  
  import foomodulegen_common
  
  def my_module_gen():
      out = FileCodeSink(sys.stdout)
      pygen_file = open(sys.argv[2], "wt")
      module_parser = ModuleParser('foo2', '::')
      module = module_parser.parse([sys.argv[1]], includes=['"foo.h"'], pygen_sink=FileCodeSink(pygen_file))
      pygen_file.close()
  
      foomodulegen_common.customize_module(module)
  
      module.generate(out)
  
  
- if __name__ == '__main__':
-     try:
-         import cProfile as profile
-     except ImportError:
+ def main():
+     if sys.argv[1] == '-d':
+         del sys.argv[1]
+         import pdb
+         pdb.set_trace()
          my_module_gen()
      else:
+         try:
+             import cProfile as profile
+         except ImportError:
+             my_module_gen()
+         else:
-         print >> sys.stderr, "** running under profiler"
+             print >> sys.stderr, "** running under profiler"
-         profile.run('my_module_gen()', 'foomodulegen-auto.pstat')
+             profile.run('my_module_gen()', 'foomodulegen-auto.pstat')
+ 
+ if __name__ == '__main__':
+     main()
  
  
Add a debug switch (-d) to enable debugger
## Code Before:

import sys
import re

import pybindgen
from pybindgen.typehandlers import base as typehandlers
from pybindgen import (ReturnValue, Parameter, Module, Function, FileCodeSink)
from pybindgen import (CppMethod, CppConstructor, CppClass, Enum)
from pybindgen.gccxmlparser import ModuleParser
from pybindgen.function import CustomFunctionWrapper
from pybindgen.cppmethod import CustomCppMethodWrapper

import foomodulegen_common

def my_module_gen():
    out = FileCodeSink(sys.stdout)
    pygen_file = open(sys.argv[2], "wt")
    module_parser = ModuleParser('foo2', '::')
    module = module_parser.parse([sys.argv[1]], includes=['"foo.h"'], pygen_sink=FileCodeSink(pygen_file))
    pygen_file.close()

    foomodulegen_common.customize_module(module)

    module.generate(out)


if __name__ == '__main__':
    try:
        import cProfile as profile
    except ImportError:
        my_module_gen()
    else:
        print >> sys.stderr, "** running under profiler"
        profile.run('my_module_gen()', 'foomodulegen-auto.pstat')


## Instruction:
Add a debug switch (-d) to enable debugger
## Code After:

import sys
import re

import pybindgen
from pybindgen.typehandlers import base as typehandlers
from pybindgen import (ReturnValue, Parameter, Module, Function, FileCodeSink)
from pybindgen import (CppMethod, CppConstructor, CppClass, Enum)
from pybindgen.gccxmlparser import ModuleParser
from pybindgen.function import CustomFunctionWrapper
from pybindgen.cppmethod import CustomCppMethodWrapper

import foomodulegen_common

def my_module_gen():
    out = FileCodeSink(sys.stdout)
    pygen_file = open(sys.argv[2], "wt")
    module_parser = ModuleParser('foo2', '::')
    module = module_parser.parse([sys.argv[1]], includes=['"foo.h"'], pygen_sink=FileCodeSink(pygen_file))
    pygen_file.close()

    foomodulegen_common.customize_module(module)

    module.generate(out)


def main():
    if sys.argv[1] == '-d':
        del sys.argv[1]
        import pdb
        pdb.set_trace()
        my_module_gen()
    else:
        try:
            import cProfile as profile
        except ImportError:
            my_module_gen()
        else:
            print >> sys.stderr, "** running under profiler"
            profile.run('my_module_gen()', 'foomodulegen-auto.pstat')

if __name__ == '__main__':
    main()

