summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/fpd2dsc/fpd2dsc.py
blob: 4a65e615a404be36e904c51a4b2967fb59273c54 (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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
## @file
# Convert an XML-based FPD file to a text-based DSC file.
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution.  The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#

##
# Import Modules
#
import os, re, sys, xml.dom.minidom  #XmlRoutines, EdkIIWorkspace
from LoadFpd import LoadFpd
from StoreDsc import StoreDsc
from optparse import OptionParser
from Common.BuildVersion import gBUILD_VERSION

# Version and Copyright
__version_number__ = ("1.0" + " " + gBUILD_VERSION)
__version__ = "%prog Version " + __version_number__
__copyright__ = "Copyright (c) 2007 - 2010, Intel Corporation  All rights reserved."

## Parse command line options
#
# Using standard Python module optparse to parse command line option of this tool.
#
# @retval Options   A optparse.Values object containing the parsed options
# @retval Args      All the arguments got from the command line
#
def MyOptionParser():
    """ Argument Parser """
    usage = "%prog [options] input_filename"
    parser = OptionParser(usage=usage,description=__copyright__,version="%prog " + str(__version_number__))
    parser.add_option("-o", "--output", dest="outfile", help="Specific Name of the DSC file to create, otherwise it is the FPD filename with the extension repalced.")
    parser.add_option("-a", "--auto", action="store_true", dest="autowrite", default=False, help="Automatically create output files and write the DSC file")
    parser.add_option("-q", "--quiet", action="store_const", const=0, dest="verbose", help="Do not print any messages, just return either 0 for succes or 1 for failure")
    parser.add_option("-v", "--verbose", action="count", dest="verbose", help="Do not print any messages, just return either 0 for succes or 1 for failure")
    parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="Enable printing of debug messages.")
    parser.add_option("-w", "--workspace", dest="workspace", default=str(os.environ.get('WORKSPACE')), help="Specify workspace directory.")
    (options, args) = parser.parse_args(sys.argv[1:])

    return options,args

## Entrance method
#
# This method mainly dispatch specific methods per the command line options.
# If no error found, return zero value so the caller of this tool can know
# if it's executed successfully or not.
#
# @retval 0     Tool was successful
# @retval 1     Tool failed
#
def Main():
    global Options
    global Args
    global WorkSpace
    Options,Args = MyOptionParser()

    WorkSpace = ""
    #print Options.workspace
    if (Options.workspace == None):
        print "ERROR: E0000: WORKSPACE not defined.\n  Please set the WORKSPACE environment variable to the location of the EDK II install directory."
        sys.exit(1)
    else:
        WorkSpace = Options.workspace
        if (Options.debug):
            print "Using Workspace:", WorkSpace
    try:
        Options.verbose +=1
    except:
        Options.verbose = 1
        pass

    InputFile = ""
    if Args == []:
        print "usage:" "%prog [options] input_filename"
    else:
        InputFile = Args[0]
        #print InputFile
    if InputFile != "":
        FileName = InputFile
        if ((Options.verbose > 1) | (Options.autowrite)):
            print "FileName:",InputFile
    else:
        print "ERROR: E0001 - You must specify an input filename"
        sys.exit(1)

    if (Options.outfile):
        OutputFile = Options.outfile
    else:
       OutputFile = FileName.replace('.fpd', '.dsc')

    if ((Options.verbose > 2) or (Options.debug)):
        print "Output Filename:", OutputFile
        
    try:
        Platform = LoadFpd(FileName)
        StoreDsc(OutputFile, Platform)
        return 0
    except Exception, e:
        print e
        return 1

if __name__ == '__main__':
    sys.exit(Main())
    #pass
    #global Options
    #global Args
    #Options,Args = MyOptionParser()
    
    #Main()
    #sys.exit(0)