<commit_before>"""distutils.dir_util

Utility functions for manipulating directories and directory trees."""

# created 2000/04/03, <NAME> (extracted from util.py)

__revision__ = "$Id$"

import os
from distutils.errors import DistutilsFileError


# cache for by mkpath() -- in addition to cheapening redundant calls,
# eliminates redundant "creating /foo/bar/baz" messages in dry-run mode
PATH_CREATED = {}

# I don't use os.makedirs because a) it's new to Python 1.5.2, and
# b) it blows up if the directory already exists (I want to silently
# succeed in that case).
def mkpath (name, mode=0777, verbose=0, dry_run=0):
    """Create a directory and any missing ancestor directories.  If the
       directory already exists (or if 'name' is the empty string, which
       means the current directory, which of course exists), then do
       nothing.  Raise DistutilsFileError if unable to create some
       directory along the way (eg. some sub-path exists, but is a file
       rather than a directory).  If 'verbose' is true, print a one-line
       summary of each mkdir to stdout.  Return the list of directories
       actually created."""

    global PATH_CREATED

    # XXX what's the better way to handle verbosity? print as we create
    # each directory in the path (the current behaviour), or only announce
    # the creation of the whole path? (quite easy to do the latter since
    # we're not using a recursive algorithm)

    name = os.path.normpath (name)
    created_dirs = []
    if os.path.isdir (name) or name == '':
        return created_dirs
    if PATH_CREATED.get (name):
        return created_dirs

    (head, tail) = os.path.split (name)<commit_msg>'mkpath()' now detects non-string 'name' arguments -- this is a fairly common bug when adding new code, so I thought I'd make it blow up earlier than deep in posix.py.<commit_after>"""distutils.dir_util

Utility functions for manipulating directories and directory trees."""

# created 2000/04/03, <NAME> (extracted from util.py)

__revision__ = "$Id$"

import os
from types import *
from distutils.errors import DistutilsFileError, DistutilsInternalError


# cache for by mkpath() -- in addition to cheapening redundant calls,
# eliminates redundant "creating /foo/bar/baz" messages in dry-run mode
PATH_CREATED = {}

# I don't use os.makedirs because a) it's new to Python 1.5.2, and
# b) it blows up if the directory already exists (I want to silently
# succeed in that case).
def mkpath (name, mode=0777, verbose=0, dry_run=0):
    """Create a directory and any missing ancestor directories.  If the
       directory already exists (or if 'name' is the empty string, which
       means the current directory, which of course exists), then do
       nothing.  Raise DistutilsFileError if unable to create some
       directory along the way (eg. some sub-path exists, but is a file
       rather than a directory).  If 'verbose' is true, print a one-line
       summary of each mkdir to stdout.  Return the list of directories
       actually created."""

    global PATH_CREATED

    # Detect a common bug -- name is None
    if type(name) is not StringType:
        raise DistutilsInternalError, \
              "mkpath: 'name' must be a string (got %s)" % `name`

    # XXX what's the better way to handle verbosity? print as we create
    # each directory in the path (the current behaviour), or only announce
    # the creation of the whole path? (quite easy to do the latter since
    # we're not using a recursive algorithm)

    name = os.path.normpath (name)
    created_dirs = []
    if os.path.isdir (name) or name == '':
        return created_dirs
    if PATH_CREATED.get (name):
        return created_dirs

    (head, tail) = os.path.split (name)
{'fraction_non_alphanumeric': 0.08066239316239317, 'fraction_numerical': 0.009081196581196582, 'mean_word_length': 3.2508513053348467, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '44835', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1034, 'n_words': 486}