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