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