def create_tree(path, tree, archives_leading_dir=True, remove_existing=False):
    'Given a list of tuples (name, load) create such a tree\n\n    if load is a tuple itself -- that would create either a subtree or an archive\n    with that content and place it into the tree if name ends with .tar.gz\n    '
    lgr.log(5, 'Creating a tree under %s', path)
    if (not exists(path)):
        os.makedirs(path)
    if isinstance(tree, dict):
        tree = tree.items()
    for (file_, load) in tree:
        if isinstance(file_, File):
            executable = file_.executable
            name = file_.name
        else:
            executable = False
            name = file_
        full_name = op.join(path, name)
        if (remove_existing and lexists(full_name)):
            rmtree(full_name, chmod_files=True)
        if isinstance(load, (tuple, list, dict)):
            if (name.endswith('.tar.gz') or name.endswith('.tar') or name.endswith('.zip')):
                create_tree_archive(path, name, load, archives_leading_dir=archives_leading_dir)
            else:
                create_tree(full_name, load, archives_leading_dir=archives_leading_dir, remove_existing=remove_existing)
        else:
            open_func = open
            if full_name.endswith('.gz'):
                open_func = gzip.open
            elif (full_name.split('.')[(- 1)] in ('xz', 'lzma')):
                import lzma
                open_func = lzma.open
            with open_func(full_name, 'wb') as f:
                f.write(ensure_bytes(load, 'utf-8'))
        if executable:
            os.chmod(full_name, (os.stat(full_name).st_mode | stat.S_IEXEC))
Given a list of tuples (name, load) create such a tree

if load is a tuple itself -- that would create either a subtree or an archive
with that content and place it into the tree if name ends with .tar.gz
def create_tree(path, tree, archives_leading_dir=True, remove_existing=False):
    'Given a list of tuples (name, load) create such a tree\n\n    if load is a tuple itself -- that would create either a subtree or an archive\n    with that content and place it into the tree if name ends with .tar.gz\n    '
    lgr.log(5, 'Creating a tree under %s', path)
    if (not exists(path)):
        os.makedirs(path)
    if isinstance(tree, dict):
        tree = tree.items()
    for (file_, load) in tree:
        if isinstance(file_, File):
            executable = file_.executable
            name = file_.name
        else:
            executable = False
            name = file_
        full_name = op.join(path, name)
        if (remove_existing and lexists(full_name)):
            rmtree(full_name, chmod_files=True)
        if isinstance(load, (tuple, list, dict)):
            if (name.endswith('.tar.gz') or name.endswith('.tar') or name.endswith('.zip')):
                create_tree_archive(path, name, load, archives_leading_dir=archives_leading_dir)
            else:
                create_tree(full_name, load, archives_leading_dir=archives_leading_dir, remove_existing=remove_existing)
        else:
            open_func = open
            if full_name.endswith('.gz'):
                open_func = gzip.open
            elif (full_name.split('.')[(- 1)] in ('xz', 'lzma')):
                import lzma
                open_func = lzma.open
            with open_func(full_name, 'wb') as f:
                f.write(ensure_bytes(load, 'utf-8'))
        if executable:
            os.chmod(full_name, (os.stat(full_name).st_mode | stat.S_IEXEC))