EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

BaseTools/Source/Python/fpd2dsc/fpd2dsc.py

Go to the documentation of this file.
00001 ## @file
00002 # Convert an XML-based FPD file to a text-based DSC file.
00003 #
00004 # Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
00005 # This program and the accompanying materials
00006 # are licensed and made available under the terms and conditions of the BSD License
00007 # which accompanies this distribution.  The full text of the license may be found at
00008 # http://opensource.org/licenses/bsd-license.php
00009 #
00010 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
00011 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
00012 #
00013 
00014 ##
00015 # Import Modules
00016 #
00017 import os, re, sys, xml.dom.minidom  #XmlRoutines, EdkIIWorkspace
00018 from LoadFpd import LoadFpd
00019 from StoreDsc import StoreDsc
00020 from optparse import OptionParser
00021 from Common.BuildVersion import gBUILD_VERSION
00022 
00023 # Version and Copyright
00024 __version_number__ = ("1.0" + " " + gBUILD_VERSION)
00025 __version__ = "%prog Version " + __version_number__
00026 __copyright__ = "Copyright (c) 2007 - 2010, Intel Corporation  All rights reserved."
00027 
00028 ## Parse command line options
00029 #
00030 # Using standard Python module optparse to parse command line option of this tool.
00031 #
00032 # @retval Options   A optparse.Values object containing the parsed options
00033 # @retval Args      All the arguments got from the command line
00034 #
00035 def MyOptionParser():
00036     """ Argument Parser """
00037     usage = "%prog [options] input_filename"
00038     parser = OptionParser(usage=usage,description=__copyright__,version="%prog " + str(__version_number__))
00039     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.")
00040     parser.add_option("-a", "--auto", action="store_true", dest="autowrite", default=False, help="Automatically create output files and write the DSC file")
00041     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")
00042     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")
00043     parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="Enable printing of debug messages.")
00044     parser.add_option("-w", "--workspace", dest="workspace", default=str(os.environ.get('WORKSPACE')), help="Specify workspace directory.")
00045     (options, args) = parser.parse_args(sys.argv[1:])
00046 
00047     return options,args
00048 
00049 ## Entrance method
00050 #
00051 # This method mainly dispatch specific methods per the command line options.
00052 # If no error found, return zero value so the caller of this tool can know
00053 # if it's executed successfully or not.
00054 #
00055 # @retval 0     Tool was successful
00056 # @retval 1     Tool failed
00057 #
00058 def Main():
00059     global Options
00060     global Args
00061     global WorkSpace
00062     Options,Args = MyOptionParser()
00063 
00064     WorkSpace = ""
00065     #print Options.workspace
00066     if (Options.workspace == None):
00067         print "ERROR: E0000: WORKSPACE not defined.\n  Please set the WORKSPACE environment variable to the location of the EDK II install directory."
00068         sys.exit(1)
00069     else:
00070         WorkSpace = Options.workspace
00071         if (Options.debug):
00072             print "Using Workspace:", WorkSpace
00073     try:
00074         Options.verbose +=1
00075     except:
00076         Options.verbose = 1
00077         pass
00078 
00079     InputFile = ""
00080     if Args == []:
00081         print "usage:" "%prog [options] input_filename"
00082     else:
00083         InputFile = Args[0]
00084         #print InputFile
00085     if InputFile != "":
00086         FileName = InputFile
00087         if ((Options.verbose > 1) | (Options.autowrite)):
00088             print "FileName:",InputFile
00089     else:
00090         print "ERROR: E0001 - You must specify an input filename"
00091         sys.exit(1)
00092 
00093     if (Options.outfile):
00094         OutputFile = Options.outfile
00095     else:
00096        OutputFile = FileName.replace('.fpd', '.dsc')
00097 
00098     if ((Options.verbose > 2) or (Options.debug)):
00099         print "Output Filename:", OutputFile
00100         
00101     try:
00102         Platform = LoadFpd(FileName)
00103         StoreDsc(OutputFile, Platform)
00104         return 0
00105     except Exception, e:
00106         print e
00107         return 1
00108 
00109 if __name__ == '__main__':
00110     sys.exit(Main())
00111     #pass
00112     #global Options
00113     #global Args
00114     #Options,Args = MyOptionParser()
00115     
00116     #Main()
00117     #sys.exit(0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines