summaryrefslogtreecommitdiff
path: root/common/lib/mmtcgen/mmtcgen.py
blob: a8cf312fb44288bc86c3c83b989546c907653901 (plain)
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
#!/usr/bin/python

#############################################################################
#  Copyright (C) 2010 Spidcom
#
#############################################################################

import sys
import os
from core import MMTypeConstGen

# Find the path for the MME txt file.
path = os.path.dirname (__file__)
# dirname function return "" if the script is run in its directory
mmetxt = "%s/mme.txt" % ("." if path == "" else path)

def mmtypes_list ():
    """Generate a dictionary containing the MMTypes."""
    m = MMTypeConstGen (mmetxt)
    try:
        m.parse ()
    except RuntimeError, e:
        print >> sys.stderr, "error:", e
    return m.mmtype_dict ()

if __name__ == "__main__":
    from optparse import OptionParser
    usage = "%prog outfile"
    parser = OptionParser (usage = usage)
    [options, args] = parser.parse_args()
    # Verify we have at most 2 arguments.
    if len (args) > 1:
        parser.error ("too many arguments")

    outfile = None
    if len (args) == 1:
        outfile = args.pop ()
    m = MMTypeConstGen (mmetxt, outfile)
    try:
        m.process ()
    except RuntimeError, e:
        print >> sys.stderr, "error:", e
        sys.exit (1)