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