def mkpath(name, mode=511, verbose=1, dry_run=0):
 global _path_created
 if (not isinstance(name, StringTypes)):
  raise DistutilsInternalError, ("mkpath: 'name' must be a string (got %r)" % (name,))
 name = os.path.normpath(name)
 created_dirs = []
 if (os.path.isdir(name) or (name == '')):
  return created_dirs
 if _path_created.get(os.path.abspath(name)):
  return created_dirs
 (head, tail) = os.path.split(name)
 tails = [tail]
 while (head and tail and (not os.path.isdir(head))):
  (head, tail) = os.path.split(head)
  tails.insert(0, tail)
 for d in tails:
  head = os.path.join(head, d)
  abs_head = os.path.abspath(head)
  if _path_created.get(abs_head):
   continue
  if (verbose >= 1):
   log.info('creating %s', head)
  if (not dry_run):
   try:
    os.mkdir(head)
    created_dirs.append(head)
   except OSError as exc:
    raise DistutilsFileError, ("could not create '%s': %s" % (head, exc[(-1)]))
  _path_created[abs_head] = 1
 return created_dirs

def mkpath ( name , mode = 511 , verbose = 1 , dry_run = 0 ) : global _path_created if ( not isinstance ( name , StringTypes ) ) : raise DistutilsInternalError , ( "mkpath: 'name' must be a string (got %r)" % ( name , ) ) name = os . path . normpath ( name ) created_dirs = [ ] if ( os . path . isdir ( name ) or ( name == '' ) ) : return created_dirs if _path_created . get ( os . path . abspath ( name ) ) : return created_dirs ( head , tail ) = os . path . split ( name ) tails = [ tail ] while ( head and tail and ( not os . path . isdir ( head ) ) ) : ( head , tail ) = os . path . split ( head ) tails . insert ( 0 , tail ) for d in tails : head = os . path . join ( head , d ) abs_head = os . path . abspath ( head ) if _path_created . get ( abs_head ) : continue if ( verbose >= 1 ) : log . info ( 'creating %s' , head ) if ( not dry_run ) : try : os . mkdir ( head ) created_dirs . append ( head ) except OSError as exc : raise DistutilsFileError , ( "could not create '%s': %s" % ( head , exc [ ( - 1 ) ] ) ) _path_created [ abs_head ] = 1 return created_dirs
build os-dependent paths properly .