turntable/utils.py
def create_dir(path, dir_dict={}):
    '''
    Tries to create a new directory in the given path.
    **create_dir** can also create subfolders according to the dictionnary given as second argument.

    Parameters
    ----------
    path : string
        string giving the path of the location to create the directory, either absolute or relative.
    dir_dict : dictionary, optional 
        Dictionary ordering the creation of subfolders. Keys must be strings, and values either None or path dictionaries.
        the default is {}, which means that no subfolders will be created

    Examples
    --------

    >>> path = './project'
    >>> dir_dict = {'dir1':None, 'dir2':{'subdir21':None}}
    >>> utils.create_dir(path, dir_dict)

    will create:

    * *project/dir1*
    * *project/dir2/subdir21*

    in your parent directory.

    '''

    folders = path.split('/')
    folders = [i for i in folders if i != '']
    rootPath = ''
    if folders[0] == 'C:':
        folders = folders[1:]
    count = 0
    for directory in folders:
        count += 1

        # required to handle the dot operators
        if (directory[0] == '.') & (count == 1):
            rootPath = directory
        else:
            rootPath = rootPath + '/' + directory
        try:
            os.makedirs(rootPath)
        # If the file already exists (EEXIST), raise exception and do nothing
        except OSError as exception:
            if exception.errno != errno.EEXIST:
                raise

    for key in dir_dict.keys():
        rootPath = path + "/" + key
        try:
            os.makedirs(rootPath)
        # If the file already exists (EEXIST), raise exception and do nothing
        except OSError as exception:
            if exception.errno != errno.EEXIST:
                raise
        if dir_dict[key] is not None:
            create_dir(rootPath, dir_dict[key])
def create_dir(path, dir_dict={}):
    '''
    Tries to create a new directory in the given path.
    **create_dir** can also create subfolders according to the dictionnary given as second argument.

    Parameters
    ----------
    path : string
        string giving the path of the location to create the directory, either absolute or relative.
    dir_dict : dictionary, optional 
        Dictionary ordering the creation of subfolders. Keys must be strings, and values either None or path dictionaries.
        the default is {}, which means that no subfolders will be created

    Examples
    --------

    >>> path = './project'
    >>> dir_dict = {'dir1':None, 'dir2':{'subdir21':None}}
    >>> utils.create_dir(path, dir_dict)

    will create:

    * *project/dir1*
    * *project/dir2/subdir21*

    in your parent directory.

    '''

    folders = path.split('/')
    folders = [i for i in folders if i != '']
    rootPath = ''
    if folders[0] == 'C:':
        folders = folders[1:]
    count = 0
    for directory in folders:
        count += 1

        # required to handle the dot operators
        if (directory[0] == '.') & (count == 1):
            rootPath = directory
        else:
            rootPath = rootPath + '/' + directory
        try:
            os.makedirs(rootPath)
        # If the file already exists (EEXIST), raise exception and do nothing
        except OSError as exception:
            if exception.errno != errno.EEXIST:
                raise

    for key in dir_dict.keys():
        rootPath = path + "/" + key
        try:
            os.makedirs(rootPath)
        # If the file already exists (EEXIST), raise exception and do nothing
        except OSError as exception:
            if exception.errno != errno.EEXIST:
                raise
        if dir_dict[key] is not None:
            create_dir(rootPath, dir_dict[key])
Tries to create a new directory in the given path.
    **create_dir** can also create subfolders according to the dictionnary given as second argument.

    Parameters
    ----------
    path : string
        string giving the path of the location to create the directory, either absolute or relative.
    dir_dict : dictionary, optional 
        Dictionary ordering the creation of subfolders. Keys must be strings, and values either None or path dictionaries.
        the default is {}, which means that no subfolders will be created

    Examples
    --------

    >>> path = './project'
    >>> dir_dict = {'dir1':None, 'dir2':{'subdir21':None}}
    >>> utils.create_dir(path, dir_dict)

    will create:

    * *project/dir1*
    * *project/dir2/subdir21*

    in your parent directory.