<s> import logging <EOL> import os <EOL> import shutil <EOL> from pypdfocr_filer import PyFiler <EOL> """<STR_LIT>""" <EOL> class PyFilerDirs ( PyFiler ) : <EOL> def __init__ ( self ) : <EOL> self . target_folder = None <EOL> self . default_folder = None <EOL> self . original_move_folder = None <EOL> self . folder_targets = { } <EOL> def add_folder_target ( self , folder , keywords ) : <EOL> assert folder not in self . folder_targets , "<STR_LIT>" % ( folder ) <EOL> self . folder_targets [ folder ] = keywords <EOL> def file_original ( self , original_filename ) : <EOL> if not self . original_move_folder : <EOL> logging . debug ( "<STR_LIT>" ) <EOL> return original_filename <EOL> tgt_path = self . original_move_folder <EOL> logging . debug ( "<STR_LIT>" % ( original_filename , tgt_path ) ) <EOL> tgtfilename = os . path . join ( tgt_path , os . path . basename ( original_filename ) ) <EOL> tgtfilename = self . _get_unique_filename_by_appending_version_integer ( tgtfilename ) <EOL> shutil . move ( original_filename , tgtfilename ) <EOL> return tgtfilename <EOL> def move_to_matching_folder ( self , filename , foldername ) : <EOL> assert self . target_folder != None <EOL> assert self . default_folder != None <EOL> if not foldername : <EOL> logging . info ( "<STR_LIT>" % ( filename , self . default_folder ) ) <EOL> tgt_path = os . path . join ( self . target_folder , self . default_folder ) <EOL> else : <EOL> logging . info ( "<STR_LIT>" % ( filename , foldername ) ) <EOL> tgt_path = os . path . join ( self . target_folder , foldername ) <EOL> if not os . path . exists ( tgt_path ) : <EOL> logging . debug ( "<STR_LIT>" % tgt_path ) <EOL> os . makedirs ( tgt_path ) <EOL> logging . debug ( "<STR_LIT>" % ( filename , tgt_path ) ) <EOL> tgtfilename = os . path . join ( tgt_path , os . path . basename ( filename ) ) <EOL> tgtfilename = self . _get_unique_filename_by_appending_version_integer ( tgtfilename ) <EOL> shutil . move ( filename , tgtfilename ) <EOL> return tgtfilename </s>
