#!%%PYTHON_BIN%% ## # Copyright (C) 2003 by Duke University # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. # # $Id: epylog.in,v 1.10.2.2 2004/02/09 20:46:11 icon Exp $ # # @Author Konstantin Ryabitsev # @version $Date: 2004/02/09 20:46:11 $ # import os import sys import getopt import time import libxml2 sys.path.insert(0, '%%PY_MODULE_DIR%%') from epylog import * DEFAULT_EPYLOG_CONFIG = '%%pkgconfdir%%/epylog.conf' EPYLOG_PIDFILE = '%%localstatedir%%/run/epylog.pid' def unxmlify_offsets(ofile, logger): """ Take the XML file with offsets and return them as a dictionary. """ logger.put(5, '>epylog.unxmlify_offsets') logger.put(3, 'Checking if we can read "%s"' % ofile) if not os.access(ofile, os.R_OK): logger.put(3, 'Could not read offsets file "%s"' % ofile) logger.put(3, 'Returning blank tuple') logger.put(5, 'epylog.xmlify_offsets') try: logger.put(3, 'Trying to open "%s" for writing.' % ofile) fh = open(ofile, 'w') except IOError: logger.put(0, 'Could not open "%s" for writing! Offsets not saved!') return logger.puthang(3, 'Making XML out of offset map') doc = libxml2.newDoc('1.0') root = doc.newChild(None, 'epylog-offsets', None) for entry in omap: enode = root.newChild(None, 'entry', None) enode.newChild(None, 'log', entry[0]) enode.newChild(None, 'inode', str(entry[1])) enode.newChild(None, 'offset', str(entry[2])) logger.endhang(3) offsets = doc.serialize() doc.freeDoc() logger.put(5, offsets) import fcntl logger.put(3, 'Locking the offsets file') fcntl.flock(fh.fileno(), fcntl.LOCK_EX) logger.puthang(3, 'Writing the offsets into "%s"' % ofile) fh.write(offsets) logger.endhang(3) logger.put(3, 'Unlocking the offsets file') fcntl.flock(fh.fileno(), fcntl.LOCK_UN) fh.close() logger.put(5, 'epylog.restore_offsets') ofile = os.path.join(epylog.vardir, 'offsets.xml') omap = unxmlify_offsets(ofile, logger) for o in omap: try: epylog.logtracker.set_start_offset_by_entry(o[0], o[1], o[2]) except NoSuchLogError: logger.put(0, 'No such log in tracker: %s' % o[0]) logger.put(5, 'epylog.store_offsets') ofile = os.path.join(epylog.vardir, 'offsets.xml') omap = epylog.logtracker.get_offset_map() xmlify_offsets(omap, ofile, logger) logger.put(5, '