File: cmdmain.py

package info (click to toggle)
ensymble 0.28-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 496 kB
  • sloc: python: 4,386; makefile: 42; sh: 31
file content (98 lines) | stat: -rwxr-xr-x 3,207 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

##############################################################################
# ensymble.py - Ensymble command line tool
# Copyright 2006, 2007, 2008, 2009 Jussi Ylänen
#
# This file is part of Ensymble developer utilities for Symbian OS(TM).
#
# Ensymble is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Ensymble is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ensymble; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
##############################################################################

import sys
import os

# Import command modules.
cmddict     = {"altere32":  None, "genuid":     None,
               "infoe32":   None, "mergesis":   None,
               "py2sis":    None, "signsis":    None,
               "simplesis": None, "version":    None}
for cmdname in cmddict.keys():
    cmddict[cmdname] = __import__("cmd_%s" % cmdname, globals(), locals(), [])


def main():
    pgmname = os.path.basename(sys.argv[0])
    debug   = False

    # Parse command line parameters.
    try:
        if len(sys.argv) < 2 or sys.argv[1] in ("-h", "--help"):
            # No command given, print help.
            commands = []
            for cmd in cmddict.keys():
                commands.append("    %-12s %s" % (cmd, cmddict[cmd].shorthelp))
            commands.sort()
            commands = "\n".join(commands)

            print (
'''
Ensymble developer utilities for Symbian OS

usage: %(pgmname)s command [command options]...

Commands:
%(commands)s

Use '%(pgmname)s command --help' to get command specific help.
''' % locals())
            return 0

        command = sys.argv[1]
        if command not in cmddict.keys():
            raise ValueError("invalid command '%s'" % command)

        if "-h" in sys.argv[2:] or "--help" in sys.argv[2:]:
            # Print command specific help.
            longhelp = cmddict[command].longhelp
            print (
'''
Ensymble developer utilities for Symbian OS

usage: %(pgmname)s %(longhelp)s''' % locals())
        else:
            if "--debug" in sys.argv[2:]:
                # Enable raw exception reporting.
                debug = True

            # Run command.
            cmddict[command].run(pgmname, sys.argv[2:])
    except Exception, e:
        if debug:
            # Debug output requested, print exception traceback as-is.
            raise
        else:
            # Normal output, use terse exception reporting.
            return "%s: %s" % (pgmname, str(e))

    return 0

# Call main if run as stand-alone executable.
#if __name__ == '__main__':
#    sys.exit(main())

# Call main regardless, to support packing with the squeeze utility.
sys.exit(main())