testboxupgrade.py revision cf22150eaeeb72431bf1cf65c309a431454fb22b
# -*- coding: utf-8 -*-
# $Id$
"""
TestBox Script - Upgrade from local file ZIP.
"""
__copyright__ = \
"""
Copyright (C) 2012-2014 Oracle Corporation
This file is part of VirtualBox Open Source Edition (OSE), as
available from http://www.virtualbox.org. This file is free software;
General Public License (GPL) as published by the Free Software
Foundation, in version 2 as it comes in the "COPYING" file of the
VirtualBox OSE distribution. VirtualBox OSE is distributed in the
hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
The contents of this file may alternatively be used under the terms
of the Common Development and Distribution License Version 1.0
(CDDL) only, as it comes in the "COPYING.CDDL" file of the
VirtualBox OSE distribution, in which case the provisions of the
CDDL are applicable instead of those of the GPL.
You may elect to license modified versions of this file under the
terms and conditions of either the GPL or the CDDL or both.
"""
__version__ = "$Revision$"
# Standard python imports.
import os
import shutil
import sys
import subprocess
import threading
import uuid;
import zipfile
# Validation Kit imports.
import testboxcommons
from testboxscript import TBS_EXITCODE_SYNTAX;
# Figure where we are.
try: __file__
"""Thread procedure for the upgrade test drive."""
return True;
def _doUpgradeCheckZip(oZip):
"""
Check that the essential files are there.
Returns list of members on success, None on failure.
"""
if ('testboxscript/testboxscript/testboxscript.py' not in asMembers) \
or ('testboxscript/testboxscript/testboxscript_real.py' not in asMembers):
return None;
return None;
return None;
return asMembers;
"""
Unzips the files into sUpdateDir, does chmod(755) on all files and
checks that there are no symlinks or special files.
"""
#
# Extract the files.
#
else:
#
# Make all files executable and make sure only owner can write to them.
# While at it, also check that there are only files and directory, no
# symbolic links or special stuff.
#
return False;
else:
return False;
try:
return True;
def _doUpgradeTestRun(sUpgradeDir):
"""
Do a testrun of the new script, to make sure it doesn't fail with
to run in any way because of old python, missing import or generally
busted upgrade.
"""
asArgs = [os.path.join(sUpgradeDir, 'testboxscript', 'testboxscript', 'testboxscript.py'), '--version' ];
asBuf = []
if iStatus is None:
return False;
if iStatus is not TBS_EXITCODE_SYNTAX:
% (iStatus, TBS_EXITCODE_SYNTAX));
return False;
try:
except:
testboxcommons.log('The new testboxscript returned an unparseable version string: "%s"!' % (sOutput,));
return False;
return True;
"""
# Apply the directories and files from the upgrade.
"""
#
# Create directories first since that's least intrusive.
#
if sMember != '':
#
# Move the files into place.
#
asOldFiles = [];
# Move the old file out of the way first.
sDstRm = None;
try:
try:
break;
try:
break;
try:
try:
except:
break;
#
# Roll back on failure.
#
for sDstRm in asOldFiles:
try:
except:
return False;
return True;
"""
Clean up all obsolete files and directories.
Returns True (shouldn't fail or raise any exceptions).
"""
try:
except:
pass;
asKnownFiles = [];
asKnownDirs = [];
if sMember == '':
continue;
else:
if sFull not in asKnownDirs:
try:
if sFull not in asKnownFiles:
try:
return True;
def upgradeFromZip(sZipFile):
"""
Upgrade the testboxscript install using the specified zip file.
"""
# A little precaution.
if utils.isRunningFromCheckout():
return False;
#
# Prepare.
#
# Note! Don't bother cleaning up files and dirs in the error paths,
# they'll be restricted to the one zip and the one upgrade dir.
# We'll remove them next time we upgrade.
#
if asMembers is None:
return False;
return False;
return False;
#
# Execute.
#
return False;
return True;
# For testing purposes.
if __name__ == '__main__':