]>
Commit | Line | Data |
---|---|---|
4234283c LG |
1 | ## @file\r |
2 | #\r | |
3 | # This file is the main entry for UPT \r | |
4 | #\r | |
5 | # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r | |
6 | #\r | |
7 | # This program and the accompanying materials are licensed and made available \r | |
8 | # under the terms and conditions of the BSD License which accompanies this \r | |
9 | # distribution. The full text of the license may be found at \r | |
10 | # http://opensource.org/licenses/bsd-license.php\r | |
11 | #\r | |
12 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | #\r | |
15 | \r | |
16 | '''\r | |
17 | UPT\r | |
18 | '''\r | |
19 | \r | |
20 | ## import modules\r | |
21 | #\r | |
22 | import sys\r | |
23 | import os.path\r | |
24 | from os import environ\r | |
25 | from sys import platform\r | |
26 | from optparse import OptionParser\r | |
27 | from traceback import format_exc\r | |
28 | from platform import python_version\r | |
29 | \r | |
30 | from Logger import StringTable as ST\r | |
31 | import Logger.Log as Logger\r | |
32 | from Logger.StringTable import MSG_VERSION\r | |
33 | from Logger.StringTable import MSG_DESCRIPTION\r | |
34 | from Logger.StringTable import MSG_USAGE\r | |
35 | from Logger.ToolError import FILE_NOT_FOUND\r | |
36 | from Logger.ToolError import OPTION_MISSING\r | |
37 | from Logger.ToolError import FILE_TYPE_MISMATCH\r | |
38 | from Logger.ToolError import OPTION_CONFLICT\r | |
39 | from Logger.ToolError import FatalError\r | |
40 | import MkPkg\r | |
41 | import InstallPkg\r | |
42 | import RmPkg\r | |
43 | from Library.Misc import CheckEnvVariable\r | |
44 | from Library import GlobalData\r | |
45 | from Core.IpiDb import IpiDatabase\r | |
b36d134f | 46 | from Common.BuildVersion import gBUILD_VERSION\r |
4234283c LG |
47 | \r |
48 | ##\r | |
49 | # Version and Copyright\r | |
50 | #\r | |
51 | #VersionNumber = "1.0"\r | |
52 | #__version__ = "Revision " + VersionNumber\r | |
53 | #__copyright__ = "Copyright (c) 2011 Intel Corporation All Rights Reserved."\r | |
54 | \r | |
55 | ## CheckConflictOption\r | |
56 | #\r | |
57 | # CheckConflictOption\r | |
58 | #\r | |
59 | def CheckConflictOption(Opt):\r | |
60 | if (Opt.PackFileToCreate and Opt.PackFileToInstall and Opt.PackFileToRemove):\r | |
61 | Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_REQUIRE_I_C_R_OPTION)\r | |
62 | elif Opt.PackFileToCreate and Opt.PackFileToInstall:\r | |
63 | Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_I_C_EXCLUSIVE)\r | |
64 | elif Opt.PackFileToInstall and Opt.PackFileToRemove:\r | |
65 | Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_I_R_EXCLUSIVE)\r | |
66 | elif Opt.PackFileToCreate and Opt.PackFileToRemove:\r | |
67 | Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_C_R_EXCLUSIVE)\r | |
68 | \r | |
69 | ## SetLogLevel\r | |
70 | #\r | |
71 | def SetLogLevel(Opt):\r | |
72 | if Opt.opt_verbose:\r | |
73 | Logger.SetLevel(Logger.VERBOSE)\r | |
74 | elif Opt.opt_quiet:\r | |
75 | Logger.SetLevel(Logger.QUIET + 1)\r | |
76 | elif Opt.debug_level != None:\r | |
77 | if Opt.debug_level < 0 or Opt.debug_level > 9:\r | |
78 | Logger.Warn("UPT", ST.ERR_DEBUG_LEVEL)\r | |
79 | Logger.SetLevel(Logger.INFO)\r | |
80 | else:\r | |
81 | Logger.SetLevel(Opt.debug_level + 1)\r | |
82 | elif Opt.opt_slient:\r | |
83 | Logger.SetLevel(Logger.SILENT)\r | |
84 | else:\r | |
85 | Logger.SetLevel(Logger.INFO)\r | |
86 | \r | |
87 | ## Main\r | |
88 | #\r | |
89 | # Main\r | |
90 | #\r | |
91 | def Main():\r | |
92 | Logger.Initialize()\r | |
93 | \r | |
b36d134f | 94 | Parser = OptionParser(version=(MSG_VERSION + ' ' + gBUILD_VERSION), description=MSG_DESCRIPTION,\r |
4234283c LG |
95 | prog="UPT.exe", usage=MSG_USAGE)\r |
96 | \r | |
97 | Parser.add_option("-d", "--debug", action="store", type="int", dest="debug_level", help=ST.HLP_PRINT_DEBUG_INFO)\r | |
98 | \r | |
99 | Parser.add_option("-v", "--verbose", action="store_true", dest="opt_verbose",\r | |
100 | help=ST.HLP_PRINT_INFORMATIONAL_STATEMENT)\r | |
101 | \r | |
102 | Parser.add_option("-s", "--silent", action="store_true", dest="opt_slient", help=ST.HLP_RETURN_NO_DISPLAY)\r | |
103 | \r | |
104 | Parser.add_option("-q", "--quiet", action="store_true", dest="opt_quiet", help=ST.HLP_RETURN_AND_DISPLAY)\r | |
105 | \r | |
106 | Parser.add_option("-i", "--install", action="store", type="string", dest="Install_Distribution_Package_File",\r | |
107 | help=ST.HLP_SPECIFY_PACKAGE_NAME_INSTALL)\r | |
108 | \r | |
109 | Parser.add_option("-c", "--create", action="store", type="string", dest="Create_Distribution_Package_File",\r | |
110 | help=ST.HLP_SPECIFY_PACKAGE_NAME_CREATE)\r | |
111 | \r | |
112 | Parser.add_option("-r", "--remove", action="store", type="string", dest="Remove_Distribution_Package_File",\r | |
113 | help=ST.HLP_SPECIFY_PACKAGE_NAME_REMOVE)\r | |
114 | \r | |
115 | Parser.add_option("-t", "--template", action="store", type="string", dest="Package_Information_Data_File",\r | |
116 | help=ST.HLP_SPECIFY_TEMPLATE_NAME_CREATE)\r | |
117 | \r | |
118 | Parser.add_option("-p", "--dec-filename", action="append", type="string", dest="EDK2_DEC_Filename",\r | |
119 | help=ST.HLP_SPECIFY_DEC_NAME_CREATE)\r | |
120 | \r | |
121 | Parser.add_option("-m", "--inf-filename", action="append", type="string", dest="EDK2_INF_Filename",\r | |
122 | help=ST.HLP_SPECIFY_INF_NAME_CREATE)\r | |
123 | \r | |
124 | Parser.add_option("-f", "--force", action="store_true", dest="Yes", help=ST.HLP_DISABLE_PROMPT)\r | |
125 | \r | |
126 | Parser.add_option("-n", "--custom-path", action="store_true", dest="CustomPath", help=ST.HLP_CUSTOM_PATH_PROMPT)\r | |
127 | \r | |
128 | Parser.add_option("-x", "--free-lock", action="store_true", dest="SkipLock", help=ST.HLP_SKIP_LOCK_CHECK)\r | |
129 | \r | |
130 | Opt = Parser.parse_args()[0]\r | |
131 | \r | |
132 | Var2Var = [\r | |
133 | ("PackageInformationDataFile", Opt.Package_Information_Data_File),\r | |
134 | ("PackFileToInstall", Opt.Install_Distribution_Package_File),\r | |
135 | ("PackFileToCreate", Opt.Create_Distribution_Package_File),\r | |
136 | ("PackFileToRemove", Opt.Remove_Distribution_Package_File),\r | |
137 | ("PackageFileList", Opt.EDK2_DEC_Filename),\r | |
138 | ("ModuleFileList", Opt.EDK2_INF_Filename)\r | |
139 | ]\r | |
140 | for Var in Var2Var:\r | |
141 | setattr(Opt, Var[0], Var[1])\r | |
142 | \r | |
143 | try:\r | |
144 | CheckEnvVariable()\r | |
145 | except FatalError, XExcept:\r | |
146 | if Logger.GetLevel() <= Logger.DEBUG_9:\r | |
147 | Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())\r | |
148 | return XExcept.args[0]\r | |
149 | \r | |
150 | GlobalData.gWORKSPACE = os.path.normpath(environ["WORKSPACE"])\r | |
151 | WorkspaceDir = GlobalData.gWORKSPACE\r | |
152 | \r | |
153 | SetLogLevel(Opt)\r | |
154 | \r | |
155 | GlobalData.gDB = IpiDatabase(os.path.normpath(os.path.join(WorkspaceDir, "Conf/DistributionPackageDatabase.db")))\r | |
156 | GlobalData.gDB.InitDatabase(Opt.SkipLock)\r | |
157 | \r | |
158 | #\r | |
159 | # Make sure the Db will get closed correctly\r | |
160 | #\r | |
161 | try:\r | |
162 | ReturnCode = 0\r | |
163 | CheckConflictOption(Opt)\r | |
164 | \r | |
165 | RunModule = None\r | |
166 | if Opt.PackFileToCreate:\r | |
167 | if Opt.PackageInformationDataFile:\r | |
168 | if not os.path.exists(Opt.PackageInformationDataFile):\r | |
169 | if not os.path.exists(os.path.join(WorkspaceDir, Opt.PackageInformationDataFile)):\r | |
170 | Logger.Error("\nUPT", FILE_NOT_FOUND, ST.ERR_NO_TEMPLATE_FILE % Opt.PackageInformationDataFile)\r | |
171 | else:\r | |
172 | Opt.PackageInformationDataFile = os.path.join(WorkspaceDir, Opt.PackageInformationDataFile)\r | |
173 | else:\r | |
174 | Logger.Error("UPT", OPTION_MISSING, ExtraData=ST.ERR_REQUIRE_T_OPTION)\r | |
175 | if not Opt.PackFileToCreate.endswith('.dist'):\r | |
176 | Logger.Error("CreatePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Opt.PackFileToCreate)\r | |
177 | RunModule = MkPkg.Main\r | |
178 | \r | |
179 | elif Opt.PackFileToInstall:\r | |
180 | if not Opt.PackFileToInstall.endswith('.dist'):\r | |
181 | Logger.Error("InstallPkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Opt.PackFileToInstall)\r | |
182 | \r | |
183 | #\r | |
184 | # check file existence, if not absolute path, then try current working directory, then $(WORKSPACE) \r | |
185 | #\r | |
186 | Existed = True\r | |
187 | if os.path.isabs(Opt.PackFileToInstall):\r | |
188 | if not (os.path.exists(Opt.PackFileToInstall) and os.path.isfile(Opt.PackFileToInstall)):\r | |
189 | Existed = False\r | |
190 | else:\r | |
191 | AbsPath = os.path.normpath(os.path.join(os.getcwd(), Opt.PackFileToInstall))\r | |
192 | if not (os.path.exists(AbsPath) and os.path.isfile(AbsPath)):\r | |
193 | AbsPath = os.path.normpath(os.path.join(WorkspaceDir, Opt.PackFileToInstall))\r | |
194 | if not (os.path.exists(AbsPath) and os.path.isfile(AbsPath)):\r | |
195 | Existed = False\r | |
196 | \r | |
197 | if Existed:\r | |
198 | Opt.PackFileToInstall = AbsPath\r | |
199 | \r | |
200 | if not Existed:\r | |
201 | Logger.Error("InstallPkg", FILE_NOT_FOUND, ST.ERR_INSTALL_DIST_NOT_FOUND % Opt.PackFileToInstall)\r | |
202 | \r | |
203 | setattr(Opt, 'PackageFile', Opt.PackFileToInstall)\r | |
204 | RunModule = InstallPkg.Main\r | |
205 | \r | |
206 | elif Opt.PackFileToRemove:\r | |
207 | if not Opt.PackFileToRemove.endswith('.dist'):\r | |
208 | Logger.Error("RemovePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Opt.PackFileToRemove)\r | |
209 | head, tail = os.path.split(Opt.PackFileToRemove)\r | |
210 | if head or not tail:\r | |
211 | Logger.Error("RemovePkg",\r | |
212 | FILE_TYPE_MISMATCH,\r | |
213 | ExtraData=ST.ERR_DIST_FILENAME_ONLY_FOR_REMOVE % Opt.PackFileToRemove)\r | |
214 | \r | |
215 | setattr(Opt, 'DistributionFile', Opt.PackFileToRemove)\r | |
216 | RunModule = RmPkg.Main\r | |
217 | else:\r | |
218 | Parser.print_usage()\r | |
219 | return OPTION_MISSING\r | |
220 | \r | |
221 | ReturnCode = RunModule(Opt)\r | |
222 | except FatalError, XExcept:\r | |
223 | ReturnCode = XExcept.args[0]\r | |
224 | if Logger.GetLevel() <= Logger.DEBUG_9:\r | |
225 | Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + \\r | |
226 | format_exc())\r | |
227 | finally:\r | |
228 | GlobalData.gDB.CloseDb()\r | |
229 | \r | |
230 | return ReturnCode\r | |
231 | \r | |
232 | if __name__ == '__main__':\r | |
233 | RETVAL = Main()\r | |
234 | #\r | |
235 | # 0-127 is a safe return range, and 1 is a standard default error\r | |
236 | #\r | |
237 | if RETVAL < 0 or RETVAL > 127:\r | |
238 | RETVAL = 1\r | |
239 | sys.exit(RETVAL)\r |