def __init__(self, config_path=None, log=sys.stdout, log_level=LogLevels.INFO): """ Create an object to interface with the ARC server. :param config_path: Path to config JSON file, or ``None`` to use the default settings :param log: File-like object to write log messages to, or ``None`` to disable logging. Use ``sys.stdout`` or ``sys.stderr`` to print messages (default: ``sys.stdout``). :param log_level: The level of detail logs should show (default: `LogLevels.INFO`). See `LogLevels` for the available levels :raises InvalidConfigError: if config is not valid JSON or is otherwise invalid """ self.logger = arc.Logger(arc.Logger_getRootLogger(), "jobsubmit") # Add a log destination if the user has provided one if log: log_dest = arc.LogStream(log) log_dest.setFormat(arc.ShortFormat) arc.Logger_getRootLogger().addDestination(log_dest) arc.Logger_getRootLogger().setThreshold(log_level.value) config_dict = {} if config_path: try: self.logger.msg( arc.DEBUG, "Using jasmin_arc config: {}".format(config_path)) # Let errors reading file bubble to calling code with open(config_path) as config_file: config_dict = json.load(config_file) # Catch JSON parsing errors except ValueError as e: raise InvalidConfigError(e.message) self.config = ConnectionConfig(config_dict, logger=self.logger) # Create jinja2 environment for loading JSDL template(s) self.env = Environment(loader=PackageLoader(__name__, TEMPLATES_DIR), autoescape=select_autoescape(["xml"])) self.cached_user_config = None