cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# -*- coding: utf-8 -*-
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# $Id$
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox Constants.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncSee VBoxConstantWrappingHack for details.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__copyright__ = \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCopyright (C) 2010-2014 Oracle Corporation
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThis file is part of VirtualBox Open Source Edition (OSE), as
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncavailable from http://www.virtualbox.org. This file is free software;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncyou can redistribute it and/or modify it under the terms of the GNU
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncGeneral Public License (GPL) as published by the Free Software
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncFoundation, in version 2 as it comes in the "COPYING" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution. VirtualBox OSE is distributed in the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsynchope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThe contents of this file may alternatively be used under the terms
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncof the Common Development and Distribution License Version 1.0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync(CDDL) only, as it comes in the "COPYING.CDDL" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution, in which case the provisions of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCDDL are applicable instead of those of the GPL.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncYou may elect to license modified versions of this file under the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncterms and conditions of either the GPL or the CDDL or both.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__version__ = "$Revision$"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Standard Python imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncimport sys
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass VBoxConstantWrappingHack(object): # pylint: disable=R0903
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync This is a hack to avoid the self.oVBoxMgr.constants.MachineState_Running
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync uglyness that forces one into the rigth margin... Anyone using this module
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync can get to the constants easily by:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync import testdriver.vbox as vbox
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.o.machine.state == vbox.MachineState_Running:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync do stuff;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync For our own convenience we have a global variable 'vbox' that refers to the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync instance of this class so we can do the same thing from within the module
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync as well (if we didn't we'd have to do testdriver.vbox.MachineState_Running).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self, oWrapped):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oWrapped = oWrapped;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oVBoxMgr = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.fpApiVer = 99.0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __getattr__(self, sName):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Our self.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return getattr(self.oWrapped, sName)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except AttributeError:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # The VBox constants.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.oVBoxMgr is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return getattr(self.oVBoxMgr.constants, sName);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except AttributeError:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Do some compatability mappings to keep it working with
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # older versions.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fpApiVer < 3.3:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sName == 'SessionState_Locked':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return getattr(self.oVBoxMgr.constants, 'SessionState_Open');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sName == 'SessionState_Unlocked':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return getattr(self.oVBoxMgr.constants, 'SessionState_Closed');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sName == 'SessionState_Unlocking':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return getattr(self.oVBoxMgr.constants, 'SessionState_Closing');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncgoHackModuleClass = VBoxConstantWrappingHack(sys.modules[__name__]); # pylint: disable=C0103
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncsys.modules[__name__] = goHackModuleClass;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync