(model_dir, clear=False)
Prepares the model directory. If clear is set to True, deletes all files, else
    renames existing directory and creates a fresh one
    Parameters:
        model_dir: Absolute path of the model directory to prepare
Prepares the model directory. If clear is set to True, deletes all files, else
    renames existing directory and creates a fresh one
    Parameters:
        model_dir: Absolute path of the model directory to prepare
Prepares the model directory . If clear is set to True deletes all files else renames existing directory and creates a fresh one Parameters : model_dir : Absolute path of the model directory to prepare
def prepare_model_dir(model_dir, clear=False):
    """
    Prepares the model directory. If clear is set to True, deletes all files, else
    renames existing directory and creates a fresh one
    Parameters:
        model_dir: Absolute path of the model directory to prepare
    """
    p = list(os.walk(model_dir))

    # Check if directory is not empty (ignore subdirectories)
    if clear:
        for file in os.listdir(model_dir):
            # Delete all files
            path = os.path.join(model_dir, file)
            if os.path.isfile(path):
                try:
                    os.remove(path)
                except:
                    logger.warning('WARNING: Failed to delete {}'.format(path))
    elif len(p[0][2]) > 0:
        # Rename to available directory
        # Max index is 10
        for i in range(1, 10):
            try:
                rename_dir = '{}-{}'.format(model_dir, i)
                if not os.path.exists(rename_dir):
                    os.rename(model_dir, rename_dir)
                    os.mkdir(model_dir)
                    break
            except:
                pass
def prepare_model_dir ( model_dir , clear = False ) : p = list ( os . walk ( model_dir ) ) # Check if directory is not empty (ignore subdirectories) if clear : for file in os . listdir ( model_dir ) : # Delete all files path = os . path . join ( model_dir , file ) if os . path . isfile ( path ) : try : os . remove ( path ) except : logger . warning ( 'WARNING: Failed to delete {}' . format ( path ) ) elif len ( p [ 0 ] [ 2 ] ) > 0 : # Rename to available directory # Max index is 10 for i in range ( 1 , 10 ) : try : rename_dir = '{}-{}' . format ( model_dir , i ) if not os . path . exists ( rename_dir ) : os . rename ( model_dir , rename_dir ) os . mkdir ( model_dir ) break except : pass