<s> import imp <EOL> import os <EOL> import inspect <EOL> import logging <EOL> class YAS3FSPlugin ( object ) : <EOL> @ staticmethod <EOL> def load_from_file ( yas3fs , filepath , expected_class = None ) : <EOL> class_inst = None <EOL> try : <EOL> mod_name , file_ext = os . path . splitext ( os . path . split ( filepath ) [ - <NUM_LIT:1> ] ) <EOL> if file_ext . lower ( ) == '<STR_LIT>' : <EOL> py_mod = imp . load_source ( mod_name , filepath ) <EOL> elif file_ext . lower ( ) == '<STR_LIT>' : <EOL> py_mod = imp . load_compiled ( mod_name , filepath ) <EOL> else : <EOL> raise <EOL> if not py_mod : <EOL> raise <EOL> for klass in inspect . getmembers ( py_mod , inspect . isclass ) : <EOL> if not issubclass ( klass [ <NUM_LIT:1> ] , YAS3FSPlugin ) : <EOL> continue <EOL> if expected_class == None or expected_class == klass [ <NUM_LIT:0> ] : <EOL> class_inst = klass [ <NUM_LIT:1> ] ( yas3fs ) <EOL> break <EOL> except Exception , e : <EOL> raise Exception ( "<STR_LIT>" + filepath + "<STR_LIT:U+0020>" + e ) <EOL> if not class_inst : <EOL> raise Exception ( "<STR_LIT>" + expected_class + "<STR_LIT:U+0020>" + e ) <EOL> return class_inst <EOL> @ staticmethod <EOL> def load_from_class ( yas3fs , expected_class ) : <EOL> try : <EOL> module_name = '<STR_LIT>' + expected_class <EOL> module = __import__ ( module_name ) <EOL> klass = getattr ( module . __dict__ [ expected_class ] , expected_class ) <EOL> class_inst = klass ( yas3fs ) <EOL> return class_inst <EOL> except Exception , e : <EOL> print str ( e ) <EOL> raise Exception ( "<STR_LIT>" + expected_class + "<STR_LIT:U+0020>" + str ( e ) ) <EOL> def __init__ ( self , yas3fs , logger = None ) : <EOL> self . logger = logger <EOL> if ( not self . logger ) : <EOL> self . logger = logging . getLogger ( '<STR_LIT>' ) <EOL> def do_cmd_on_s3_now_w_retries ( self , fn ) : <EOL> def wrapper ( * args , ** kargs ) : <EOL> try : <EOL> return fn ( * args , ** kargs ) <EOL> except Exception as e : <EOL> selfless_args = None <EOL> if args [ <NUM_LIT:1> ] : <EOL> selfless_args = args [ <NUM_LIT:1> : ] <EOL> self . logger . info ( "<STR_LIT>" + "<STR_LIT:U+0020>" + str ( selfless_args ) ) <EOL> return args [ <NUM_LIT:2> ] <EOL> return wrapper </s>
