當前位置: 首頁>>代碼示例>>Python>>正文


Python stat.ST_MODE屬性代碼示例

本文整理匯總了Python中stat.ST_MODE屬性的典型用法代碼示例。如果您正苦於以下問題:Python stat.ST_MODE屬性的具體用法?Python stat.ST_MODE怎麽用?Python stat.ST_MODE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在stat的用法示例。


在下文中一共展示了stat.ST_MODE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __call__

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_MODE [as 別名]
def __call__(self, step):
        slavever = step.slaveVersion('stat')
        if not slavever:
            raise BuildSlaveTooOldError("slave is too old, does not know "
                                        "about stat")

        def commandComplete(cmd):
            if cmd.rc != 0:
                return False

            s = cmd.updates["stat"][-1]
            filemode = s[stat.ST_MODE]
            if stat.S_ISREG(filemode) or stat.S_ISLNK(filemode):
                # True only if this is a file or a link and not any other file
                # system object.
                return True
            else:
                return False

        cmd = LoggedRemoteCommand('stat', {'file': self.filename})
        d = step.runCommand(cmd)
        d.addCallback(lambda res: commandComplete(cmd))
        return d 
開發者ID:llvm,項目名稱:llvm-zorg,代碼行數:25,代碼來源:FileConditions.py

