Taken and modified from os.makedirs to set user, group and mode for each
    directory created.

    CLI Example:

    .. code-block:: bash

        salt '*' file.makedirs_perms /opt/code
13986
def makedirs_perms(name,
                   user=None,
                   group=None,
                   mode='0755'):
    '''
    
    '''
    name = os.path.expanduser(name)

    path = os.path
    head, tail = path.split(name)
    if not tail:
        head, tail = path.split(head)
    if head and tail and not path.exists(head):
        try:
            makedirs_perms(head, user, group, mode)
        except OSError as exc:
            # be happy if someone already created the path
            if exc.errno != errno.EEXIST:
                raise
        if tail == os.curdir:  # xxx/newdir/. exists if xxx/newdir exists
            return
    os.mkdir(name)
    check_perms(name,
                None,
                user,
                group,
                int('{0}'.format(mode)) if mode else None)
178434
def make_directories
      begin
        `rm -rf #{@blastdb_dir}` if File.directory?(@blastdb_dir) && @rebuild_db
        Dir.mkdir(@blastdb_dir) unless File.directory?(@blastdb_dir)

        `rm -rf #{@gff_dir}` if File.directory?(@gff_dir) && @rebuild_db
        Dir.mkdir(@gff_dir) unless File.directory?(@gff_dir)

        Dir.mkdir(@log_dir) unless File.directory?(@log_dir)
      rescue SystemCallError => e
        @output.puts e.message
        raise "Unable to make directory. " <<
          "Perhaps you forgot to execute the quorum initializer. \n\n" <<
          "rails generate quorum:install"
      end
    end
107108
def init
      File.exist?(EXCLUDE_FILE) ? @logger.info('skip: creation excludes.d') : create_exclude_config
      Dir.exist?(ROLE_DIR) ? @logger.info('skip: creation roles.d') : create_roles_dir
      Dir.exist?(USER_DIR) ? @logger.info('skip: creation users.d') : create_users_dir
    end
248094
def create_directory(directory):
    
    try:
        os.makedirs(directory)
    except OSError, e:
        if e.errno == errno.EEXIST and os.path.isdir(directory):
            pass

    return directory
1201596
def salt_ssh_create_dirs(self):
        
        logger.debug('Creating salt-ssh dirs into: %s', self.settings_dir)
        utils.create_dir(os.path.join(self.settings_dir, 'salt'))
        utils.create_dir(os.path.join(self.settings_dir, 'pillar'))
        utils.create_dir(os.path.join(self.settings_dir, 'etc', 'salt'))
        utils.create_dir(os.path.join(self.settings_dir, 'var', 'cache', 'salt'))
        utils.create_dir(os.path.join(self.settings_dir, 'var', 'log', 'salt'))
1250143
def makedirs_perm(path, perm=None):
    
    if not os.path.exists(path):
        if perm is None:
            os.makedirs(path)
        else:
            umask = os.umask(0)
            try:
                os.makedirs(path, perm)
            finally:
                os.umask(umask)
421303
def _set_users(self, node):
        '''
        
        '''
        # Get real local users with the local passwords
        shadow = {}
        with salt.utils.files.fopen('/etc/shadow') as rfh:
            for sh_line in rfh.read().split(os.linesep):
                if sh_line.strip():
                    login, pwd = sh_line.split(":")[:2]
                    if pwd and pwd[0] not in '!*':
                        shadow[login] = {'p': pwd}

        with salt.utils.files.fopen('/etc/passwd') as rfh:
            for ps_line in rfh.read().split(os.linesep):
                if ps_line.strip():
                    ps_line = ps_line.strip().split(':')
                    if ps_line[0] in shadow:
                        shadow[ps_line[0]]['h'] = ps_line[5]
                        shadow[ps_line[0]]['s'] = ps_line[6]
                        shadow[ps_line[0]]['g'] = self._get_user_groups(ps_line[0])

        users_groups = []
        users_node = etree.SubElement(node, 'users')
        for u_name, u_data in shadow.items():
            user_node = etree.SubElement(users_node, 'user')
            user_node.set('password', u_data['p'])
            user_node.set('home', u_data['h'])
            user_node.set('name', u_name)
            users_groups.extend(u_data['g'])
        users_node.set('group', ','.join(users_groups))

        return users_node
521129
def _makeBaseDir(basedir, quiet):
    
    if os.path.exists(basedir):
        if not quiet:
            print("updating existing installation")
        return

    if not quiet:
        print("mkdir", basedir)

    try:
        os.mkdir(basedir)
    except OSError as exception:
        raise CreateWorkerError("error creating directory {0}: {1}".format(
                                basedir, exception.strerror))
257459
def _make_dir(self, client_kwargs):
        
        with _handle_oss_error():
            bucket = self._get_bucket(client_kwargs)

            # Object
            if 'key' in client_kwargs:
                return bucket.put_object(
                    key=client_kwargs['key'], data=b'')

            # Bucket
            return bucket.create_bucket()
514112
def cli(ctx, group, user):
    
    return ctx.gi.users.add_to_group(group, user)
446411
def _setup_user_dir(self):
        """"""
        user_dir = self._get_user_dir_path()

        rules_dir = user_dir.joinpath('rules')
        if not rules_dir.is_dir():
            rules_dir.mkdir(parents=True)
        self.user_dir = user_dir
319568
def _mkdirs(d):
    
    try:
        os.makedirs(d)
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise
255403
def makedirs(directory):
    
    parent = os.path.dirname(os.path.abspath(directory))
    if not os.path.exists(parent):
        makedirs(parent)
    os.mkdir(directory)
231648
def _mkdir_for_config(cfg_file=cfg_file):
    
    dirname, filename = os.path.split(cfg_file)
    try:
        os.makedirs(dirname)
    except OSError as exc:
        if exc.errno == errno.EEXIST and os.path.isdir(dirname):
            pass
        else:
            raise
487272
def makedirs(name, mode=0o777, exist_ok=False):
    
    try:
        os.makedirs(name, mode)
    except OSError:
        if not os.path.isdir(name) or not exist_ok:
            raise
618247
def set_user_dir(self):
        
        is_checked = self.custom_UseUserDirectory_checkbox.isChecked()
        if is_checked:
            # Show previous templates dir
            path = setting(
                key='defaultUserDirectory',
                default='',
                expected_type=str,
                qsettings=self.settings)
        else:
            # Set the template report dir to ''
            path = temp_dir('impacts')

        self.leUserDirectoryPath.setText(path)
        self.splitter_user_directory.setEnabled(is_checked)
1358504
def SetConfiguredUsers(self, users):
    
    prefix = self.logger.name + '-'
    with tempfile.NamedTemporaryFile(
        mode='w', prefix=prefix, delete=True) as updated_users:
      updated_users_file = updated_users.name
      for user in users:
        updated_users.write(user + '\n')
      updated_users.flush()
      if not os.path.exists(self.google_users_dir):
        os.makedirs(self.google_users_dir)
      shutil.copy(updated_users_file, self.google_users_file)

    file_utils.SetPermissions(self.google_users_file, mode=0o600, uid=0, gid=0)