]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/fpd2dsc/fpd2dsc.py
Sync BaseTools Branch (version r2321) to EDKII main trunk.
[mirror_edk2.git] / BaseTools / Source / Python / fpd2dsc / fpd2dsc.py
1 ## @file
2 # Convert an XML-based FPD file to a text-based DSC file.
3 #
4 # Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13
14 ##
15 # Import Modules
16 #
17 import os, re, sys, xml.dom.minidom #XmlRoutines, EdkIIWorkspace
18 from LoadFpd import LoadFpd
19 from StoreDsc import StoreDsc
20 from optparse import OptionParser
21 from Common.BuildVersion import gBUILD_VERSION
22
23 # Version and Copyright
24 __version_number__ = ("1.0" + " " + gBUILD_VERSION)
25 __version__ = "%prog Version " + __version_number__
26 __copyright__ = "Copyright (c) 2007 - 2010, Intel Corporation All rights reserved."
27
28 ## Parse command line options
29 #
30 # Using standard Python module optparse to parse command line option of this tool.
31 #
32 # @retval Options A optparse.Values object containing the parsed options
33 # @retval Args All the arguments got from the command line
34 #
35 def MyOptionParser():
36 """ Argument Parser """
37 usage = "%prog [options] input_filename"
38 parser = OptionParser(usage=usage,description=__copyright__,version="%prog " + str(__version_number__))
39 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.")
40 parser.add_option("-a", "--auto", action="store_true", dest="autowrite", default=False, help="Automatically create output files and write the DSC file")
41 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")
42 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")
43 parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="Enable printing of debug messages.")
44 parser.add_option("-w", "--workspace", dest="workspace", default=str(os.environ.get('WORKSPACE')), help="Specify workspace directory.")
45 (options, args) = parser.parse_args(sys.argv[1:])
46
47 return options,args
48
49 ## Entrance method
50 #
51 # This method mainly dispatch specific methods per the command line options.
52 # If no error found, return zero value so the caller of this tool can know
53 # if it's executed successfully or not.
54 #
55 # @retval 0 Tool was successful
56 # @retval 1 Tool failed
57 #
58 def Main():
59 global Options
60 global Args
61 global WorkSpace
62 Options,Args = MyOptionParser()
63
64 WorkSpace = ""
65 #print Options.workspace
66 if (Options.workspace == None):
67 print "ERROR: E0000: WORKSPACE not defined.\n Please set the WORKSPACE environment variable to the location of the EDK II install directory."
68 sys.exit(1)
69 else:
70 WorkSpace = Options.workspace
71 if (Options.debug):
72 print "Using Workspace:", WorkSpace
73 try:
74 Options.verbose +=1
75 except:
76 Options.verbose = 1
77 pass
78
79 InputFile = ""
80 if Args == []:
81 print "usage:" "%prog [options] input_filename"
82 else:
83 InputFile = Args[0]
84 #print InputFile
85 if InputFile != "":
86 FileName = InputFile
87 if ((Options.verbose > 1) | (Options.autowrite)):
88 print "FileName:",InputFile
89 else:
90 print "ERROR: E0001 - You must specify an input filename"
91 sys.exit(1)
92
93 if (Options.outfile):
94 OutputFile = Options.outfile
95 else:
96 OutputFile = FileName.replace('.fpd', '.dsc')
97
98 if ((Options.verbose > 2) or (Options.debug)):
99 print "Output Filename:", OutputFile
100
101 try:
102 Platform = LoadFpd(FileName)
103 StoreDsc(OutputFile, Platform)
104 return 0
105 except Exception, e:
106 print e
107 return 1
108
109 if __name__ == '__main__':
110 sys.exit(Main())
111 #pass
112 #global Options
113 #global Args
114 #Options,Args = MyOptionParser()
115
116 #Main()
117 #sys.exit(0)