VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/testdriver/vboxcon.py@ 83432

Last change on this file since 83432 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1# -*- coding: utf-8 -*-
2# $Id: vboxcon.py 82968 2020-02-04 10:35:17Z vboxsync $
3
4"""
5VirtualBox Constants.
6
7See VBoxConstantWrappingHack for details.
8"""
9
10__copyright__ = \
11"""
12Copyright (C) 2010-2020 Oracle Corporation
13
14This file is part of VirtualBox Open Source Edition (OSE), as
15available from http://www.virtualbox.org. This file is free software;
16you can redistribute it and/or modify it under the terms of the GNU
17General Public License (GPL) as published by the Free Software
18Foundation, in version 2 as it comes in the "COPYING" file of the
19VirtualBox OSE distribution. VirtualBox OSE is distributed in the
20hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
21
22The contents of this file may alternatively be used under the terms
23of the Common Development and Distribution License Version 1.0
24(CDDL) only, as it comes in the "COPYING.CDDL" file of the
25VirtualBox OSE distribution, in which case the provisions of the
26CDDL are applicable instead of those of the GPL.
27
28You may elect to license modified versions of this file under the
29terms and conditions of either the GPL or the CDDL or both.
30"""
31__version__ = "$Revision: 82968 $"
32
33
34# Standard Python imports.
35import sys
36
37
38class VBoxConstantWrappingHack(object): # pylint: disable=too-few-public-methods
39 """
40 This is a hack to avoid the self.oVBoxMgr.constants.MachineState_Running
41 ugliness that forces one into the right margin... Anyone using this module
42 can get to the constants easily by:
43
44 from testdriver import vboxcon
45 if self.o.machine.state == vboxcon.MachineState_Running:
46 do stuff;
47
48 For our own convenience there's a vboxcon attribute set up in vbox.py,
49 class TestDriver which is the basis for the VirtualBox testcases. It takes
50 care of setting things up properly through the global variable
51 'goHackModuleClass' that refers to the instance of this class(if we didn't
52 we'd have to use testdriver.vboxcon.MachineState_Running).
53 """
54 def __init__(self, oWrapped):
55 self.oWrapped = oWrapped;
56 self.oVBoxMgr = None;
57 self.fpApiVer = 99.0;
58
59 def __getattr__(self, sName):
60 # Our self.
61 try:
62 return getattr(self.oWrapped, sName)
63 except AttributeError:
64 # The VBox constants.
65 if self.oVBoxMgr is None:
66 raise;
67 try:
68 return getattr(self.oVBoxMgr.constants, sName);
69 except AttributeError:
70 # Do some compatability mappings to keep it working with
71 # older versions.
72 if self.fpApiVer < 3.3:
73 if sName == 'SessionState_Locked':
74 return getattr(self.oVBoxMgr.constants, 'SessionState_Open');
75 if sName == 'SessionState_Unlocked':
76 return getattr(self.oVBoxMgr.constants, 'SessionState_Closed');
77 if sName == 'SessionState_Unlocking':
78 return getattr(self.oVBoxMgr.constants, 'SessionState_Closing');
79 raise;
80
81
82goHackModuleClass = VBoxConstantWrappingHack(sys.modules[__name__]); # pylint: disable=invalid-name
83sys.modules[__name__] = goHackModuleClass;
84
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette