#!/usr/bin/env python3
from _rfstools import arg_parser, arg_processor
import logging


def get_instance():
  p = arg_parser.oneplus_arg_parser(description='This command exits with success, when all given remote files are dirs. The command fails with 2, when at least one of files is not dir.')
  return arg_processor.init(p, "pisdir", [])

try:
  with get_instance() as ic:

    for f in ic.files:
      if f.remote == False:
        raise ValueError("A given file must be remote.")
      
      if not ic.connection.isdir(f.path):
        logging.info("Remote file {} is not a dir. Exiting. (returning 2)".format(f.path))
        exit(2)

except Exception: 
  logging.exception("Fatal error. (returning 1)")
  exit(1)
 
logging.info("Finished succesfully. (returning 0)")
exit(0)
