]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/fpd2dsc/MigrationUtilities.py
Check In tool source code based on Build tool project revision r1655.
[mirror_edk2.git] / BaseTools / Source / Python / fpd2dsc / MigrationUtilities.py
diff --git a/BaseTools/Source/Python/fpd2dsc/MigrationUtilities.py b/BaseTools/Source/Python/fpd2dsc/MigrationUtilities.py
new file mode 100644 (file)
index 0000000..d3c7248
--- /dev/null
@@ -0,0 +1,563 @@
+## @file\r
+# Contains several utilitities shared by migration tools.\r
+#\r
+# Copyright (c) 2007, Intel Corporation\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+\r
+##\r
+# Import Modules\r
+#\r
+import os\r
+import re\r
+import EdkLogger\r
+from optparse import OptionParser\r
+from Common.BuildToolError import *\r
+from XmlRoutines import *\r
+from CommonDataClass.CommonClass import *\r
+\r
+## Set all fields of CommonClass object.\r
+#\r
+# Set all attributes of CommonClass object from XML Dom object of XmlCommon.\r
+#\r
+# @param  Common     The destine CommonClass object.\r
+# @param  XmlCommon  The source XML Dom object.\r
+#\r
+def SetCommon(Common, XmlCommon):\r
+    XmlTag = "Usage"\r
+    Common.Usage = XmlAttribute(XmlCommon, XmlTag).split()\r
+\r
+    XmlTag = "FeatureFlag"\r
+    Common.FeatureFlag = XmlAttribute(XmlCommon, XmlTag)\r
+    \r
+    XmlTag = "SupArchList"\r
+    Common.SupArchList = XmlAttribute(XmlCommon, XmlTag).split()\r
+    \r
+    XmlTag = XmlNodeName(XmlCommon) + "/" + "HelpText"\r
+    Common.HelpText = XmlElement(XmlCommon, XmlTag)\r
+\r
+\r
+## Set some fields of CommonHeaderClass object.\r
+#\r
+# Set Name, Guid, FileName and FullPath fields of CommonHeaderClass object from\r
+# XML Dom object of XmlCommonHeader, NameTag and FileName.\r
+#\r
+# @param  CommonHeader       The destine CommonClass object.\r
+# @param  XmlCommonHeader    The source XML Dom object.\r
+# @param  NameTag            The name tag in XML Dom object.\r
+# @param  FileName           The file name of the XML file.\r
+#\r
+def SetIdentification(CommonHeader, XmlCommonHeader, NameTag, FileName):\r
+    XmlParentTag = XmlNodeName(XmlCommonHeader)\r
+    \r
+    XmlTag = XmlParentTag + "/" + NameTag\r
+    CommonHeader.Name = XmlElement(XmlCommonHeader, XmlTag)\r
+\r
+    XmlTag = XmlParentTag + "/" + "GuidValue"\r
+    CommonHeader.Guid = XmlElement(XmlCommonHeader, XmlTag)\r
+\r
+    XmlTag = XmlParentTag + "/" + "Version"\r
+    CommonHeader.Version = XmlElement(XmlCommonHeader, XmlTag)\r
+\r
+    CommonHeader.FileName = os.path.basename(FileName)\r
+    CommonHeader.FullPath = os.path.abspath(FileName)\r
+\r
+\r
+## Regular expression to match specification and value.\r
+mReSpecification = re.compile(r"(?P<Specification>\w+)\s+(?P<Value>\w*)")\r
+\r
+## Add specification to specification dictionary.\r
+#\r
+# Abstract specification name, value pair from Specification String and add them\r
+# to specification dictionary.\r
+#\r
+# @param  SpecificationDict   The destine Specification dictionary.\r
+# @param  SpecificationString The source Specification String from which the\r
+#                             specification name and value pair is abstracted.\r
+#\r
+def AddToSpecificationDict(SpecificationDict, SpecificationString):\r
+    """Abstract specification name, value pair from Specification String"""\r
+    for SpecificationMatch in mReSpecification.finditer(SpecificationString):\r
+        Specification = SpecificationMatch.group("Specification")\r
+        Value = SpecificationMatch.group("Value")\r
+        SpecificationDict[Specification] = Value\r
+\r
+## Set all fields of CommonHeaderClass object.\r
+#\r
+# Set all attributes of CommonHeaderClass object from XML Dom object of\r
+# XmlCommonHeader, NameTag and FileName.\r
+#\r
+# @param  CommonHeader       The destine CommonClass object.\r
+# @param  XmlCommonHeader    The source XML Dom object.\r
+# @param  NameTag            The name tag in XML Dom object.\r
+# @param  FileName           The file name of the XML file.\r
+#\r
+def SetCommonHeader(CommonHeader, XmlCommonHeader):\r
+    """Set all attributes of CommonHeaderClass object from XmlCommonHeader"""\r
+    XmlParent = XmlNodeName(XmlCommonHeader)\r
+    \r
+    XmlTag = XmlParent + "/" + "Abstract"\r
+    CommonHeader.Abstract = XmlElement(XmlCommonHeader, XmlTag)\r
+\r
+    XmlTag = XmlParent + "/" + "Description"\r
+    CommonHeader.Description = XmlElement(XmlCommonHeader, XmlTag)\r
+\r
+    XmlTag = XmlParent + "/" + "Copyright"\r
+    CommonHeader.Copyright = XmlElement(XmlCommonHeader, XmlTag)\r
+\r
+    XmlTag = XmlParent + "/" + "License"\r
+    CommonHeader.License = XmlElement(XmlCommonHeader, XmlTag)\r
+\r
+    XmlTag = XmlParent + "/" + "Specification"\r
+    Specification = XmlElement(XmlCommonHeader, XmlTag)\r
+\r
+    AddToSpecificationDict(CommonHeader.Specification, Specification)\r
+\r
+    XmlTag = XmlParent + "/" + "ModuleType"\r
+    CommonHeader.ModuleType = XmlElement(XmlCommonHeader, XmlTag)\r
+\r
+\r
+## Load a new Cloned Record class object.\r
+#\r
+# Read an input XML ClonedRecord DOM object and return an object of Cloned Record\r
+# contained in the DOM object.\r
+#\r
+# @param  XmlCloned            A child XML DOM object in a Common XML DOM.\r
+#\r
+# @retvel ClonedRecord         A new Cloned Record object created by XmlCloned.\r
+#\r
+def LoadClonedRecord(XmlCloned):\r
+    ClonedRecord = ClonedRecordClass()\r
+\r
+    XmlTag = "Id"\r
+    ClonedRecord.Id = int(XmlAttribute(XmlCloned, XmlTag))\r
+\r
+    XmlTag = "FarGuid"\r
+    ClonedRecord.FarGuid = XmlAttribute(XmlCloned, XmlTag)\r
+\r
+    XmlTag = "Cloned/PackageGuid"\r
+    ClonedRecord.PackageGuid = XmlElement(XmlCloned, XmlTag)\r
+    \r
+    XmlTag = "Cloned/PackageVersion"\r
+    ClonedRecord.PackageVersion = XmlElement(XmlCloned, XmlTag)\r
+    \r
+    XmlTag = "Cloned/ModuleGuid"\r
+    ClonedRecord.ModuleGuid = XmlElement(XmlCloned, XmlTag)\r
+    \r
+    XmlTag = "Cloned/ModuleVersion"\r
+    ClonedRecord.ModuleVersion = XmlElement(XmlCloned, XmlTag)\r
+    \r
+    return ClonedRecord\r
+\r
+\r
+## Load a new Guid/Protocol/Ppi common class object.\r
+#\r
+# Read an input XML Guid/Protocol/Ppi DOM object and return an object of\r
+# Guid/Protocol/Ppi contained in the DOM object.\r
+#\r
+# @param  XmlGuidProtocolPpiCommon A child XML DOM object in a Common XML DOM.\r
+#\r
+# @retvel GuidProtocolPpiCommon    A new GuidProtocolPpiCommon class object\r
+#                                  created by XmlGuidProtocolPpiCommon.\r
+#\r
+def LoadGuidProtocolPpiCommon(XmlGuidProtocolPpiCommon):\r
+    GuidProtocolPpiCommon = GuidProtocolPpiCommonClass()\r
+    \r
+    XmlTag = "Name"\r
+    GuidProtocolPpiCommon.Name = XmlAttribute(XmlGuidProtocolPpiCommon, XmlTag)\r
+\r
+    XmlParent = XmlNodeName(XmlGuidProtocolPpiCommon)\r
+    if XmlParent == "Entry":\r
+        XmlTag = "%s/C_Name" % XmlParent\r
+    elif XmlParent == "GuidCNames":\r
+        XmlTag = "%s/GuidCName" % XmlParent\r
+    else:\r
+        XmlTag = "%s/%sCName" % (XmlParent, XmlParent)\r
+        \r
+    GuidProtocolPpiCommon.CName = XmlElement(XmlGuidProtocolPpiCommon, XmlTag)\r
+    \r
+    XmlTag = XmlParent + "/" + "GuidValue"\r
+    GuidProtocolPpiCommon.Guid = XmlElement(XmlGuidProtocolPpiCommon, XmlTag)\r
+    \r
+    if XmlParent.endswith("Notify"):\r
+        GuidProtocolPpiCommon.Notify = True\r
+\r
+    XmlTag = "GuidTypeList"\r
+    GuidTypes = XmlAttribute(XmlGuidProtocolPpiCommon, XmlTag)\r
+    GuidProtocolPpiCommon.GuidTypeList = GuidTypes.split()\r
+    \r
+    XmlTag = "SupModuleList"\r
+    SupModules = XmlAttribute(XmlGuidProtocolPpiCommon, XmlTag)\r
+    GuidProtocolPpiCommon.SupModuleList = SupModules.split()\r
+\r
+    SetCommon(GuidProtocolPpiCommon, XmlGuidProtocolPpiCommon)\r
+\r
+    return GuidProtocolPpiCommon\r
+\r
+\r
+## Load a new Pcd class object.\r
+#\r
+# Read an input XML Pcd DOM object and return an object of Pcd\r
+# contained in the DOM object.\r
+#\r
+# @param  XmlPcd               A child XML DOM object in a Common XML DOM.\r
+#\r
+# @retvel Pcd                  A new Pcd object created by XmlPcd.\r
+#\r
+def LoadPcd(XmlPcd):\r
+    """Return a new PcdClass object equivalent to XmlPcd"""\r
+    Pcd = PcdClass()\r
+\r
+    XmlTag = "PcdEntry/C_Name"\r
+    Pcd.CName = XmlElement(XmlPcd, XmlTag)\r
+\r
+    XmlTag = "PcdEntry/Token"\r
+    Pcd.Token = XmlElement(XmlPcd, XmlTag)\r
+\r
+    XmlTag = "PcdEntry/TokenSpaceGuidCName"\r
+    Pcd.TokenSpaceGuidCName = XmlElement(XmlPcd, XmlTag)\r
+\r
+    XmlTag = "PcdEntry/DatumType"\r
+    Pcd.DatumType = XmlElement(XmlPcd, XmlTag)\r
+\r
+    XmlTag = "PcdEntry/MaxDatumSize"\r
+    Pcd.MaxDatumSize = XmlElement(XmlPcd, XmlTag)\r
+\r
+    XmlTag = "PcdEntry/DefaultValue"\r
+    Pcd.DefaultValue = XmlElement(XmlPcd, XmlTag)\r
+\r
+    XmlTag = "PcdItemType"\r
+    Pcd.ItemType = XmlAttribute(XmlPcd, XmlTag)\r
+\r
+    XmlTag = "PcdEntry/ValidUsage"\r
+    Pcd.ValidUsage = XmlElement(XmlPcd, XmlTag).split()\r
+\r
+    XmlTag = "SupModuleList"\r
+    Pcd.SupModuleList = XmlAttribute(XmlPcd, XmlTag).split()\r
+\r
+    SetCommon(Pcd, XmlPcd)\r
+\r
+    return Pcd\r
+\r
+\r
+## Load a new LibraryClass class object.\r
+#\r
+# Read an input XML LibraryClass DOM object and return an object of LibraryClass\r
+# contained in the DOM object.\r
+#\r
+# @param  XmlLibraryClass    A child XML DOM object in a Common XML DOM.\r
+#\r
+# @retvel LibraryClass       A new LibraryClass object created by XmlLibraryClass.\r
+#\r
+def LoadLibraryClass(XmlLibraryClass):\r
+    LibraryClass = LibraryClassClass()\r
+\r
+    XmlTag = "LibraryClass/Keyword"\r
+    LibraryClass.LibraryClass = XmlElement(XmlLibraryClass, XmlTag)\r
+    if LibraryClass.LibraryClass == "":\r
+        XmlTag = "Name"\r
+        LibraryClass.LibraryClass = XmlAttribute(XmlLibraryClass, XmlTag)\r
+    \r
+    XmlTag = "LibraryClass/IncludeHeader"\r
+    LibraryClass.IncludeHeader = XmlElement(XmlLibraryClass, XmlTag)\r
+    \r
+    XmlTag = "RecommendedInstanceVersion"\r
+    RecommendedInstanceVersion = XmlAttribute(XmlLibraryClass, XmlTag)\r
+    LibraryClass.RecommendedInstanceVersion = RecommendedInstanceVersion\r
+    \r
+    XmlTag = "RecommendedInstanceGuid"\r
+    RecommendedInstanceGuid = XmlAttribute(XmlLibraryClass, XmlTag)\r
+    LibraryClass.RecommendedInstanceGuid = RecommendedInstanceGuid\r
+    \r
+    XmlTag = "SupModuleList"\r
+    SupModules = XmlAttribute(XmlLibraryClass, XmlTag)\r
+    LibraryClass.SupModuleList = SupModules.split()\r
+    \r
+    SetCommon(LibraryClass, XmlLibraryClass)\r
+    \r
+    return LibraryClass\r
+\r
+\r
+## Load a new Build Option class object.\r
+#\r
+# Read an input XML BuildOption DOM object and return an object of Build Option\r
+# contained in the DOM object.\r
+#\r
+# @param  XmlBuildOption       A child XML DOM object in a Common XML DOM.\r
+#\r
+# @retvel BuildOption          A new Build Option object created by XmlBuildOption.\r
+#\r
+def LoadBuildOption(XmlBuildOption):\r
+    """Return a new BuildOptionClass object equivalent to XmlBuildOption"""\r
+    BuildOption = BuildOptionClass()\r
+    \r
+    BuildOption.Option = XmlElementData(XmlBuildOption)\r
+\r
+    XmlTag = "BuildTargets"\r
+    BuildOption.BuildTargetList = XmlAttribute(XmlBuildOption, XmlTag).split()\r
+    \r
+    XmlTag = "ToolChainFamily"\r
+    BuildOption.ToolChainFamily = XmlAttribute(XmlBuildOption, XmlTag)\r
+    \r
+    XmlTag = "TagName"\r
+    BuildOption.TagName = XmlAttribute(XmlBuildOption, XmlTag)\r
+    \r
+    XmlTag = "ToolCode"\r
+    BuildOption.ToolCode = XmlAttribute(XmlBuildOption, XmlTag)\r
+    \r
+    XmlTag = "SupArchList"\r
+    BuildOption.SupArchList = XmlAttribute(XmlBuildOption, XmlTag).split()\r
+    \r
+    return BuildOption\r
+\r
+\r
+## Load a new User Extensions class object.\r
+#\r
+# Read an input XML UserExtensions DOM object and return an object of User\r
+# Extensions contained in the DOM object.\r
+#\r
+# @param  XmlUserExtensions    A child XML DOM object in a Common XML DOM.\r
+#\r
+# @retvel UserExtensions       A new User Extensions object created by\r
+#                              XmlUserExtensions.\r
+#\r
+def LoadUserExtensions(XmlUserExtensions):\r
+    UserExtensions = UserExtensionsClass()\r
+    \r
+    XmlTag = "UserId"\r
+    UserExtensions.UserID = XmlAttribute(XmlUserExtensions, XmlTag)\r
+    \r
+    XmlTag = "Identifier"\r
+    UserExtensions.Identifier = XmlAttribute(XmlUserExtensions, XmlTag)\r
+    \r
+    UserExtensions.Content = XmlElementData(XmlUserExtensions)\r
+    \r
+    return UserExtensions\r
+\r
+\r
+## Store content to a text file object.\r
+#\r
+# Write some text file content to a text file object. The contents may echo\r
+# in screen in a verbose way.\r
+#\r
+# @param  TextFile           The text file object.\r
+# @param  Content            The string object to be written to a text file.\r
+#\r
+def StoreTextFile(TextFile, Content):\r
+    EdkLogger.verbose(Content)\r
+    TextFile.write(Content)\r
+\r
+\r
+## Add item to a section.\r
+#\r
+# Add an Item with specific CPU architecture to section dictionary.\r
+# The possible duplication is ensured to be removed.\r
+#\r
+# @param  Section            Section dictionary indexed by CPU architecture.\r
+# @param  Arch               CPU architecture: Ia32, X64, Ipf, Ebc or Common.\r
+# @param  Item               The Item to be added to section dictionary.\r
+#\r
+def AddToSection(Section, Arch, Item):\r
+    SectionArch = Section.get(Arch, [])\r
+    if Item not in SectionArch:\r
+        SectionArch.append(Item)\r
+        Section[Arch] = SectionArch\r
+\r
+\r
+## Get section contents.\r
+#\r
+# Return the content of section named SectionName.\r
+# the contents is based on Methods and ObjectLists.\r
+#\r
+# @param  SectionName        The name of the section.\r
+# @param  Method             A function returning a string item of an object.\r
+# @param  ObjectList         The list of object.\r
+#\r
+# @retval Section            The string content of a section.\r
+#\r
+def GetSection(SectionName, Method, ObjectList):\r
+    SupportedArches = ["common", "Ia32", "X64", "Ipf", "Ebc"]\r
+    SectionDict = {}\r
+    for Object in ObjectList:\r
+        Item = Method(Object)\r
+        if Item == "":\r
+            continue\r
+        Item = "  %s" % Item\r
+        Arches = Object.SupArchList\r
+        if len(Arches) == 0:\r
+            AddToSection(SectionDict, "common", Item)\r
+        else:\r
+            for Arch in SupportedArches:\r
+                if Arch.upper() in Arches:\r
+                    AddToSection(SectionDict, Arch, Item)\r
+\r
+    Section = ""\r
+    for Arch in SupportedArches:\r
+        SectionArch = "\n".join(SectionDict.get(Arch, []))\r
+        if SectionArch != "":\r
+            Section += "[%s.%s]\n%s\n" % (SectionName, Arch, SectionArch)\r
+            Section += "\n"\r
+    if Section != "":\r
+        Section += "\n"\r
+    return Section\r
+\r
+\r
+## Store file header to a text file.\r
+#\r
+# Write standard file header to a text file. The content includes copyright,\r
+# abstract, description and license extracted from CommonHeader class object.\r
+#\r
+# @param  TextFile           The text file object.\r
+# @param  CommonHeader       The source CommonHeader class object.\r
+#\r
+def StoreHeader(TextFile, CommonHeader):\r
+    CopyRight = CommonHeader.Copyright\r
+    Abstract = CommonHeader.Abstract\r
+    Description = CommonHeader.Description\r
+    License = CommonHeader.License\r
+\r
+    Header =  "#/** @file\n#\n"\r
+    Header += "# " + Abstract + "\n#\n"\r
+    Header += "# " + Description.strip().replace("\n", "\n# ") + "\n"\r
+    Header += "# " + CopyRight + "\n#\n"\r
+    Header += "#  " + License.replace("\n", "\n# ").replace("  ", " ")\r
+    Header += "\n#\n#**/\n\n"\r
+\r
+    StoreTextFile(TextFile, Header)\r
+\r
+## Store file header to a text file.\r
+#\r
+# Write Defines section to a text file. DefinesTupleList determines the content.\r
+#\r
+# @param  TextFile           The text file object.\r
+# @param  DefinesTupleList   The list of (Tag, Value) to be added as one item.\r
+#\r
+def StoreDefinesSection(TextFile, DefinesTupleList):\r
+    Section = "[Defines]\n"\r
+    for DefineItem in DefinesTupleList:\r
+        Section += "  %-30s = %s\n" % DefineItem\r
+\r
+    Section += "\n\n"\r
+    StoreTextFile(TextFile, Section)\r
+\r
+\r
+## Add item to PCD dictionary.\r
+#\r
+# Add an PcdClass object to PCD dictionary. The key is generated from\r
+# PcdItemType.\r
+#\r
+# @param  PcdDict            PCD dictionary indexed by Pcd Item Type.\r
+# @param  Arch               CPU architecture: Ia32, X64, Ipf, Ebc or Common.\r
+# @param  Item               The Item to be added to section dictionary.\r
+#\r
+def AddToPcdsDict(PcdDict, PcdItemType, PcdCode):\r
+    PcdSectionName = PcdItemType\r
+    PcdSectionName = PcdSectionName.title()\r
+    PcdSectionName = PcdSectionName.replace("_", "")\r
+    PcdSectionName = "Pcds" + PcdSectionName\r
+    PcdDict.setdefault(PcdSectionName, []).append(PcdCode)\r
+\r
+## Regular expression to match an equation.\r
+mReEquation = re.compile(r"\s*(\S+)\s*=\s*(\S*)\s*")\r
+\r
+## Return a value tuple matching information in a text fle.\r
+#\r
+# Parse the text file and return a value tuple corresponding to an input tag\r
+# tuple. In case of any error, an tuple of empty strings is returned.\r
+#\r
+# @param  FileName           The file name of the text file.\r
+# @param  TagTuple           A tuple of tags as the key to the value.\r
+#\r
+# @param  ValueTupe          The returned tuple corresponding to the tag tuple.\r
+#\r
+def GetTextFileInfo(FileName, TagTuple):\r
+    ValueTuple = [""] * len(TagTuple)\r
+    try:\r
+        for Line in open(FileName):\r
+            Line = Line.split("#", 1)[0]\r
+            MatchEquation = mReEquation.match(Line)\r
+            if MatchEquation:\r
+                Tag = MatchEquation.group(1).upper()\r
+                Value = MatchEquation.group(2)\r
+                for Index in range(len(TagTuple)):\r
+                    if TagTuple[Index] == Tag:\r
+                        ValueTuple[Index] = Value\r
+    except:\r
+        EdkLogger.info("IO Error in reading file %s" % FileName)\r
+        \r
+    return ValueTuple\r
+\r
+## Return a value tuple matching information in an XML fle.\r
+#\r
+# Parse the XML file and return a value tuple corresponding to an input tag\r
+# tuple. In case of any error, an tuple of empty strings is returned.\r
+#\r
+# @param  FileName           The file name of the XML file.\r
+# @param  TagTuple           A tuple of tags as the key to the value.\r
+#\r
+# @param  ValueTupe          The returned tuple corresponding to the tag tuple.\r
+#\r
+def GetXmlFileInfo(FileName, TagTuple):\r
+    XmlDom = XmlParseFile(FileName)\r
+    return tuple([XmlElement(XmlDom, XmlTag) for XmlTag in TagTuple])\r
+\r
+# Version and Copyright\r
+__version_number__ = "1.0"\r
+__version__ = "%prog Version " + __version_number__\r
+__copyright__ = "Copyright (c) 2007, Intel Corporation. All rights reserved."\r
+\r
+## Parse migration command line options\r
+#\r
+# Use standard Python module optparse to parse command line option of this tool.\r
+#\r
+# @param  Source             The source file type.\r
+# @param  Destinate          The destinate file type.\r
+#\r
+# @retval Options            A optparse object containing the parsed options.\r
+# @retval InputFile          Path of an source file to be migrated.\r
+#\r
+def MigrationOptionParser(Source, Destinate):\r
+    # use clearer usage to override default usage message\r
+    UsageString = "%prog [-a] [-o <output_file>] <input_file>"\r
+\r
+    Parser = OptionParser(description=__copyright__, version=__version__, usage=UsageString)\r
+\r
+    HelpText = "The name of the %s file to be created." % Destinate\r
+    Parser.add_option("-o", "--output", dest="OutputFile", help=HelpText)\r
+    \r
+    HelpText = "Automatically create the %s file using the name of the %s file and replacing file extension" % (Source, Destinate)\r
+    Parser.add_option("-a", "--auto", dest="AutoWrite", action="store_true", default=False, help=HelpText)\r
+\r
+    Options, Args = Parser.parse_args()\r
+\r
+    # error check\r
+    if len(Args) == 0:\r
+        raise MigrationError(OPTION_MISSING, name="Input file", usage=Parser.get_usage())\r
+    if len(Args) > 1:\r
+        raise MigrationError(OPTION_NOT_SUPPORTED, name="Too many input files", usage=Parser.get_usage())\r
+\r
+    InputFile = Args[0]\r
+    if not os.path.exists(InputFile):\r
+        raise MigrationError(FILE_NOT_FOUND, name=InputFile)\r
+\r
+    if Options.OutputFile:\r
+        if Options.AutoWrite:\r
+            raise MigrationError(OPTION_CONFLICT, arg1="-o", arg2="-a", usage=Parser.get_usage())\r
+    else:\r
+        if Options.AutoWrite:\r
+            Options.OutputFile = os.path.splitext(InputFile)[0] + "." + Destinate.lower()\r
+        else:\r
+            raise MigrationError(OPTION_MISSING, name="-o", usage=Parser.get_usage())\r
+\r
+    return Options, InputFile\r
+\r
+# This acts like the main() function for the script, unless it is 'import'ed\r
+# into another script.\r
+if __name__ == '__main__':\r
+    pass\r