text: # Control all containers
  # Simple Python script for interacting with all Docker containers
  # Author: Michael Grigoryan 2021
  import time
  import docker
  
  # Process start time
  t0 = time.perf_counter()
  # Docker client
  client = docker.from_env()
  # All containers
  containers = client.containers.list(True)
  
  # Done message
  done_message = "Done."
  # String used for dividing actions
  divider_string = "------------------"
  # Starting all containers message
  starting_all_message = "Starting all containers"
  # Stopping all containers message
  stopping_all_message = "Stopping all containers"
  # Restarting all containers message
  restarting_all_message = "Restarting all containers"
  # Invalid choice message
  invalid_choice_message = "Hmm.. seems like there's no option like that. Try again"
  
  # For starting all containers
  def startAll():
      # Info log
      print(starting_all_message)
      # Loop through all containers
      for container in containers:
          # Container id
          id = container.id
          # Info log
          print("Starting container " + id)
          # Start the container with id
          client.api.start(id)
          # Info log
          print("Container " + id + " has started")
          # Separator
          print(divider_string)
  
      return
  
  # For stopping all containers
  def stopAll():
      # Info log
      print(stopping_all_message)
      # Loop through all containers
      for container in containers:
          # Container id
          id = container.id
          # Info log
          print("Stopping container " + id)
          # Start the container with id
          client.api.stop(id)
          # Info log
          print("Container " + id + " has been stopped")
          # Separator
          print(divider_string)
  
      return
  
  def restartAll():
      # Info log
      print(restarting_all_message)
      stopAll()
      startAll()
  
      return
  
  # Entry
  def init(
      # Variable to check whether previous choice was valid or not
      isInvalid = False
  ):
      try:
          # If previous choice was invalid
          if (isInvalid):
              # Print invalid choice message
              print(invalid_choice_message)
  
          # User input
          action = int(input("Would you like to start(1), stop(2) or restart(3) all your containers? \n> "))
          # Divider string
          print(divider_string)
  
          # If user selected 1
          if action == 1:
              # Start all containers
              startAll()
  
          # If user selected 2
          elif action == 2:
              # Stop all containers
              stopAll()
          
          # If user selected 3
          elif action == 3:
              # Restart all containers
              restartAll()
          # If user's choice is incorrect
          else:
              # Try again
              init(True)
          
      # If user's choice is not an integer
      except Exception:
          # Try again
          init(True)
  
  # Used for logging execution time
  def performanceLog():
      # End time
      t1 = time.perf_counter()
      # Calculated time
      final_process_time = t1 - t0
      # Info log
      return print("Executed in " + str(final_process_time) + " seconds")
  
  
  # Program start
  if __name__ == "__main__":
      # Entry
      init()
      # Performance log
      performanceLog()
  