VirtualBox

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

Last change on this file since 102455 was 98103, checked in by vboxsync, 2 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.4 KB
Line 
1# -*- coding: utf-8 -*-
2# $Id: vboxcon.py 98103 2023-01-17 14:15:46Z vboxsync $
3
4"""
5VirtualBox Constants.
6
7See VBoxConstantWrappingHack for details.
8"""
9
10__copyright__ = \
11"""
12Copyright (C) 2010-2023 Oracle and/or its affiliates.
13
14This file is part of VirtualBox base platform packages, as
15available from https://www.virtualbox.org.
16
17This program is free software; you can redistribute it and/or
18modify it under the terms of the GNU General Public License
19as published by the Free Software Foundation, in version 3 of the
20License.
21
22This program is distributed in the hope that it will be useful, but
23WITHOUT ANY WARRANTY; without even the implied warranty of
24MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25General Public License for more details.
26
27You should have received a copy of the GNU General Public License
28along with this program; if not, see <https://www.gnu.org/licenses>.
29
30The contents of this file may alternatively be used under the terms
31of the Common Development and Distribution License Version 1.0
32(CDDL), a copy of it is provided in the "COPYING.CDDL" file included
33in the VirtualBox distribution, in which case the provisions of the
34CDDL are applicable instead of those of the GPL.
35
36You may elect to license modified versions of this file under the
37terms and conditions of either the GPL or the CDDL or both.
38
39SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
40"""
41__version__ = "$Revision: 98103 $"
42
43
44# Standard Python imports.
45import sys
46
47
48class VBoxConstantWrappingHack(object): # pylint: disable=too-few-public-methods
49 """
50 This is a hack to avoid the self.oVBoxMgr.constants.MachineState_Running
51 ugliness that forces one into the right margin... Anyone using this module
52 can get to the constants easily by:
53
54 from testdriver import vboxcon
55 if self.o.machine.state == vboxcon.MachineState_Running:
56 do stuff;
57
58 For our own convenience there's a vboxcon attribute set up in vbox.py,
59 class TestDriver which is the basis for the VirtualBox testcases. It takes
60 care of setting things up properly through the global variable
61 'goHackModuleClass' that refers to the instance of this class(if we didn't
62 we'd have to use testdriver.vboxcon.MachineState_Running).
63 """
64 def __init__(self, oWrapped):
65 self.oWrapped = oWrapped;
66 self.oVBoxMgr = None;
67 self.fpApiVer = 99.0;
68
69 def __getattr__(self, sName):
70 # Our self.
71 try:
72 return getattr(self.oWrapped, sName)
73 except AttributeError:
74 # The VBox constants.
75 if self.oVBoxMgr is None:
76 raise;
77 try:
78 return getattr(self.oVBoxMgr.constants, sName);
79 except AttributeError:
80 # Do some compatability mappings to keep it working with
81 # older versions.
82 if self.fpApiVer < 3.3:
83 if sName == 'SessionState_Locked':
84 return getattr(self.oVBoxMgr.constants, 'SessionState_Open');
85 if sName == 'SessionState_Unlocked':
86 return getattr(self.oVBoxMgr.constants, 'SessionState_Closed');
87 if sName == 'SessionState_Unlocking':
88 return getattr(self.oVBoxMgr.constants, 'SessionState_Closing');
89 raise;
90
91
92goHackModuleClass = VBoxConstantWrappingHack(sys.modules[__name__]); # pylint: disable=invalid-name
93sys.modules[__name__] = goHackModuleClass;
94
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