#!/usr/bin/python # Daemon for processing the Perforce Journal file as it is written to. import Journal, Setup, listener, cutil, p4util, types, os DEFAULT_REMOTE_CHECKPOINT_COUNTER = 'remote-checkpoint' def ConfigureLastCheckpoint(): ''' Configure the "lastCheckpoint" property in the Setup parameters. This value represents the last checkpoint the remote server was restored from. As it can be tricky to accurately represent in these scripts, you can alternatively default the value to None or a string, and the system will use the Perforce counter with that name (default is 'remote-checkpoint'). ''' lastcp = Setup.SERVER.lastCheckpoint if lastcp is None: lastcp = DEFAULT_REMOTE_CHECKPOINT_COUNTER if type(lastcp) in types.StringTypes: p4 = p4util.createP4() lastcp = p4.getCounter(lastcp) if lastcp is not None: Setup.lastCheckpoint = lastcp cutil.log(cutil.WARN, 'Using remote last checkpoint %d' % lastcp) if lastcp is None or type(lastcp) != types.IntType: cutil.log(cutil.FATAL, "Invalid last checkpoint value [%s]" % str(lastcp)) if __name__ == "__main__": cutil.log(cutil.WARN, "Starting daemon.") ConfigureLastCheckpoint() # started from the command-line try: poller = Journal.RotateJournal(Setup.SERVER.lastCheckpoint, Journal.TailJournalFile( Setup.SERVER.journal, os.path.join(Setup.SERVER.datadir, "journal-position"), True), Setup.SERVER.rotateJournal) loop = listener.ListenerRunner(poller, Setup.JOURNAL.listeners) loop.setupSignals() loop.loop(Setup.POLL_INTERVAL) except: cutil.log_error(cutil.FATAL) cutil.log(cutil.WARN, "Ending daemon.")