# # VickyInstallerMon.py # # watch InSite builds published to \\perforce1\InSiteInstallers, # copy latest of each release branch to \\h-vmfarm4\InSiteInstallers # # the cache on h-vmfarm4 won't be a full mirror of perforce1, # we only care about recent stuff # # assume that each build gets put into dir named like "InSite_5.6.0.5680", # and a matching zip file InSite_5.6.0.5680.zip is written beside it after # the directory is fully populated # # eventually, we will want to auto-purge old builds that are no longer # of interest, except for ones that are manually marked as worth keeping. # # the local account vickybuild should have sufficient permissions to read # the source dir, and write/delete files/dirs in the destination dir # import sys import re import os import time import traceback import win32api import pprint from pprint import pprint as pp # pretty print import logging import logging.handlers #import win32serviceutil #import win32service #import win32event #import win32api #import win32wnet #import win32crypt #import win32netcon _scriptfile = sys.argv[0] _scriptpath = os.path.abspath( _scriptfile ) _scriptdir = os.path.dirname( _scriptpath ) _scriptname = os.path.splitext( os.path.basename( _scriptpath ) )[0] LOGDIR = os.path.join( _scriptdir, 'logs' ) if not os.path.isdir( LOGDIR ): os.makedirs( LOGDIR ) LOGFILENAME = _scriptname + '.log' LOGFILEPATH = os.path.join( LOGDIR, LOGFILENAME ) def initlog(): #h = logging.FileHandler( LOGFILEPATH, 'a' ) h = logging.handlers.TimedRotatingFileHandler( LOGFILEPATH, 'M', 2, 7 ) h.setLevel( logging.DEBUG ) f = logging.Formatter( '%(asctime)s %(levelname)s %(message)s', '%Y-%m-%d %H:%M:%S' ) h.setFormatter( f ) logging.root.addHandler( h ) logging.root.setLevel( logging.DEBUG ) def now(): return time.ctime( time.time() ) dryrun = True cancelled = False def testlog(): initlog() try: logging.info( '-' * 79 ) logging.info( 'starting on %s', win32api.GetComputerName() ) global cancelled while not cancelled: try: logging.debug( 'scheduling next rescan at %s', time.ctime( time.time() + 10 ) ) time.sleep( 10 ) logging.debug( 'rescanning' ) except KeyboardInterrupt: cancelled = True except: logging.exception( 'error scanning' ) logging.debug( 'scheduling next retry at %s', time.ctime( time.time() + 10 ) ) time.sleep( 10 ) #sys.exit( 1 ) finally: logging.info( 'ending' ) if __name__ == '__main__': testlog()