<s> import os <EOL> import os . path <EOL> import shutil <EOL> import simport <EOL> class MissingArgument ( Exception ) : <EOL> pass <EOL> class ArchiveCallback ( object ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> pass <EOL> def on_open ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def on_close ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> return filename <EOL> class CallbackList ( ArchiveCallback ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( CallbackList , self ) . __init__ ( ** kwargs ) <EOL> self . callbacks = [ ] <EOL> self . config = kwargs <EOL> callback_str = self . config . get ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> callback_str_list = [ x . strip ( ) for x in callback_str . split ( "<STR_LIT:U+002C>" ) ] <EOL> self . callbacks = [ simport . load ( c ) ( ** self . config ) <EOL> for c in callback_str_list ] <EOL> def on_open ( self , filename ) : <EOL> for c in self . callbacks : <EOL> c . on_open ( filename ) <EOL> def on_close ( self , filename ) : <EOL> for c in self . callbacks : <EOL> filename = c . on_close ( filename ) <EOL> class ChangeExtensionCallback ( ArchiveCallback ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( ChangeExtensionCallback , self ) . __init__ ( ** kwargs ) <EOL> self . new_extension = kwargs . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def on_close ( self , filename ) : <EOL> new = "<STR_LIT>" % ( filename , self . new_extension ) <EOL> os . rename ( filename , new ) <EOL> return new <EOL> class MoveFileCallback ( ArchiveCallback ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( MoveFileCallback , self ) . __init__ ( ** kwargs ) <EOL> self . destination_folder = kwargs . get ( '<STR_LIT>' , '<STR_LIT:.>' ) <EOL> def on_close ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> shutil . move ( filename , self . destination_folder ) <EOL> path , fn = os . path . split ( filename ) <EOL> return os . path . join ( self . destination_folder , fn ) <EOL> class DeleteFileCallback ( ArchiveCallback ) : <EOL> def on_close ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> os . remove ( filename ) <EOL> return None </s>
