filearchiver.py revision cf22150eaeeb72431bf1cf65c309a431454fb22b
# -*- coding: utf-8 -*-
# $Id$
# pylint: disable=C0301
"""
A cronjob that compresses logs and other files, moving them to the
g_ksZipFileAreaRootDir storage area.
"""
__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.
"""
__version__ = "$Revision$"
# Standard python imports
import sys
import os
from optparse import OptionParser
import time;
import zipfile;
# Add Test Manager's modules path
# Test Manager imports
from testmanager import config;
"""
Log+files comp
"""
"""
Parse command line
"""
#self.oTestSetLogic = TestSetLogic(TMDatabaseConnection(self.dprint if self.fVerbose else None));
""" Verbose output. """
print sText;
return True;
"""Prints a warning."""
print sText;
return True;
"""
Worker for processDir.
Same return codes as processDir.
"""
#
# Skip the file if the test set is still running.
# But delete them if the testset is not found.
#
oTestSet = None;
if oTestSet is not None:
return True;
#
# If we have a zip file already, don't try recreate it as we might
# have had trouble removing the source files.
#
#
# Create zip file with all testset files as members.
#
## @todo Consider storing these files outside the zip if they are a little largish.
else:
#
# .zip.tmp -> .zip.
#
#else: Dry run.
else:
#
# Delete the files.
#
return fRc;
"""
Process the given directory (relative to sSrcDir and sDstDir).
Returns success indicator.
"""
#
# Sift thought the directory content, collecting subdirectories and
# sort relevant files by test set.
# Generally there will either be subdirs or there will be files.
#
asSubDirs = [];
dTestSets = {};
# Parse the file name. ASSUMES 'TestSet-%d-filename' format.
continue;
except:
continue;
if idTestSet <= 0:
continue;
continue;
# Add it.
#
# Test sets.
#
try:
except:
self.warning('TestSet %d: Exception in _processTestSet:\n%s' % (idTestSet, '\n'.join(utils.getXcptInfo()),));
#
# Sub dirs.
#
#
# Try Remove the directory iff it's not '.' and it's been unmodified
# for the last 24h (race protection).
#
if sCurDir != '.':
try:
except:
pass;
return fRc;
def main():
""" C-style main(). """
#
# Parse options.
#
oParser = OptionParser();
help = 'Verbose output.');
help = 'Quiet operation.');
help = 'Dry run, do not make any changes.');
if asArgs != []:
return 1;
#
# Do the work.
#
if __name__ == '__main__':