## @file\r
# Install distribution package.\r
#\r
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
#\r
# This program and the accompanying materials are licensed and made available \r
# under the terms and conditions of the BSD License which accompanies this \r
from sys import platform\r
\r
from Core.DependencyRules import DependencyRules\r
-from Library.Misc import CheckEnvVariable\r
from Library import GlobalData\r
from Logger import StringTable as ST\r
import Logger.Log as Logger\r
Logger.Error("RmPkg", \r
OPTION_MISSING, \r
ExtraData=ST.ERR_SPECIFY_PACKAGE)\r
- CheckEnvVariable()\r
WorkspaceDir = GlobalData.gWORKSPACE\r
#\r
# Prepare check dependency\r
#\r
Dep = DependencyRules(DataBase)\r
\r
- if Options.DistributionFile:\r
- (Guid, Version, NewDpFileName) = \\r
- DataBase.GetDpByName(os.path.split(Options.DistributionFile)[1])\r
- if not Guid:\r
- Logger.Error("RmPkg", UNKNOWN_ERROR, ST.ERR_PACKAGE_NOT_INSTALLED % Options.DistributionFile)\r
- else:\r
- Guid = Options.PackageGuid\r
- Version = Options.PackageVersion\r
- #\r
- # Check Dp existing\r
- #\r
- if not Dep.CheckDpExists(Guid, Version):\r
- Logger.Error("RmPkg", UNKNOWN_ERROR, ST.ERR_DISTRIBUTION_NOT_INSTALLED)\r
#\r
- # Check for Distribution files existence in /conf/upt, if not exist, \r
- # Warn user and go on.\r
+ # Get the Dp information\r
#\r
- StoredDistFile = os.path.normpath(os.path.join(WorkspaceDir, GlobalData.gUPT_DIR, NewDpFileName))\r
- if not os.path.isfile(StoredDistFile):\r
- Logger.Warn("RmPkg", ST.WRN_DIST_NOT_FOUND%StoredDistFile)\r
- StoredDistFile = None\r
- \r
+ StoredDistFile, Guid, Version = GetInstalledDpInfo(Options.DistributionFile, Dep, DataBase, WorkspaceDir)\r
+\r
# \r
# Check Dp depex\r
#\r
CheckDpDepex(Dep, Guid, Version, WorkspaceDir)\r
\r
+ # \r
+ # remove distribution\r
#\r
- # Get Current File List\r
- #\r
- NewFileList = GetCurrentFileList(DataBase, Guid, Version, WorkspaceDir)\r
-\r
- #\r
- # Remove all files\r
- #\r
- MissingFileList = []\r
- for (Path, Md5Sum) in DataBase.GetDpFileList(Guid, Version):\r
- if os.path.isfile(Path):\r
- if Path in NewFileList:\r
- NewFileList.remove(Path)\r
- if not Options.Yes:\r
- #\r
- # check whether modified by users\r
- #\r
- Md5Sigature = md5.new(open(str(Path), 'rb').read())\r
- if Md5Sum != Md5Sigature.hexdigest():\r
- Logger.Info(ST.MSG_CONFIRM_REMOVE2 % Path)\r
- Input = stdin.readline()\r
- Input = Input.replace('\r', '').replace('\n', '')\r
- if Input.upper() != 'Y':\r
- continue\r
- RemovePath(Path)\r
- else:\r
- MissingFileList.append(Path)\r
- \r
- for Path in NewFileList:\r
- if os.path.isfile(Path):\r
- if (not Options.Yes) and (not os.path.split(Path)[1].startswith('.')):\r
- Logger.Info(ST.MSG_CONFIRM_REMOVE3 % Path)\r
- Input = stdin.readline()\r
- Input = Input.replace('\r', '').replace('\n', '')\r
- if Input.upper() != 'Y':\r
- continue\r
- RemovePath(Path)\r
-\r
- #\r
- # Remove distribution files in /Conf/.upt\r
- #\r
- if StoredDistFile is not None:\r
- os.remove(StoredDistFile)\r
+ RemoveDist(Guid, Version, StoredDistFile, DataBase, WorkspaceDir, Options.Yes)\r
\r
- #\r
- # update database\r
- #\r
- Logger.Quiet(ST.MSG_UPDATE_PACKAGE_DATABASE)\r
- DataBase.RemoveDpObj(Guid, Version)\r
Logger.Quiet(ST.MSG_FINISH)\r
\r
ReturnCode = 0\r
format_exc())\r
ReturnCode = CODE_ERROR\r
return ReturnCode\r
- \r
\r
+## GetInstalledDpInfo method\r
+#\r
+# Get the installed distribution information\r
+#\r
+# @param DistributionFile: the name of the distribution\r
+# @param Dep: the instance of DependencyRules\r
+# @param DataBase: the internal database\r
+# @param WorkspaceDir: work space directory\r
+# @retval StoredDistFile: the distribution file that backed up\r
+# @retval Guid: the Guid of the distribution\r
+# @retval Version: the Version of distribution\r
+#\r
+def GetInstalledDpInfo(DistributionFile, Dep, DataBase, WorkspaceDir):\r
+ (Guid, Version, NewDpFileName) = DataBase.GetDpByName(os.path.split(DistributionFile)[1])\r
+ if not Guid:\r
+ Logger.Error("RmPkg", UNKNOWN_ERROR, ST.ERR_PACKAGE_NOT_INSTALLED % DistributionFile)\r
+\r
+ #\r
+ # Check Dp existing\r
+ #\r
+ if not Dep.CheckDpExists(Guid, Version):\r
+ Logger.Error("RmPkg", UNKNOWN_ERROR, ST.ERR_DISTRIBUTION_NOT_INSTALLED)\r
+ #\r
+ # Check for Distribution files existence in /conf/upt, if not exist, \r
+ # Warn user and go on.\r
+ #\r
+ StoredDistFile = os.path.normpath(os.path.join(WorkspaceDir, GlobalData.gUPT_DIR, NewDpFileName))\r
+ if not os.path.isfile(StoredDistFile):\r
+ Logger.Warn("RmPkg", ST.WRN_DIST_NOT_FOUND%StoredDistFile)\r
+ StoredDistFile = None\r
+\r
+ return StoredDistFile, Guid, Version\r
+\r
+## RemoveDist method\r
+#\r
+# remove a distribution\r
+#\r
+# @param Guid: the Guid of the distribution\r
+# @param Version: the Version of distribution\r
+# @param StoredDistFile: the distribution file that backed up\r
+# @param DataBase: the internal database\r
+# @param WorkspaceDir: work space directory\r
+# @param ForceRemove: whether user want to remove file even it is modified\r
+#\r
+def RemoveDist(Guid, Version, StoredDistFile, DataBase, WorkspaceDir, ForceRemove):\r
+ #\r
+ # Get Current File List\r
+ #\r
+ NewFileList = GetCurrentFileList(DataBase, Guid, Version, WorkspaceDir)\r
+\r
+ #\r
+ # Remove all files\r
+ #\r
+ MissingFileList = []\r
+ for (Path, Md5Sum) in DataBase.GetDpFileList(Guid, Version):\r
+ if os.path.isfile(Path):\r
+ if Path in NewFileList:\r
+ NewFileList.remove(Path)\r
+ if not ForceRemove:\r
+ #\r
+ # check whether modified by users\r
+ #\r
+ Md5Sigature = md5.new(open(str(Path), 'rb').read())\r
+ if Md5Sum != Md5Sigature.hexdigest():\r
+ Logger.Info(ST.MSG_CONFIRM_REMOVE2 % Path)\r
+ Input = stdin.readline()\r
+ Input = Input.replace('\r', '').replace('\n', '')\r
+ if Input.upper() != 'Y':\r
+ continue\r
+ RemovePath(Path)\r
+ else:\r
+ MissingFileList.append(Path)\r
+ \r
+ for Path in NewFileList:\r
+ if os.path.isfile(Path):\r
+ if (not ForceRemove) and (not os.path.split(Path)[1].startswith('.')):\r
+ Logger.Info(ST.MSG_CONFIRM_REMOVE3 % Path)\r
+ Input = stdin.readline()\r
+ Input = Input.replace('\r', '').replace('\n', '')\r
+ if Input.upper() != 'Y':\r
+ continue\r
+ RemovePath(Path)\r
+\r
+ #\r
+ # Remove distribution files in /Conf/.upt\r
+ #\r
+ if StoredDistFile is not None:\r
+ os.remove(StoredDistFile)\r
+\r
+ #\r
+ # update database\r
+ #\r
+ Logger.Quiet(ST.MSG_UPDATE_PACKAGE_DATABASE)\r
+ DataBase.RemoveDpObj(Guid, Version)\r