示例2: _check_cert

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_MODE [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

示例3: unpack_and_compile

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_MODE [as 別名]
def unpack_and_compile(self, egg_path, destination):
        to_compile = []
        to_chmod = []

        def pf(src, dst):
            if dst.endswith('.py') and not src.startswith('EGG-INFO/'):
                to_compile.append(dst)
            elif dst.endswith('.dll') or dst.endswith('.so'):
                to_chmod.append(dst)
            self.unpack_progress(src, dst)
            return not self.dry_run and dst or None

        unpack_archive(egg_path, destination, pf)
        self.byte_compile(to_compile)
        if not self.dry_run:
            for f in to_chmod:
                mode = ((os.stat(f)[stat.ST_MODE]) | 0o555) & 0o7755
                chmod(f, mode) 
開發者ID:jpush,項目名稱:jbox,代碼行數:20,代碼來源:easy_install.py

示例4: __init__

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_MODE [as 別名]
def __init__(self, devname=None):
        if devname is None:
            self.name = "/dev/urandom"
        else:
            self.name = devname

        # Test that /dev/urandom is a character special device
        f = open(self.name, "rb", 0)
        fmode = os.fstat(f.fileno())[stat.ST_MODE]
        if not stat.S_ISCHR(fmode):
            f.close()
            raise TypeError("%r is not a character special device" % (self.name,))

        self.__file = f

        BaseRNG.__init__(self) 
開發者ID:mortcanty,項目名稱:earthengine,代碼行數:18,代碼來源:posix.py

示例5: writefile

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_MODE [as 別名]
def writefile(cluster, indices, source, destination, timeout=DEFAULT_AGENT_TIMEOUT):
    try:
        with open(source) as f:
            source_data = f.read()
        perms = os.stat(source)[stat.ST_MODE]
    except IOError as err:
        raise PcoccError("unable to read source file for copy: {}".format(err))

    start_time = time.time()
    ret = AgentCommand.writefile(cluster, indices,
                                 path=destination, data=source_data,
                                 perms=perms, append=False, timeout=timeout)
    for k, e in ret.iterate():
        click.secho("vm{}: {}".format(k, e), fg='red', err=True)

    click.secho("{} VMs answered in {:.2f}s".format(
        len(indices), time.time() - start_time),
                fg='green', err=True)

    ret.raise_errors() 
開發者ID:cea-hpc,項目名稱:pcocc,代碼行數:22,代碼來源:cmd.py

示例6: copyFunc

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_MODE [as 別名]
def copyFunc(dest, source, env):
    """Install a source file or directory into a destination by copying,
    (including copying permission/mode bits)."""

    if os.path.isdir(source):
        if os.path.exists(dest):
            if not os.path.isdir(dest):
                raise SCons.Errors.UserError("cannot overwrite non-directory `%s' with a directory `%s'" % (str(dest), str(source)))
        else:
            parent = os.path.split(dest)[0]
            if not os.path.exists(parent):
                os.makedirs(parent)
        scons_copytree(source, dest)
    else:
        shutil.copy2(source, dest)
        st = os.stat(source)
        os.chmod(dest, stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)

    return 0

#
# Functions doing the actual work of the InstallVersionedLib Builder.
# 
開發者ID:Autodesk,項目名稱:arnold-usd,代碼行數:25,代碼來源:install.py

示例7: CacheRetrieveFunc

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_MODE [as 別名]
def CacheRetrieveFunc(target, source, env):
    t = target[0]
    fs = t.fs
    cd = env.get_CacheDir()
    cachedir, cachefile = cd.cachepath(t)
    if not fs.exists(cachefile):
        cd.CacheDebug('CacheRetrieve(%s):  %s not in cache\n', t, cachefile)
        return 1
    cd.CacheDebug('CacheRetrieve(%s):  retrieving from %s\n', t, cachefile)
    if SCons.Action.execute_actions:
        if fs.islink(cachefile):
            fs.symlink(fs.readlink(cachefile), t.get_internal_path())
        else:
            env.copy_from_cache(cachefile, t.get_internal_path())
            try:
                os.utime(cachefile, None)
            except OSError:
                pass
        st = fs.stat(cachefile)
        fs.chmod(t.get_internal_path(), stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
    return 0 
開發者ID:Autodesk,項目名稱:arnold-usd,代碼行數:23,代碼來源:CacheDir.py

示例8: unpack_and_compile

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_MODE [as 別名]
def unpack_and_compile(self, egg_path, destination):
        to_compile = []
        to_chmod = []

        def pf(src, dst):
            if dst.endswith('.py') and not src.startswith('EGG-INFO/'):
                to_compile.append(dst)
            elif dst.endswith('.dll') or dst.endswith('.so'):
                to_chmod.append(dst)
            self.unpack_progress(src,dst)
            return not self.dry_run and dst or None

        unpack_archive(egg_path, destination, pf)
        self.byte_compile(to_compile)
        if not self.dry_run:
            for f in to_chmod:
                mode = ((os.stat(f)[stat.ST_MODE]) | 0o555) & 0o7755
                chmod(f, mode) 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:20,代碼來源:easy_install.py

示例9: CacheRetrieveFunc

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_MODE [as 別名]
def CacheRetrieveFunc(target, source, env):
    t = target[0]
    fs = t.fs
    cd = env.get_CacheDir()
    cachedir, cachefile = cd.cachepath(t)
    if not fs.exists(cachefile):
        cd.CacheDebug('CacheRetrieve(%s):  %s not in cache\n', t, cachefile)
        return 1
    cd.CacheDebug('CacheRetrieve(%s):  retrieving from %s\n', t, cachefile)
    if SCons.Action.execute_actions:
        if fs.islink(cachefile):
            fs.symlink(fs.readlink(cachefile), t.get_internal_path())
        else:
            env.copy_from_cache(cachefile, t.get_internal_path())
        st = fs.stat(cachefile)
        fs.chmod(t.get_internal_path(), stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
    return 0 
開發者ID:bq,項目名稱:web2board,代碼行數:19,代碼來源:CacheDir.py

示例10: copyFunc

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_MODE [as 別名]
def copyFunc(dest, source, env):
    """Install a source file or directory into a destination by copying,
    (including copying permission/mode bits)."""

    if os.path.isdir(source):
        if os.path.exists(dest):
            if not os.path.isdir(dest):
                raise SCons.Errors.UserError("cannot overwrite non-directory `%s' with a directory `%s'" % (str(dest), str(source)))
        else:
            parent = os.path.split(dest)[0]
            if not os.path.exists(parent):
                os.makedirs(parent)
        shutil.copytree(source, dest)
    else:
        shutil.copy2(source, dest)
        st = os.stat(source)
        os.chmod(dest, stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)

    return 0 
開發者ID:coin3d,項目名稱:pivy,代碼行數:21,代碼來源:install.py

示例11: __init__

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_MODE [as 別名]
def __init__(self, name, directory, defaultMode=None):
        """
        Create a log file.

        @param name: name of the file
        @param directory: directory holding the file
        @param defaultMode: permissions used to create the file. Default to
        current permissions of the file if the file exists.
        """
        self.directory = directory
        self.name = name
        self.path = os.path.join(directory, name)
        if defaultMode is None and os.path.exists(self.path):
            self.defaultMode = stat.S_IMODE(os.stat(self.path)[stat.ST_MODE])
        else:
            self.defaultMode = defaultMode
        self._openFile() 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:19,代碼來源:logfile.py

示例12: getPermissionString

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_MODE [as 別名]
def getPermissionString(path):
        """ Get permissions string for a file's mode.
        Qt.py compatibility fix since QFileInfo.permissions isn't in PySide2.
        
        :Parameters:
            path : `str`
                File path
        :Returns:
            String corresponding to read (r), write (w), and execute (x) permissions for file.
        """
        mode = os.stat(path)[stat.ST_MODE]
        perms = "-"
        for who in "USR", "GRP", "OTH":
            for what in "R", "W", "X":
                if mode & getattr(stat, "S_I" + what + who):
                    perms += what.lower()
                else:
                    perms += "-"
        return perms 
開發者ID:dreamworksanimation,項目名稱:usdmanager,代碼行數:21,代碼來源:__init__.py

示例13: test_cache_failure_warns

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_MODE [as 別名]
def test_cache_failure_warns(self, testdir, monkeypatch):
        monkeypatch.setenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "1")
        cache_dir = str(testdir.tmpdir.ensure_dir(".pytest_cache"))
        mode = os.stat(cache_dir)[stat.ST_MODE]
        testdir.tmpdir.ensure_dir(".pytest_cache").chmod(0)
        try:
            testdir.makepyfile("def test_error(): raise Exception")
            result = testdir.runpytest()
            assert result.ret == 1
            # warnings from nodeids, lastfailed, and stepwise
            result.stdout.fnmatch_lines(
                [
                    # Validate location/stacklevel of warning from cacheprovider.
                    "*= warnings summary =*",
                    "*/cacheprovider.py:*",
                    "  */cacheprovider.py:*: PytestCacheWarning: could not create cache path "
                    "{}/v/cache/nodeids".format(cache_dir),
                    '    config.cache.set("cache/nodeids", sorted(self.cached_nodeids))',
                    "*1 failed, 3 warnings in*",
                ]
            )
        finally:
            testdir.tmpdir.ensure_dir(".pytest_cache").chmod(mode) 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:25,代碼來源:test_cacheprovider.py

示例14: check_and_process

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_MODE [as 別名]
def check_and_process(pathname, atftype, verbose=False):
    mode = os.stat(pathname)[ST_MODE]
    if S_ISREG(mode) and pathname.lower().endswith('.atf'):
        # It's a file, call the callback function
        if verbose:
            click.echo('Info: Parsing {0}.'.format(pathname))
        check_atf(pathname, atftype, verbose) 
開發者ID:oracc,項目名稱:pyoracc,代碼行數:9,代碼來源:cli.py

示例15: findall

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_MODE [as 別名]
def findall(dir = os.curdir):
    """Find all files under 'dir' and return the list of full filenames
    (relative to 'dir').
    """
    from stat import ST_MODE, S_ISREG, S_ISDIR, S_ISLNK

    list = []
    stack = [dir]
    pop = stack.pop
    push = stack.append

    while stack:
        dir = pop()
        names = os.listdir(dir)

        for name in names:
            if dir != os.curdir:        # avoid the dreaded "./" syndrome
                fullname = os.path.join(dir, name)
            else:
                fullname = name

            # Avoid excess stat calls -- just one will do, thank you!
            stat = os.stat(fullname)
            mode = stat[ST_MODE]
            if S_ISREG(mode):
                list.append(fullname)
            elif S_ISDIR(mode) and not S_ISLNK(mode):
                push(fullname)

    return list 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:32,代碼來源:filelist.py


注:本文中的stat.ST_MODE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。