]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Common/MigrationUtilities.py
BaseTools/Common: add MM Module data types.
[mirror_edk2.git] / BaseTools / Source / Python / Common / MigrationUtilities.py
CommitLineData
30fdf114
LG
1## @file\r
2# Contains several utilitities shared by migration tools.\r
3#\r
1be2ed90 4# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
40d841f6 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
1be2ed90 17import Common.LongFilePathOs as os\r
30fdf114
LG
18import re\r
19import EdkLogger\r
20from optparse import OptionParser\r
21from Common.BuildToolError import *\r
22from XmlRoutines import *\r
23from CommonDataClass.CommonClass import *\r
1be2ed90 24from Common.LongFilePathSupport import OpenLongFilePath as open\r
30fdf114
LG
25\r
26## Set all fields of CommonClass object.\r
27#\r
28# Set all attributes of CommonClass object from XML Dom object of XmlCommon.\r
29#\r
30# @param Common The destine CommonClass object.\r
31# @param XmlCommon The source XML Dom object.\r
32#\r
33def SetCommon(Common, XmlCommon):\r
34 XmlTag = "Usage"\r
35 Common.Usage = XmlAttribute(XmlCommon, XmlTag).split()\r
36\r
37 XmlTag = "FeatureFlag"\r
38 Common.FeatureFlag = XmlAttribute(XmlCommon, XmlTag)\r
39 \r
40 XmlTag = "SupArchList"\r
41 Common.SupArchList = XmlAttribute(XmlCommon, XmlTag).split()\r
42 \r
43 XmlTag = XmlNodeName(XmlCommon) + "/" + "HelpText"\r
44 Common.HelpText = XmlElement(XmlCommon, XmlTag)\r
45\r
46\r
47## Set some fields of CommonHeaderClass object.\r
48#\r
49# Set Name, Guid, FileName and FullPath fields of CommonHeaderClass object from\r
50# XML Dom object of XmlCommonHeader, NameTag and FileName.\r
51#\r
52# @param CommonHeader The destine CommonClass object.\r
53# @param XmlCommonHeader The source XML Dom object.\r
54# @param NameTag The name tag in XML Dom object.\r
55# @param FileName The file name of the XML file.\r
56#\r
57def SetIdentification(CommonHeader, XmlCommonHeader, NameTag, FileName):\r
58 XmlParentTag = XmlNodeName(XmlCommonHeader)\r
59 \r
60 XmlTag = XmlParentTag + "/" + NameTag\r
61 CommonHeader.Name = XmlElement(XmlCommonHeader, XmlTag)\r
62\r
63 XmlTag = XmlParentTag + "/" + "GuidValue"\r
64 CommonHeader.Guid = XmlElement(XmlCommonHeader, XmlTag)\r
65\r
66 XmlTag = XmlParentTag + "/" + "Version"\r
67 CommonHeader.Version = XmlElement(XmlCommonHeader, XmlTag)\r
68\r
69 CommonHeader.FileName = os.path.basename(FileName)\r
70 CommonHeader.FullPath = os.path.abspath(FileName)\r
71\r
72\r
73## Regular expression to match specification and value.\r
74mReSpecification = re.compile(r"(?P<Specification>\w+)\s+(?P<Value>\w*)")\r
75\r
76## Add specification to specification dictionary.\r
77#\r
78# Abstract specification name, value pair from Specification String and add them\r
79# to specification dictionary.\r
80#\r
81# @param SpecificationDict The destine Specification dictionary.\r
82# @param SpecificationString The source Specification String from which the\r
83# specification name and value pair is abstracted.\r
84#\r
85def AddToSpecificationDict(SpecificationDict, SpecificationString):\r
86 """Abstract specification name, value pair from Specification String"""\r
87 for SpecificationMatch in mReSpecification.finditer(SpecificationString):\r
88 Specification = SpecificationMatch.group("Specification")\r
89 Value = SpecificationMatch.group("Value")\r
90 SpecificationDict[Specification] = Value\r
91\r
92## Set all fields of CommonHeaderClass object.\r
93#\r
94# Set all attributes of CommonHeaderClass object from XML Dom object of\r
95# XmlCommonHeader, NameTag and FileName.\r
96#\r
97# @param CommonHeader The destine CommonClass object.\r
98# @param XmlCommonHeader The source XML Dom object.\r
99# @param NameTag The name tag in XML Dom object.\r
100# @param FileName The file name of the XML file.\r
101#\r
102def SetCommonHeader(CommonHeader, XmlCommonHeader):\r
103 """Set all attributes of CommonHeaderClass object from XmlCommonHeader"""\r
104 XmlParent = XmlNodeName(XmlCommonHeader)\r
105 \r
106 XmlTag = XmlParent + "/" + "Abstract"\r
107 CommonHeader.Abstract = XmlElement(XmlCommonHeader, XmlTag)\r
108\r
109 XmlTag = XmlParent + "/" + "Description"\r
110 CommonHeader.Description = XmlElement(XmlCommonHeader, XmlTag)\r
111\r
112 XmlTag = XmlParent + "/" + "Copyright"\r
113 CommonHeader.Copyright = XmlElement(XmlCommonHeader, XmlTag)\r
114\r
115 XmlTag = XmlParent + "/" + "License"\r
116 CommonHeader.License = XmlElement(XmlCommonHeader, XmlTag)\r
117\r
118 XmlTag = XmlParent + "/" + "Specification"\r
119 Specification = XmlElement(XmlCommonHeader, XmlTag)\r
120\r
121 AddToSpecificationDict(CommonHeader.Specification, Specification)\r
122\r
123 XmlTag = XmlParent + "/" + "ModuleType"\r
124 CommonHeader.ModuleType = XmlElement(XmlCommonHeader, XmlTag)\r
125\r
126\r
127## Load a new Cloned Record class object.\r
128#\r
129# Read an input XML ClonedRecord DOM object and return an object of Cloned Record\r
130# contained in the DOM object.\r
131#\r
132# @param XmlCloned A child XML DOM object in a Common XML DOM.\r
133#\r
134# @retvel ClonedRecord A new Cloned Record object created by XmlCloned.\r
135#\r
136def LoadClonedRecord(XmlCloned):\r
137 ClonedRecord = ClonedRecordClass()\r
138\r
139 XmlTag = "Id"\r
140 ClonedRecord.Id = int(XmlAttribute(XmlCloned, XmlTag))\r
141\r
142 XmlTag = "FarGuid"\r
143 ClonedRecord.FarGuid = XmlAttribute(XmlCloned, XmlTag)\r
144\r
145 XmlTag = "Cloned/PackageGuid"\r
146 ClonedRecord.PackageGuid = XmlElement(XmlCloned, XmlTag)\r
147 \r
148 XmlTag = "Cloned/PackageVersion"\r
149 ClonedRecord.PackageVersion = XmlElement(XmlCloned, XmlTag)\r
150 \r
151 XmlTag = "Cloned/ModuleGuid"\r
152 ClonedRecord.ModuleGuid = XmlElement(XmlCloned, XmlTag)\r
153 \r
154 XmlTag = "Cloned/ModuleVersion"\r
155 ClonedRecord.ModuleVersion = XmlElement(XmlCloned, XmlTag)\r
156 \r
157 return ClonedRecord\r
158\r
159\r
160## Load a new Guid/Protocol/Ppi common class object.\r
161#\r
162# Read an input XML Guid/Protocol/Ppi DOM object and return an object of\r
163# Guid/Protocol/Ppi contained in the DOM object.\r
164#\r
165# @param XmlGuidProtocolPpiCommon A child XML DOM object in a Common XML DOM.\r
166#\r
167# @retvel GuidProtocolPpiCommon A new GuidProtocolPpiCommon class object\r
168# created by XmlGuidProtocolPpiCommon.\r
169#\r
170def LoadGuidProtocolPpiCommon(XmlGuidProtocolPpiCommon):\r
171 GuidProtocolPpiCommon = GuidProtocolPpiCommonClass()\r
172 \r
173 XmlTag = "Name"\r
174 GuidProtocolPpiCommon.Name = XmlAttribute(XmlGuidProtocolPpiCommon, XmlTag)\r
175\r
176 XmlParent = XmlNodeName(XmlGuidProtocolPpiCommon)\r
177 if XmlParent == "Entry":\r
178 XmlTag = "%s/C_Name" % XmlParent\r
179 elif XmlParent == "GuidCNames":\r
180 XmlTag = "%s/GuidCName" % XmlParent\r
181 else:\r
182 XmlTag = "%s/%sCName" % (XmlParent, XmlParent)\r
183 \r
184 GuidProtocolPpiCommon.CName = XmlElement(XmlGuidProtocolPpiCommon, XmlTag)\r
185 \r
186 XmlTag = XmlParent + "/" + "GuidValue"\r
187 GuidProtocolPpiCommon.Guid = XmlElement(XmlGuidProtocolPpiCommon, XmlTag)\r
188 \r
189 if XmlParent.endswith("Notify"):\r
190 GuidProtocolPpiCommon.Notify = True\r
191\r
192 XmlTag = "GuidTypeList"\r
193 GuidTypes = XmlAttribute(XmlGuidProtocolPpiCommon, XmlTag)\r
194 GuidProtocolPpiCommon.GuidTypeList = GuidTypes.split()\r
195 \r
196 XmlTag = "SupModuleList"\r
197 SupModules = XmlAttribute(XmlGuidProtocolPpiCommon, XmlTag)\r
198 GuidProtocolPpiCommon.SupModuleList = SupModules.split()\r
199\r
200 SetCommon(GuidProtocolPpiCommon, XmlGuidProtocolPpiCommon)\r
201\r
202 return GuidProtocolPpiCommon\r
203\r
204\r
205## Load a new Pcd class object.\r
206#\r
207# Read an input XML Pcd DOM object and return an object of Pcd\r
208# contained in the DOM object.\r
209#\r
210# @param XmlPcd A child XML DOM object in a Common XML DOM.\r
211#\r
212# @retvel Pcd A new Pcd object created by XmlPcd.\r
213#\r
214def LoadPcd(XmlPcd):\r
215 """Return a new PcdClass object equivalent to XmlPcd"""\r
216 Pcd = PcdClass()\r
217\r
218 XmlTag = "PcdEntry/C_Name"\r
219 Pcd.CName = XmlElement(XmlPcd, XmlTag)\r
220\r
221 XmlTag = "PcdEntry/Token"\r
222 Pcd.Token = XmlElement(XmlPcd, XmlTag)\r
223\r
224 XmlTag = "PcdEntry/TokenSpaceGuidCName"\r
225 Pcd.TokenSpaceGuidCName = XmlElement(XmlPcd, XmlTag)\r
226\r
227 XmlTag = "PcdEntry/DatumType"\r
228 Pcd.DatumType = XmlElement(XmlPcd, XmlTag)\r
229\r
230 XmlTag = "PcdEntry/MaxDatumSize"\r
231 Pcd.MaxDatumSize = XmlElement(XmlPcd, XmlTag)\r
232\r
233 XmlTag = "PcdEntry/DefaultValue"\r
234 Pcd.DefaultValue = XmlElement(XmlPcd, XmlTag)\r
235\r
236 XmlTag = "PcdItemType"\r
237 Pcd.ItemType = XmlAttribute(XmlPcd, XmlTag)\r
238\r
239 XmlTag = "PcdEntry/ValidUsage"\r
240 Pcd.ValidUsage = XmlElement(XmlPcd, XmlTag).split()\r
241\r
242 XmlTag = "SupModuleList"\r
243 Pcd.SupModuleList = XmlAttribute(XmlPcd, XmlTag).split()\r
244\r
245 SetCommon(Pcd, XmlPcd)\r
246\r
247 return Pcd\r
248\r
249\r
250## Load a new LibraryClass class object.\r
251#\r
252# Read an input XML LibraryClass DOM object and return an object of LibraryClass\r
253# contained in the DOM object.\r
254#\r
255# @param XmlLibraryClass A child XML DOM object in a Common XML DOM.\r
256#\r
257# @retvel LibraryClass A new LibraryClass object created by XmlLibraryClass.\r
258#\r
259def LoadLibraryClass(XmlLibraryClass):\r
260 LibraryClass = LibraryClassClass()\r
261\r
262 XmlTag = "LibraryClass/Keyword"\r
263 LibraryClass.LibraryClass = XmlElement(XmlLibraryClass, XmlTag)\r
264 if LibraryClass.LibraryClass == "":\r
265 XmlTag = "Name"\r
266 LibraryClass.LibraryClass = XmlAttribute(XmlLibraryClass, XmlTag)\r
267 \r
268 XmlTag = "LibraryClass/IncludeHeader"\r
269 LibraryClass.IncludeHeader = XmlElement(XmlLibraryClass, XmlTag)\r
270 \r
271 XmlTag = "RecommendedInstanceVersion"\r
272 RecommendedInstanceVersion = XmlAttribute(XmlLibraryClass, XmlTag)\r
273 LibraryClass.RecommendedInstanceVersion = RecommendedInstanceVersion\r
274 \r
275 XmlTag = "RecommendedInstanceGuid"\r
276 RecommendedInstanceGuid = XmlAttribute(XmlLibraryClass, XmlTag)\r
277 LibraryClass.RecommendedInstanceGuid = RecommendedInstanceGuid\r
278 \r
279 XmlTag = "SupModuleList"\r
280 SupModules = XmlAttribute(XmlLibraryClass, XmlTag)\r
281 LibraryClass.SupModuleList = SupModules.split()\r
282 \r
283 SetCommon(LibraryClass, XmlLibraryClass)\r
284 \r
285 return LibraryClass\r
286\r
287\r
288## Load a new Build Option class object.\r
289#\r
290# Read an input XML BuildOption DOM object and return an object of Build Option\r
291# contained in the DOM object.\r
292#\r
293# @param XmlBuildOption A child XML DOM object in a Common XML DOM.\r
294#\r
295# @retvel BuildOption A new Build Option object created by XmlBuildOption.\r
296#\r
297def LoadBuildOption(XmlBuildOption):\r
298 """Return a new BuildOptionClass object equivalent to XmlBuildOption"""\r
299 BuildOption = BuildOptionClass()\r
300 \r
301 BuildOption.Option = XmlElementData(XmlBuildOption)\r
302\r
303 XmlTag = "BuildTargets"\r
304 BuildOption.BuildTargetList = XmlAttribute(XmlBuildOption, XmlTag).split()\r
305 \r
306 XmlTag = "ToolChainFamily"\r
307 BuildOption.ToolChainFamily = XmlAttribute(XmlBuildOption, XmlTag)\r
308 \r
309 XmlTag = "TagName"\r
310 BuildOption.TagName = XmlAttribute(XmlBuildOption, XmlTag)\r
311 \r
312 XmlTag = "ToolCode"\r
313 BuildOption.ToolCode = XmlAttribute(XmlBuildOption, XmlTag)\r
314 \r
315 XmlTag = "SupArchList"\r
316 BuildOption.SupArchList = XmlAttribute(XmlBuildOption, XmlTag).split()\r
317 \r
318 return BuildOption\r
319\r
320\r
321## Load a new User Extensions class object.\r
322#\r
323# Read an input XML UserExtensions DOM object and return an object of User\r
324# Extensions contained in the DOM object.\r
325#\r
326# @param XmlUserExtensions A child XML DOM object in a Common XML DOM.\r
327#\r
328# @retvel UserExtensions A new User Extensions object created by\r
329# XmlUserExtensions.\r
330#\r
331def LoadUserExtensions(XmlUserExtensions):\r
332 UserExtensions = UserExtensionsClass()\r
333 \r
334 XmlTag = "UserID"\r
335 UserExtensions.UserID = XmlAttribute(XmlUserExtensions, XmlTag)\r
336 \r
337 XmlTag = "Identifier"\r
338 UserExtensions.Identifier = XmlAttribute(XmlUserExtensions, XmlTag)\r
339 \r
340 UserExtensions.Content = XmlElementData(XmlUserExtensions)\r
341 \r
342 return UserExtensions\r
343\r
344\r
345## Store content to a text file object.\r
346#\r
347# Write some text file content to a text file object. The contents may echo\r
348# in screen in a verbose way.\r
349#\r
350# @param TextFile The text file object.\r
351# @param Content The string object to be written to a text file.\r
352#\r
353def StoreTextFile(TextFile, Content):\r
354 EdkLogger.verbose(Content)\r
355 TextFile.write(Content)\r
356\r
357\r
358## Add item to a section.\r
359#\r
360# Add an Item with specific CPU architecture to section dictionary.\r
361# The possible duplication is ensured to be removed.\r
362#\r
363# @param Section Section dictionary indexed by CPU architecture.\r
4afd3d04 364# @param Arch CPU architecture: Ia32, X64, Ipf, ARM, AARCH64, Ebc or Common.\r
30fdf114
LG
365# @param Item The Item to be added to section dictionary.\r
366#\r
367def AddToSection(Section, Arch, Item):\r
368 SectionArch = Section.get(Arch, [])\r
369 if Item not in SectionArch:\r
370 SectionArch.append(Item)\r
371 Section[Arch] = SectionArch\r
372\r
373\r
374## Get section contents.\r
375#\r
376# Return the content of section named SectionName.\r
377# the contents is based on Methods and ObjectLists.\r
378#\r
379# @param SectionName The name of the section.\r
380# @param Method A function returning a string item of an object.\r
381# @param ObjectList The list of object.\r
382#\r
383# @retval Section The string content of a section.\r
384#\r
385def GetSection(SectionName, Method, ObjectList):\r
4afd3d04 386 SupportedArches = ["common", "Ia32", "X64", "Ipf", "Ebc", "ARM", "AARCH64"]\r
30fdf114
LG
387 SectionDict = {}\r
388 for Object in ObjectList:\r
389 Item = Method(Object)\r
390 if Item == "":\r
391 continue\r
392 Item = " %s" % Item\r
393 Arches = Object.SupArchList\r
394 if len(Arches) == 0:\r
395 AddToSection(SectionDict, "common", Item)\r
396 else:\r
397 for Arch in SupportedArches:\r
398 if Arch.upper() in Arches:\r
399 AddToSection(SectionDict, Arch, Item)\r
400\r
401 Section = ""\r
402 for Arch in SupportedArches:\r
403 SectionArch = "\n".join(SectionDict.get(Arch, []))\r
404 if SectionArch != "":\r
405 Section += "[%s.%s]\n%s\n" % (SectionName, Arch, SectionArch)\r
406 Section += "\n"\r
407 if Section != "":\r
408 Section += "\n"\r
409 return Section\r
410\r
411\r
412## Store file header to a text file.\r
413#\r
414# Write standard file header to a text file. The content includes copyright,\r
415# abstract, description and license extracted from CommonHeader class object.\r
416#\r
417# @param TextFile The text file object.\r
418# @param CommonHeader The source CommonHeader class object.\r
419#\r
420def StoreHeader(TextFile, CommonHeader):\r
421 CopyRight = CommonHeader.Copyright\r
422 Abstract = CommonHeader.Abstract\r
423 Description = CommonHeader.Description\r
424 License = CommonHeader.License\r
425\r
47fea6af 426 Header = "#/** @file\n#\n"\r
30fdf114
LG
427 Header += "# " + Abstract + "\n#\n"\r
428 Header += "# " + Description.strip().replace("\n", "\n# ") + "\n"\r
429 Header += "# " + CopyRight + "\n#\n"\r
430 Header += "# " + License.replace("\n", "\n# ").replace(" ", " ")\r
431 Header += "\n#\n#**/\n\n"\r
432\r
433 StoreTextFile(TextFile, Header)\r
434\r
435## Store file header to a text file.\r
436#\r
437# Write Defines section to a text file. DefinesTupleList determines the content.\r
438#\r
439# @param TextFile The text file object.\r
440# @param DefinesTupleList The list of (Tag, Value) to be added as one item.\r
441#\r
442def StoreDefinesSection(TextFile, DefinesTupleList):\r
443 Section = "[Defines]\n"\r
444 for DefineItem in DefinesTupleList:\r
445 Section += " %-30s = %s\n" % DefineItem\r
446\r
447 Section += "\n\n"\r
448 StoreTextFile(TextFile, Section)\r
449\r
450\r
451## Return one User Extension section.\r
452#\r
453# Read the input UserExtentsions class object and return one section.\r
454#\r
455# @param UserExtensions An input UserExtensions class object.\r
456#\r
457# @retval UserExtensionSection A section representing UserExtensions object.\r
458#\r
459def GetUserExtensions(UserExtensions):\r
460 UserId = UserExtensions.UserID\r
461 Identifier = UserExtensions.Identifier\r
462 Content = UserExtensions.Content\r
463\r
464 return "[UserExtensions.%s.%s]\n %s\n\n" % (UserId, Identifier, Content)\r
465\r
466## Regular expression to match an equation.\r
467mReEquation = re.compile(r"\s*(\S+)\s*=\s*(\S*)\s*")\r
468\r
469## Return a value tuple matching information in a text fle.\r
470#\r
471# Parse the text file and return a value tuple corresponding to an input tag\r
472# tuple. In case of any error, an tuple of empty strings is returned.\r
473#\r
474# @param FileName The file name of the text file.\r
475# @param TagTuple A tuple of tags as the key to the value.\r
476#\r
477# @param ValueTupe The returned tuple corresponding to the tag tuple.\r
478#\r
479def GetTextFileInfo(FileName, TagTuple):\r
480 ValueTuple = [""] * len(TagTuple)\r
481 try:\r
482 for Line in open(FileName):\r
483 Line = Line.split("#", 1)[0]\r
484 MatchEquation = mReEquation.match(Line)\r
485 if MatchEquation:\r
486 Tag = MatchEquation.group(1).upper()\r
487 Value = MatchEquation.group(2)\r
488 for Index in range(len(TagTuple)):\r
489 if TagTuple[Index] == Tag:\r
490 ValueTuple[Index] = Value\r
491 except:\r
492 EdkLogger.info("IO Error in reading file %s" % FileName)\r
493 \r
494 return ValueTuple\r
495\r
496\r
497## Return a value tuple matching information in an XML fle.\r
498#\r
499# Parse the XML file and return a value tuple corresponding to an input tag\r
500# tuple. In case of any error, an tuple of empty strings is returned.\r
501#\r
502# @param FileName The file name of the XML file.\r
503# @param TagTuple A tuple of tags as the key to the value.\r
504#\r
505# @param ValueTupe The returned tuple corresponding to the tag tuple.\r
506#\r
507def GetXmlFileInfo(FileName, TagTuple):\r
508 XmlDom = XmlParseFile(FileName)\r
509 return tuple([XmlElement(XmlDom, XmlTag) for XmlTag in TagTuple])\r
510\r
511\r
512## Parse migration command line options\r
513#\r
514# Use standard Python module optparse to parse command line option of this tool.\r
515#\r
516# @param Source The source file type.\r
517# @param Destinate The destinate file type.\r
518#\r
519# @retval Options A optparse object containing the parsed options.\r
520# @retval InputFile Path of an source file to be migrated.\r
521#\r
47fea6af 522def MigrationOptionParser(Source, Destinate, ToolName, VersionNumber=1.0):\r
30fdf114
LG
523 # use clearer usage to override default usage message\r
524 UsageString = "%s [-a] [-v|-q] [-o <output_file>] <input_file>" % ToolName\r
525 Version = "%s Version %.2f" % (ToolName, VersionNumber)\r
526 Copyright = "Copyright (c) 2007, Intel Corporation. All rights reserved."\r
527 \r
528 Parser = OptionParser(description=Copyright, version=Version, usage=UsageString)\r
529 Parser.add_option("-o", "--output", dest="OutputFile", help="The name of the %s file to be created." % Destinate)\r
530 Parser.add_option("-a", "--auto", dest="AutoWrite", action="store_true", default=False, help="Automatically create the %s file using the name of the %s file and replacing file extension" % (Source, Destinate))\r
531 Parser.add_option("-q", "--quiet", action="store_true", type=None, help="Disable all messages except FATAL ERRORS.")\r
532 Parser.add_option("-v", "--verbose", action="store_true", type=None, help="Turn on verbose output with informational messages printed.")\r
533\r
534 Options, Args = Parser.parse_args()\r
535\r
536 # Set logging level\r
537 if Options.verbose:\r
538 EdkLogger.setLevel(EdkLogger.VERBOSE)\r
539 elif Options.quiet:\r
540 EdkLogger.setLevel(EdkLogger.QUIET)\r
541 else:\r
542 EdkLogger.setLevel(EdkLogger.INFO)\r
543 \r
544 # error check\r
545 if len(Args) == 0:\r
546 raise MigrationError(PARAMETER_MISSING, name="Input file", usage=Parser.get_usage())\r
547 if len(Args) > 1:\r
548 raise MigrationError(PARAMETER_INVALID, name="Too many input files", usage=Parser.get_usage())\r
549\r
550 InputFile = Args[0]\r
551 if not os.path.exists(InputFile):\r
552 raise MigrationError(FILE_NOT_FOUND, name=InputFile)\r
553\r
554 if Options.OutputFile:\r
555 if Options.AutoWrite:\r
556 raise MigrationError(OPTION_CONFLICT, arg1="-o", arg2="-a", usage=Parser.get_usage())\r
557 else:\r
558 if Options.AutoWrite:\r
559 Options.OutputFile = os.path.splitext(InputFile)[0] + "." + Destinate.lower()\r
560 else:\r
561 raise MigrationError(OPTION_MISSING, name="-o", usage=Parser.get_usage())\r
562\r
563 return Options, InputFile\r
564\r
565# This acts like the main() function for the script, unless it is 'import'ed\r
566# into another script.\r
567if __name__ == '__main__':\r
568 pass\r