當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。