<s> """<STR_LIT>""" <EOL> import logging <EOL> import os <EOL> import sys <EOL> def FixPath ( ) : <EOL> parent_dir = os . path . dirname ( os . path . realpath ( sys . argv [ <NUM_LIT:0> ] ) ) <EOL> if os . path . isdir ( parent_dir ) : <EOL> sys . path . append ( parent_dir ) <EOL> FixPath ( ) <EOL> from utils import LockFile <EOL> from utils import System <EOL> from metadata_watcher import MetadataWatcher <EOL> LOCKFILE = '<STR_LIT>' <EOL> def HandleClockDriftToken ( metadata_watcher , on_change ) : <EOL> """<STR_LIT>""" <EOL> clock_drift_token_key = '<STR_LIT>' <EOL> def Handler ( event ) : <EOL> on_change ( event ) <EOL> metadata_watcher . WatchMetadataForever ( clock_drift_token_key , <EOL> Handler , initial_value = '<STR_LIT>' ) <EOL> def OnChange ( event ) : <EOL> """<STR_LIT>""" <EOL> system = System ( ) <EOL> logging . info ( '<STR_LIT>' , event ) <EOL> logging . info ( '<STR_LIT>' ) <EOL> result = system . RunCommand ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> if system . RunCommandFailed ( result ) : <EOL> logging . error ( '<STR_LIT>' ) <EOL> else : <EOL> logging . info ( '<STR_LIT>' ) <EOL> def Main ( system = System ( ) , logger = logging . getLogger ( ) , log_handler = None , <EOL> lock_file = LockFile ( ) , lock_fname = None ) : <EOL> if not log_handler : <EOL> log_handler = system . MakeLoggingHandler ( <EOL> '<STR_LIT>' , logging . handlers . SysLogHandler . LOG_SYSLOG ) <EOL> system . SetLoggingHandler ( logger , log_handler ) <EOL> logging . info ( '<STR_LIT>' ) <EOL> if not lock_fname : <EOL> lock_fname = LOCKFILE <EOL> watcher = MetadataWatcher ( ) <EOL> lock_file . RunExclusively ( lock_fname , HandleClockDriftToken ( watcher , OnChange ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> Main ( ) </s>
