1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 | # $Id: close_orphaned_testsets.py 82968 2020-02-04 10:35:17Z 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-2020 Oracle Corporation
|
---|
15 |
|
---|
16 | This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
17 | available from http://www.virtualbox.org. This file is free software;
|
---|
18 | you can redistribute it and/or modify it under the terms of the GNU
|
---|
19 | General Public License (GPL) as published by the Free Software
|
---|
20 | Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
21 | VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
22 | hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
23 |
|
---|
24 | The contents of this file may alternatively be used under the terms
|
---|
25 | of the Common Development and Distribution License Version 1.0
|
---|
26 | (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
27 | VirtualBox OSE distribution, in which case the provisions of the
|
---|
28 | CDDL are applicable instead of those of the GPL.
|
---|
29 |
|
---|
30 | You may elect to license modified versions of this file under the
|
---|
31 | terms and conditions of either the GPL or the CDDL or both.
|
---|
32 | """
|
---|
33 | __version__ = "$Revision: 82968 $"
|
---|
34 |
|
---|
35 | # Standard python imports
|
---|
36 | import sys
|
---|
37 | import os
|
---|
38 | from optparse import OptionParser; # pylint: disable=deprecated-module
|
---|
39 |
|
---|
40 | # Add Test Manager's modules path
|
---|
41 | g_ksTestManagerDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
---|
42 | sys.path.append(g_ksTestManagerDir)
|
---|
43 |
|
---|
44 | # Test Manager imports
|
---|
45 | from testmanager.core.db import TMDatabaseConnection
|
---|
46 | from testmanager.core.testset import TestSetLogic;
|
---|
47 |
|
---|
48 |
|
---|
49 | class CloseOrphanedTestSets(object):
|
---|
50 | """
|
---|
51 | Finds and closes orphaned testsets.
|
---|
52 | """
|
---|
53 |
|
---|
54 | def __init__(self):
|
---|
55 | """
|
---|
56 | Parse command line
|
---|
57 | """
|
---|
58 | oParser = OptionParser();
|
---|
59 | oParser.add_option('-d', '--just-do-it', dest='fJustDoIt', action='store_true',
|
---|
60 | help='Do the database changes.');
|
---|
61 |
|
---|
62 |
|
---|
63 | (self.oConfig, _) = oParser.parse_args();
|
---|
64 |
|
---|
65 |
|
---|
66 | def main(self):
|
---|
67 | """ Main method. """
|
---|
68 | oDb = TMDatabaseConnection();
|
---|
69 |
|
---|
70 | # Get a list of orphans.
|
---|
71 | oLogic = TestSetLogic(oDb);
|
---|
72 | aoOrphans = oLogic.fetchOrphaned();
|
---|
73 | if aoOrphans:
|
---|
74 | # Complete them.
|
---|
75 | if self.oConfig.fJustDoIt:
|
---|
76 | print('Completing %u test sets as abandoned:' % (len(aoOrphans),));
|
---|
77 | for oTestSet in aoOrphans:
|
---|
78 | print('#%-7u: idTestBox=%-3u tsCreated=%s tsDone=%s'
|
---|
79 | % (oTestSet.idTestSet, oTestSet.idTestBox, oTestSet.tsCreated, oTestSet.tsDone));
|
---|
80 | oLogic.completeAsAbandoned(oTestSet.idTestSet);
|
---|
81 | print('Committing...');
|
---|
82 | oDb.commit();
|
---|
83 | else:
|
---|
84 | for oTestSet in aoOrphans:
|
---|
85 | print('#%-7u: idTestBox=%-3u tsCreated=%s tsDone=%s'
|
---|
86 | % (oTestSet.idTestSet, oTestSet.idTestBox, oTestSet.tsCreated, oTestSet.tsDone));
|
---|
87 | print('Not completing any testsets without seeing the --just-do-it option.');
|
---|
88 | else:
|
---|
89 | print('No orphaned test sets.\n');
|
---|
90 | return 0;
|
---|
91 |
|
---|
92 |
|
---|
93 | if __name__ == '__main__':
|
---|
94 | sys.exit(CloseOrphanedTestSets().main())
|
---|
95 |
|
---|