home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fnb101.zip / fngen.cmd < prev    next >
OS/2 REXX Batch file  |  1999-06-28  |  4KB  |  120 lines

  1. extproc python -x %PYTHONHOME%\fngen.cmd
  2. #############################################################################
  3. # Copyright (C) DSTC Pty Ltd (ACN 052 372 577) 1997, 1998, 1999
  4. # All Rights Reserved.
  5. #
  6. # The software contained on this media is the property of the DSTC Pty
  7. # Ltd.  Use of this software is strictly in accordance with the
  8. # license agreement in the accompanying LICENSE.HTML file.  If your
  9. # distribution of this software does not contain a LICENSE.HTML file
  10. # then you have no rights to use this software in any manner and
  11. # should contact DSTC at the address below to determine an appropriate
  12. # licensing arrangement.
  13. #      DSTC Pty Ltd
  14. #      Level 7, GP South
  15. #      Staff House Road
  16. #      University of Queensland
  17. #      St Lucia, 4072
  18. #      Australia
  19. #      Tel: +61 7 3365 4310
  20. #      Fax: +61 7 3365 4311
  21. #      Email: enquiries@dstc.edu.au
  22. # This software is being provided "AS IS" without warranty of any
  23. # kind.  In no event shall DSTC Pty Ltd be liable for damage of any
  24. # kind arising out of or in connection with the use or performance of
  25. # this software.
  26. #
  27. # Project:      Fnorb
  28. # File:         $Source: /units/arch/src/Fnorb/script/RCS/fngen,v $
  29. # Version:      @(#)$RCSfile: fngen,v $ $Revision: 1.5 $
  30. #
  31. #############################################################################
  32. """ Generate Python code for Interface Repository objects. """
  33.  
  34.  
  35. # Standard/built-in modules.
  36. import sys, string
  37.  
  38. # Fnorb modules.
  39. from Fnorb.orb      import CORBA, Util
  40. from Fnorb.compiler import IDLCompiler
  41.  
  42.  
  43. # Default options.
  44. DEFAULT_DIRECTORY = '.' 
  45. DEFAULT_PACKAGE   = Util.PackageName()
  46. DEFAULT_GLOBALS   = '_GlobalIDL'
  47.  
  48.  
  49. def main(argv):
  50.     """ Do it. """
  51.  
  52.     # Default options.
  53.     directory = DEFAULT_DIRECTORY
  54.     package   = DEFAULT_PACKAGE
  55.     globals   = DEFAULT_GLOBALS
  56.  
  57.     ifr_ids = []
  58.     for arg in argv[1:]:
  59.     # Output directory option.
  60.     if arg[:12] == '--directory=':
  61.         directory = string.split(arg, '=')[1]
  62.  
  63.     # Package option.
  64.     elif arg[:10] == '--package=':
  65.         package = Util.PackageName(string.split(arg, '=')[1])
  66.  
  67.     # Global IDL package option.
  68.     elif arg[:10] == '--globals=':
  69.         globals = string.split(arg, '=')[1]
  70.  
  71.     # Interface repository ids.
  72.     elif arg[:4] == 'IDL:':
  73.         ifr_ids.append(arg)
  74.  
  75.     # Ignore anything else (including the spurious last argument '\n' on
  76.     # Windoows 95 ;^).
  77.     else:
  78.         pass
  79.  
  80.     # Create the compilation context.
  81.     context = IDLCompiler.Context(directory, package, globals)
  82.  
  83.     # Initialise the ORB.
  84.     orb = CORBA.ORB_init(argv, CORBA.ORB_ID)
  85.  
  86.     # Get a reference to the IFR.
  87.     ifr = orb.resolve_initial_references('InterfaceRepository')
  88.  
  89.     # Lookup the repository id(s) specified on the command line.
  90.     contents = []
  91.     for ifr_id in ifr_ids:
  92.     ifr_object = ifr.lookup_id(ifr_id)
  93.     if ifr_object._is_nil():
  94.         raise 'No definition found for id:', ifr_id
  95.  
  96.     contents.append(ifr_object)
  97.  
  98.     # Make sure we actually have something to do ;^)
  99.     if len(contents) > 0:
  100.     # Create an IDLCompiler to do the work!
  101.     idl_compiler = IDLCompiler.IDLCompiler()
  102.  
  103.     # Generate code for the specified objects.
  104.     idl_compiler.compile(context, contents)
  105.  
  106.     else:
  107.     print 'Hmmm, generate nothing, I can do that ;^)'
  108.  
  109.     return 0
  110.  
  111. #############################################################################
  112.  
  113. if __name__ == '__main__':
  114.     # Do it!
  115.     sys.exit(main(sys.argv[1:]))
  116.  
  117. #############################################################################
  118.