# -*- coding: utf-8 -*-
# $Id$
"""
Test Manager - VcsRevisions
"""
__copyright__ = \
"""
Copyright (C) 2012-2014 Oracle Corporation
This file is part of VirtualBox Open Source Edition (OSE), as
available from http://www.virtualbox.org. This file is free software;
General Public License (GPL) as published by the Free Software
Foundation, in version 2 as it comes in the "COPYING" file of the
VirtualBox OSE distribution. VirtualBox OSE is distributed in the
hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
The contents of this file may alternatively be used under the terms
of the Common Development and Distribution License Version 1.0
(CDDL) only, as it comes in the "COPYING.CDDL" file of the
VirtualBox OSE distribution, in which case the provisions of the
CDDL are applicable instead of those of the GPL.
You may elect to license modified versions of this file under the
terms and conditions of either the GPL or the CDDL or both.
"""
# Standard python imports.
import unittest;
# Validation Kit imports.
from testmanager.core.base import ModelDataBase, ModelDataBaseTestCase, ModelLogicBase, TMExceptionBase;
"""
A version control system (VCS) revision.
"""
#kasIdAttr = ['sRepository',iRevision];
kasAllowNullAttributes = [ ];
#
# Initialize with defaults.
# See the database for explanations of each of these fields.
#
self.sRepository = None;
"""
Re-initializes the object from a SELECT * FROM VcsRevisions row.
Returns self. Raises exception if aoRow is None.
"""
if aoRow is None:
raise TMExceptionBase('VcsRevision not found.');
return self;
"""
Initialize from the database, given the tree and revision of a row.
"""
oDb.execute('SELECT * FROM VcsRevisions WHERE sRepository = %s AND iRevision = %u', (sRepository, iRevision,));
if aoRow is None:
"""
Reinitializes form a set of values.
return self.
"""
return self;
"""
VCS revisions database logic.
"""
#
# Standard methods.
#
"""
Fetches VCS revisions for listing.
Returns an array (list) of VcsRevisionData items, empty list if none.
Raises exception on error.
"""
_ = tsNow;
'FROM VcsRevisions\n'
'ORDER BY tsCreated, sRepository, iRevision\n'
'LIMIT %s OFFSET %s\n'
aoRows = [];
return aoRows;
"""
Tries to fetch the specified tree revision record.
Returns VcsRevisionData instance if found, None if not found.
Raises exception on input and database errors.
"""
( sRepository, iRevision, ));
return None
#
# Other methods.
#
"""
Adds (or updates) a tree revision record.
Raises exception on input and database errors.
"""
# Check VcsRevisionData before do anything
# Does it already exist?
if oOldData is None:
# New row.
self._oDb.execute('INSERT INTO VcsRevisions (sRepository, iRevision, tsCreated, sAuthor, sMessage)\n'
'VALUES (%s, %s, %s, %s, %s)\n'
, ( oData.sRepository,
));
# Update old row.
' SET tsCreated = %s,\n'
' sAuthor = %s,\n'
' sMessage = %s\n'
'WHERE sRepository = %s\n'
' AND iRevision = %s'
));
return oData;
"""
Get the last known revision number for the given repository, returns 0
if the repository is not known to us:
"""
'FROM VcsRevisions\n'
'WHERE sRepository = %s\n'
'ORDER BY iRevision DESC\n'
'LIMIT 1\n'
, ( sRepository, ));
return 0;
"""
Fetches a VCS timeline portion for a repository.
Returns an array (list) of VcsRevisionData items, empty list if none.
Raises exception on error.
"""
'FROM VcsRevisions\n'
'WHERE sRepository = %s\n'
' AND iRevision > %s\n'
' AND iRevision <= %s\n'
'ORDER BY iRevision DESC\n'
'LIMIT %s\n'
aoRows = [];
return aoRows;
#
# Unit testing.
#
# pylint: disable=C0111
if __name__ == '__main__':
# not reached.