1 | # -*- coding: utf-8 -*-
|
---|
2 | # $Id: vboxcon.py 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
3 |
|
---|
4 | """
|
---|
5 | VirtualBox Constants.
|
---|
6 |
|
---|
7 | See VBoxConstantWrappingHack for details.
|
---|
8 | """
|
---|
9 |
|
---|
10 | __copyright__ = \
|
---|
11 | """
|
---|
12 | Copyright (C) 2010-2023 Oracle and/or its affiliates.
|
---|
13 |
|
---|
14 | This file is part of VirtualBox base platform packages, as
|
---|
15 | available from https://www.virtualbox.org.
|
---|
16 |
|
---|
17 | This program is free software; you can redistribute it and/or
|
---|
18 | modify it under the terms of the GNU General Public License
|
---|
19 | as published by the Free Software Foundation, in version 3 of the
|
---|
20 | License.
|
---|
21 |
|
---|
22 | This program is distributed in the hope that it will be useful, but
|
---|
23 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
25 | General Public License for more details.
|
---|
26 |
|
---|
27 | You should have received a copy of the GNU General Public License
|
---|
28 | along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
29 |
|
---|
30 | The contents of this file may alternatively be used under the terms
|
---|
31 | of the Common Development and Distribution License Version 1.0
|
---|
32 | (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
33 | in the VirtualBox distribution, in which case the provisions of the
|
---|
34 | CDDL are applicable instead of those of the GPL.
|
---|
35 |
|
---|
36 | You may elect to license modified versions of this file under the
|
---|
37 | terms and conditions of either the GPL or the CDDL or both.
|
---|
38 |
|
---|
39 | SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
40 | """
|
---|
41 | __version__ = "$Revision: 98103 $"
|
---|
42 |
|
---|
43 |
|
---|
44 | # Standard Python imports.
|
---|
45 | import sys
|
---|
46 |
|
---|
47 |
|
---|
48 | class 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 |
|
---|
92 | goHackModuleClass = VBoxConstantWrappingHack(sys.modules[__name__]); # pylint: disable=invalid-name
|
---|
93 | sys.modules[__name__] = goHackModuleClass;
|
---|
94 |
|
---|