<s> import json <EOL> import os <EOL> import yaml <EOL> from six . moves . urllib import parse <EOL> from six . moves . urllib import request <EOL> from mistralclient import exceptions <EOL> def do_action_on_many ( action , resources , success_msg , error_msg ) : <EOL> """<STR_LIT>""" <EOL> failure_flag = False <EOL> for resource in resources : <EOL> try : <EOL> action ( resource ) <EOL> print ( success_msg % resource ) <EOL> except Exception as e : <EOL> failure_flag = True <EOL> print ( e ) <EOL> if failure_flag : <EOL> raise exceptions . MistralClientException ( error_msg ) <EOL> def load_content ( content ) : <EOL> if content is None or content == '<STR_LIT>' : <EOL> return dict ( ) <EOL> try : <EOL> data = yaml . safe_load ( content ) <EOL> except Exception : <EOL> data = json . loads ( content ) <EOL> return data <EOL> def load_file ( path ) : <EOL> with open ( path , '<STR_LIT:r>' ) as f : <EOL> return load_content ( f . read ( ) ) <EOL> def get_contents_if_file ( contents_or_file_name ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if parse . urlparse ( contents_or_file_name ) . scheme : <EOL> definition_url = contents_or_file_name <EOL> else : <EOL> path = os . path . abspath ( contents_or_file_name ) <EOL> definition_url = parse . urljoin ( <EOL> '<STR_LIT>' , <EOL> request . pathname2url ( path ) <EOL> ) <EOL> return request . urlopen ( definition_url ) . read ( ) . decode ( '<STR_LIT:utf8>' ) <EOL> except Exception : <EOL> return contents_or_file_name </s>
