当前位置: 首页>>代码示例>>Python>>正文


Python stat.ST_UID属性代码示例

本文整理汇总了Python中stat.ST_UID属性的典型用法代码示例。如果您正苦于以下问题:Python stat.ST_UID属性的具体用法?Python stat.ST_UID怎么用?Python stat.ST_UID使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在stat的用法示例。


在下文中一共展示了stat.ST_UID属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _check_cert

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_UID [as 别名]
def _check_cert(filename):
    """
    Does this certificate file look okay?

    Returns error message, or None if okay
    """
    try:
        st = os.stat(filename)
    except OSError:
        return filename + " doesn't exist"
    else:
        good_perm = stat.S_IFREG | stat.S_IRUSR # | stat.S_IWUSR
        if (st[stat.ST_UID], st[stat.ST_GID]) != (0,0):
            return 'not owned by root.root'
        perm = st[stat.ST_MODE]
        if good_perm != perm:
            return "expected permissions %o but found %o." % (good_perm, perm) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:19,代码来源:panel.py

示例2: writable_by

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_UID [as 别名]
def writable_by(dirname, name, user_or_group):
    """ Checks if the given directory is writable by the named user or group.
        user_or_group is a boolean with True for a user and False for a group. """
    try:
        pwnam = pwd.getpwnam(name)
    except KeyError:
        print('[ERROR] User or group {0} does not exist!'.format(name))
        return False
    ugid = pwnam.pw_uid if user_or_group else pwnam.pw_gid

    dir_stat = os.stat(dirname)
    ug_stat = dir_stat[stat.ST_UID] if user_or_group else dir_stat[stat.ST_GID]
    iw_stat = stat.S_IWUSR if user_or_group else stat.S_IWGRP

    if ((ug_stat == ugid) and (dir_stat[stat.ST_MODE] & iw_stat)):
        return True

    return False 
开发者ID:PhotoBackup,项目名称:server-bottle,代码行数:20,代码来源:init.py

示例3: file

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_UID [as 别名]
def file(self, file):
        """Process a single file."""
        dst = re.sub(self.src, self.dst, file)
        if self.verbose:
            print "cp <%s> <%s>" % (file, dst)
        if not self.dryrun:
            try:
                # Copy file contents from snapshot to destination.
                shutil.copyfile(file, dst)
                # Copy the permissions and accessed/modified times.
                shutil.copystat(file, dst)
                # Copy the owner/group values to destination.
                stats = os.lstat(file)
                chown(dst, stats[stat.ST_UID], stats[stat.ST_GID])
            except IOError, e:
                print "ERROR '{}' processing file {}".format(e, file) 
开发者ID:nlfiedler,项目名称:timedog,代码行数:18,代码来源:timecopy.py

示例4: get_file_info

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_UID [as 别名]
def get_file_info(system, path, verbose=False):
    fullpath = get_fullpath(system, path)
    if fullpath == IO_ERROR:
        return IO_ERROR
    
    result = {}    
    if system.startswith('/'): # local or sub
        if can_read(system, path):
            # TODO platform-specific
            stats = os.stat(fullpath)
            stm = stats.st_mode
            result['type'] = get_file_type_char(stat.S_IFMT(stm))
            result['permissions'] = '%o' % (stat.S_IMODE(stm))
            result['UID'] = stats[stat.ST_UID]
            result['GID'] = stats[stat.ST_GID]
            result['ATIME'] = stats[stat.ST_ATIME]
            result['MTIME'] = stats[stat.ST_MTIME]
            result['CTIME'] = stats[stat.ST_CTIME] # actually mtime on UNIX, TODO
        else:
            if verbose:
                log.info('File \'%s\' is not accessible.' % (fullpath))
            result['type'] = None
            result['permissions'] =  None
            result['UID'] = None
            result['GID'] = None
            result['ATIME'] = None
            result['MTIME'] = None
            result['CTIME'] = None
        return result

    else: # SSH/FTP/TFTP/HTTP
        # TODO NOT IMPLEMENTED
        return IO_ERROR 
开发者ID:lightfaith,项目名称:locasploit,代码行数:35,代码来源:io.py

示例5: dir

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_UID [as 别名]
def dir(self, dir):
        """Create destination directory, copying stats and ownership."""
        dst = re.sub(self.src, self.dst, dir)
        if self.verbose:
            print "mkdir <%s>" % dst
        if not self.dryrun:
            os.mkdir(dst)
            shutil.copystat(dir, dst)
            stats = os.lstat(dir)
            chown(dst, stats[stat.ST_UID], stats[stat.ST_GID])
        if not self.dryrun or self.extattr:
            copyxattr(dir, dst)
        # Continue traversal...
        visitfiles(dir, self) 
开发者ID:nlfiedler,项目名称:timedog,代码行数:16,代码来源:timecopy.py

示例6: link

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_UID [as 别名]
def link(self, link):
        """Copy link to destination."""
        lnk = os.readlink(link)
        dst = re.sub(self.src, self.dst, link)
        if self.verbose:
            print "ln -s <%s> <%s>" % (lnk, dst)
        if not self.dryrun:
            os.symlink(lnk, dst)
            stats = os.lstat(link)
            chown(dst, stats[stat.ST_UID], stats[stat.ST_GID])
        if not self.dryrun or self.extattr:
            copyxattr(link, dst) 
开发者ID:nlfiedler,项目名称:timedog,代码行数:14,代码来源:timecopy.py

示例7: __getitem__

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_UID [as 别名]
def __getitem__(self, item):
        if item == stat.ST_UID:
            return self.uid
        if item == stat.ST_GID:
            return self.gid
        return self.sb.__getitem__(item) 
开发者ID:sassoftware,项目名称:conary,代码行数:8,代码来源:sourcetest.py

示例8: calc_mode

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_UID [as 别名]
def calc_mode(
        sticky=False,
        isuid=True,
        isgid=True,
        type=stat.S_IFREG,
        owner_read=True,
        owner_write=True,
        owner_exec=True,
        group_read=True,
        group_write=True,
        group_exec=True,
        other_read=True,
        other_write=True,
        other_exec=True,
):
    """helper function to calculate the mode bits of a file."""
    mode = 0
    if owner_read:
        mode |= stat.S_IRUSR
    if owner_write:
        mode |= stat.S_IWUSR
    if owner_exec:
        mode |= stat.S_IXUSR
    if group_read:
        mode |= stat.S_IRGRP
    if group_write:
        mode |= stat.S_IWGRP
    if group_exec:
        mode |= stat.S_IXGRP
    if other_read:
        mode |= stat.S_IROTH
    if other_write:
        mode |= stat.S_IWOTH
    if other_exec:
        mode |= stat.S_IXOTH
    if sticky:
        mode |= stat.S_ISVTX
    if isuid:
        mode |= stat.ST_UID
    if isgid:
        mode |= stat.ST_GID
    mode |= type
    return mode 
开发者ID:ywangd,项目名称:stash,代码行数:45,代码来源:base.py


注:本文中的stat.ST_UID属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。