<commit_before>import os
import os.path

def ensureDirectory(dir):
    if not os.path.exists(dir):
        os.makedirs(dir)

def update():
    try:
        import inviwoqt as qt
        qt.update();
    except: 
        pass


def snapshotAllCanvasesWithWorkspace(basePath: str , workspaceName  , canvasFilenamePrefix="" , canvasFilenameSufix = "" , filetype="png"):
    import inviwo as i
    canvases = [];
    for canvas in i.listCanvases():
        canvases.append(canvas[0])
    return snapshotWithWorkspace(basePath , canvases, workspaceName, canvasFilenamePrefix, canvasFilenameSufix , filetype )



def snapshotWithWorkspace(basePath: str, canvases , workspaceName  , canvasFilenamePrefix="" , canvasFilenameSufix = "" , filetype="png"):
    canvasList = []
    if type(canvases) is list:
        canvasList = canvases
    elif type(canvases) is str:
        canvasList = [canvases]
    else:
        raise TypeError("snapshotWithWorkspace expect parameter 2 to be either string or a list of strings of canvas ids")


    import inviwo
    import inviwoqt

    if not workspaceName.endswith('.inv'):
        workspaceName = workspaceName + '.inv'

    inviwoqt.saveWorkspace(basePath + "/" + workspaceName );

    workspacePath = basePath + "/" + workspaceName;
    workspaceDir = os.path.dirname(workspacePath);
    
    ensureDirectory(basePath)
    ensureDirectory(workspaceDir)

    inviwoqt.saveWorkspace(basePath + "/" + workspaceName  , False);<commit_msg>Python3: Removed duplicated code in inviwo_utils.py<commit_after>import os
import os.path

def ensureDirectory(dir):
    if not os.path.exists(dir):
        os.makedirs(dir)

def update():
    try:
        import inviwoqt as qt
        qt.update();
    except: 
        pass


def snapshotAllCanvasesWithWorkspace(basePath: str , workspaceName  , canvasFilenamePrefix="" , canvasFilenameSufix = "" , filetype="png"):
    import inviwo as i
    canvases = [];
    for canvas in i.listCanvases():
        canvases.append(canvas[0])
    return snapshotWithWorkspace(basePath , canvases, workspaceName, canvasFilenamePrefix, canvasFilenameSufix , filetype )



def snapshotWithWorkspace(basePath: str, canvases , workspaceName  , canvasFilenamePrefix="" , canvasFilenameSufix = "" , filetype="png"):
    canvasList = []
    if type(canvases) is list:
        canvasList = canvases
    elif type(canvases) is str:
        canvasList = [canvases]
    else:
        raise TypeError("snapshotWithWorkspace expect parameter 2 to be either string or a list of strings of canvas ids")

    import inviwo
    import inviwoqt

    if not workspaceName.endswith('.inv'):
        workspaceName = workspaceName + '.inv'


    workspacePath = basePath + "/" + workspaceName;
    workspaceDir = os.path.dirname(workspacePath);
    
    ensureDirectory(basePath)
    ensureDirectory(workspaceDir)

    inviwoqt.saveWorkspace(basePath + "/" + workspaceName  , False);
{'fraction_non_alphanumeric': 0.09698423577793008, 'fraction_numerical': 0.0017135023989033585, 'mean_word_length': 3.4496951219512195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1773710', 'n_tokens_mistral': 871, 'n_tokens_neox': 866, 'n_words': 212}