#!/usr/bin/env python3
# Copyright (c) 2021 Arista Networks, Inc.  All rights reserved.
# Arista Networks, Inc. Confidential and Proprietary.

import argparse
import os
import Tac

description = '''Utility to write a local reload cause'''

# This utility writes a local reload cause atomically
# to the directory used by the reload cause agent.
# This is meant to be used by shell scripts that are not
# able to easily call the writeLocalReloadCause TAC function.
# See BUG 551936 for the rationale behind this file.

def main():
   parser = argparse.ArgumentParser( description=description )
   parser.add_argument( '-d', '--debug-info-filename',
                        help='Name of a debug filename',
                        default = '' )
   parser.add_argument( '-c', '--consume-later',
                        help='Consume the information after boot',
                        action='store_true' )
   parser.add_argument( '-n', '--no-sync-sleep',
                        help='No sleep after sync',
                        action='store_true' )
   parser.add_argument( 'description',
                        help='Description of reload cause' )

   args = parser.parse_args()

   if args.no_sync_sleep:
      os.environ[ 'RELOAD_CAUSE_NOSLEEP' ] = '1'

   reloadConstants = Tac.Value( "ReloadCause::ReloadCauseConstants" )
   reloadConstants.writeLocalReloadCause(
      args.description, args.debug_info_filename, args.consume_later )

if __name__ == '__main__':
   main()
