1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 | # $Id: close_orphaned_testsets.py 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
4 | # pylint: disable=line-too-long
|
---|
5 |
|
---|
6 | """
|
---|
7 | Maintenance tool for closing orphaned testsets.
|
---|
8 | """
|
---|
9 |
|
---|
10 | from __future__ import print_function;
|
---|
11 |
|
---|
12 | __copyright__ = \
|
---|
13 | """
|
---|
14 | Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
15 |
|
---|
16 | This file is part of VirtualBox base platform packages, as
|
---|
17 | available from https://www.virtualbox.org.
|
---|
18 |
|
---|
19 | This program is free software; you can redistribute it and/or
|
---|
20 | modify it under the terms of the GNU General Public License
|
---|
21 | as published by the Free Software Foundation, in version 3 of the
|
---|
22 | License.
|
---|
23 |
|
---|
24 | This program is distributed in the hope that it will be useful, but
|
---|
25 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
27 | General Public License for more details.
|
---|
28 |
|
---|
29 | You should have received a copy of the GNU General Public License
|
---|
30 | along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
31 |
|
---|
32 | The contents of this file may alternatively be used under the terms
|
---|
33 | of the Common Development and Distribution License Version 1.0
|
---|
34 | (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
35 | in the VirtualBox distribution, in which case the provisions of the
|
---|
36 | CDDL are applicable instead of those of the GPL.
|
---|
37 |
|
---|
38 | You may elect to license modified versions of this file under the
|
---|
39 | terms and conditions of either the GPL or the CDDL or both.
|
---|
40 |
|
---|
41 | SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
42 | """
|
---|
43 | __version__ = "$Revision: 98103 $"
|
---|
44 |
|
---|
45 | # Standard python imports
|
---|
46 | import sys
|
---|
47 | import os
|
---|
48 | from optparse import OptionParser; # pylint: disable=deprecated-module
|
---|
49 |
|
---|
50 | # Add Test Manager's modules path
|
---|
51 | g_ksTestManagerDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
---|
52 | sys.path.append(g_ksTestManagerDir)
|
---|
53 |
|
---|
54 | # Test Manager imports
|
---|
55 | from testmanager.core.db import TMDatabaseConnection
|
---|
56 | from testmanager.core.testset import TestSetLogic;
|
---|
57 |
|
---|
58 |
|
---|
59 | class CloseOrphanedTestSets(object):
|
---|
60 | """
|
---|
61 | Finds and closes orphaned testsets.
|
---|
62 | """
|
---|
63 |
|
---|
64 | def __init__(self):
|
---|
65 | """
|
---|
66 | Parse command line
|
---|
67 | """
|
---|
68 | oParser = OptionParser();
|
---|
69 | oParser.add_option('-d', '--just-do-it', dest='fJustDoIt', action='store_true',
|
---|
70 | help='Do the database changes.');
|
---|
71 |
|
---|
72 |
|
---|
73 | (self.oConfig, _) = oParser.parse_args();
|
---|
74 |
|
---|
75 |
|
---|
76 | def main(self):
|
---|
77 | """ Main method. """
|
---|
78 | oDb = TMDatabaseConnection();
|
---|
79 |
|
---|
80 | # Get a list of orphans.
|
---|
81 | oLogic = TestSetLogic(oDb);
|
---|
82 | aoOrphans = oLogic.fetchOrphaned();
|
---|
83 | if aoOrphans:
|
---|
84 | # Complete them.
|
---|
85 | if self.oConfig.fJustDoIt:
|
---|
86 | print('Completing %u test sets as abandoned:' % (len(aoOrphans),));
|
---|
87 | for oTestSet in aoOrphans:
|
---|
88 | print('#%-7u: idTestBox=%-3u tsCreated=%s tsDone=%s'
|
---|
89 | % (oTestSet.idTestSet, oTestSet.idTestBox, oTestSet.tsCreated, oTestSet.tsDone));
|
---|
90 | oLogic.completeAsAbandoned(oTestSet.idTestSet);
|
---|
91 | print('Committing...');
|
---|
92 | oDb.commit();
|
---|
93 | else:
|
---|
94 | for oTestSet in aoOrphans:
|
---|
95 | print('#%-7u: idTestBox=%-3u tsCreated=%s tsDone=%s'
|
---|
96 | % (oTestSet.idTestSet, oTestSet.idTestBox, oTestSet.tsCreated, oTestSet.tsDone));
|
---|
97 | print('Not completing any testsets without seeing the --just-do-it option.');
|
---|
98 | else:
|
---|
99 | print('No orphaned test sets.\n');
|
---|
100 | return 0;
|
---|
101 |
|
---|
102 |
|
---|
103 | if __name__ == '__main__':
|
---|
104 | sys.exit(CloseOrphanedTestSets().main())
|
---|
105 |
|
---|