]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/fpd2dsc/fpd2dsc.py
Sync EDKII BaseTools to BaseTools project r1971
[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
22 # Version and Copyright
23 __version_number__ = "1.0"
24 __version__ = "%prog Version " + __version_number__
25 __copyright__ = "Copyright (c) 2007 - 2010, Intel Corporation All rights reserved."
26
27 ## Parse command line options
28 #
29 # Using standard Python module optparse to parse command line option of this tool.
30 #
31 # @retval Options A optparse.Values object containing the parsed options
32 # @retval Args All the arguments got from the command line
33 #
34 def MyOptionParser():
35 """ Argument Parser """
36 usage = "%prog [options] input_filename"
37 parser = OptionParser(usage=usage,description=__copyright__,version="%prog " + str(__version_number__))
38 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.")
39 parser.add_option("-a", "--auto", action="store_true", dest="autowrite", default=False, help="Automatically create output files and write the DSC file")
40 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")
41 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")
42 parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="Enable printing of debug messages.")
43 parser.add_option("-w", "--workspace", dest="workspace", default=str(os.environ.get('WORKSPACE')), help="Specify workspace directory.")
44 (options, args) = parser.parse_args(sys.argv[1:])
45
46 return options,args
47
48 ## Entrance method
49 #
50 # This method mainly dispatch specific methods per the command line options.
51 # If no error found, return zero value so the caller of this tool can know
52 # if it's executed successfully or not.
53 #
54 # @retval 0 Tool was successful
55 # @retval 1 Tool failed
56 #
57 def Main():
58 global Options
59 global Args
60 global WorkSpace
61 Options,Args = MyOptionParser()
62
63 WorkSpace = ""
64 #print Options.workspace
65 if (Options.workspace == None):
66 print "ERROR: E0000: WORKSPACE not defined.\n Please set the WORKSPACE environment variable to the location of the EDK II install directory."
67 sys.exit(1)
68 else:
69 WorkSpace = Options.workspace
70 if (Options.debug):
71 print "Using Workspace:", WorkSpace
72 try:
73 Options.verbose +=1
74 except:
75 Options.verbose = 1
76 pass
77
78 InputFile = ""
79 if Args == []:
80 print "usage:" "%prog [options] input_filename"
81 else:
82 InputFile = Args[0]
83 #print InputFile
84 if InputFile != "":
85 FileName = InputFile
86 if ((Options.verbose > 1) | (Options.autowrite)):
87 print "FileName:",InputFile
88 else:
89 print "ERROR: E0001 - You must specify an input filename"
90 sys.exit(1)
91
92 if (Options.outfile):
93 OutputFile = Options.outfile
94 else:
95 OutputFile = FileName.replace('.fpd', '.dsc')
96
97 if ((Options.verbose > 2) or (Options.debug)):
98 print "Output Filename:", OutputFile
99
100 try:
101 Platform = LoadFpd(FileName)
102 StoreDsc(OutputFile, Platform)
103 return 0
104 except Exception, e:
105 print e
106 return 1
107
108 if __name__ == '__main__':
109 sys.exit(Main())
110 #pass
111 #global Options
112 #global Args
113 #Options,Args = MyOptionParser()
114
115 #Main()
116 #sys.exit(0)