src/tools/py2sis/ensymble/cmdmain.py
changeset 0 ca70ae20a155
equal deleted inserted replaced
-1:000000000000 0:ca70ae20a155
       
     1 #!/usr/bin/env python
       
     2 # -*- coding: utf-8 -*-
       
     3 
       
     4 ##############################################################################
       
     5 # ensymble.py - Ensymble command line tool
       
     6 # Copyright 2006, 2007, 2008, 2009 Jussi Ylänen
       
     7 #
       
     8 # This file is part of Ensymble developer utilities for Symbian OS(TM).
       
     9 #
       
    10 # Ensymble is free software; you can redistribute it and/or modify
       
    11 # it under the terms of the GNU General Public License as published by
       
    12 # the Free Software Foundation; either version 2 of the License, or
       
    13 # (at your option) any later version.
       
    14 #
       
    15 # Ensymble is distributed in the hope that it will be useful,
       
    16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    18 # GNU General Public License for more details.
       
    19 #
       
    20 # You should have received a copy of the GNU General Public License
       
    21 # along with Ensymble; if not, write to the Free Software
       
    22 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    23 ##############################################################################
       
    24 
       
    25 import sys
       
    26 import os
       
    27 
       
    28 # Import command modules.
       
    29 cmddict     = {"altere32":  None, "genuid":     None,
       
    30                "infoe32":   None, "mergesis":   None,
       
    31                "py2sis":    None, "signsis":    None,
       
    32                "simplesis": None, "version":    None}
       
    33 for cmdname in cmddict.keys():
       
    34     cmddict[cmdname] = __import__("cmd_%s" % cmdname, globals(), locals(), [])
       
    35 
       
    36 
       
    37 def main():
       
    38     pgmname = os.path.basename(sys.argv[0])
       
    39     debug   = False
       
    40 
       
    41     # Parse command line parameters.
       
    42     try:
       
    43         if len(sys.argv) < 2 or sys.argv[1] in ("-h", "--help"):
       
    44             # No command given, print help.
       
    45             commands = []
       
    46             for cmd in cmddict.keys():
       
    47                 commands.append("    %-12s %s" % (cmd, cmddict[cmd].shorthelp))
       
    48             commands.sort()
       
    49             commands = "\n".join(commands)
       
    50 
       
    51             print (
       
    52 '''
       
    53 Ensymble developer utilities for Symbian OS
       
    54 
       
    55 usage: %(pgmname)s command [command options]...
       
    56 
       
    57 Commands:
       
    58 %(commands)s
       
    59 
       
    60 Use '%(pgmname)s command --help' to get command specific help.
       
    61 ''' % locals())
       
    62             return 0
       
    63 
       
    64         command = sys.argv[1]
       
    65         if command not in cmddict.keys():
       
    66             raise ValueError("invalid command '%s'" % command)
       
    67 
       
    68         if "-h" in sys.argv[2:] or "--help" in sys.argv[2:]:
       
    69             # Print command specific help.
       
    70             longhelp = cmddict[command].longhelp
       
    71             print (
       
    72 '''
       
    73 Ensymble developer utilities for Symbian OS
       
    74 
       
    75 usage: %(pgmname)s %(longhelp)s''' % locals())
       
    76         else:
       
    77             if "--debug" in sys.argv[2:]:
       
    78                 # Enable raw exception reporting.
       
    79                 debug = True
       
    80 
       
    81             # Run command.
       
    82             cmddict[command].run(pgmname, sys.argv[2:])
       
    83     except Exception, e:
       
    84         if debug:
       
    85             # Debug output requested, print exception traceback as-is.
       
    86             raise
       
    87         else:
       
    88             # Normal output, use terse exception reporting.
       
    89             return "%s: %s" % (pgmname, str(e))
       
    90 
       
    91     return 0
       
    92 
       
    93 # Call main if run as stand-alone executable.
       
    94 #if __name__ == '__main__':
       
    95 #    sys.exit(main())
       
    96 
       
    97 # Call main regardless, to support packing with the squeeze utility.
       
    98 sys.exit(main())