#
# BusyB, an automated build utility.
#
# Copyright (C) 1997-2003
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
import time
import os
import Base
import busybee.BusyBException
from Path import Path
from FileVisitor import FileVisitor
from Int import Int
from Interval import Interval
from Recursive import Recursive
class Touch(Base.Base):
def __init__(self):
Base.Base.__init__(self)
self.interval=Int(0)
self.recursive=Recursive()
self.targetPath=Path()
def setParent(self, parent):
parent.addAction(self)
def setInterval(self, i):
self.interval = i
def setRecursive(self, r):
self.recursive = r
def setPath(self, p):
self.targetPath = p
def process(self):
self.getLogger().timeStamp( "Touching: " + self.targetPath() )
self.getLogger().timeStamp( "Interval: " + str(self.interval) )
self.getLogger().timeStamp( "Recursive: " + str(self.recursive()) )
self.doTouch()
return 0
def doTouch(self):
now=time.time()
self.newTime=now+self.interval.getN()
if ( self.recursive() ):
self.doRecursiveTouch(self.targetPath())
else:
self.doSingleTouch( self.targetPath())
def doSingleTouch( self, path ):
if os.path.exists(path):
os.utime( path, (self.newTime, self.newTime) )
else:
f = open(path,"w")
f.close()
return 0
def doRecursiveTouch( self, path ):
fv = FileVisitor( self.doSingleTouch, self.doSingleTouch )
fv.visit( path )
def __str__(self):
return "send mail"
|