Python stat 模块,S_IXUSR 实例代码(5)

电脑杂谈  发布时间:2019-08-14 20:01:38  来源:网络整理

项目:kinect-2-libras 作者:inessadl 文件:webbrowser.py |项目代码 |文档代码

def _isexecutable(cmd):
        if os.path.isfile(cmd):
            mode = os.stat(cmd)[stat.ST_MODE]
            if mode & stat.S_IXUSR or mode & stat.S_IXGRP or mode & stat.S_IXOTH:
                return True
        return False

项目:pyppeteer 作者:miyakogi 文件:chromium_downloader.py |项目代码 |文档代码

def extract_zip(data: bytes, path: Path) -> None:
    """Extract zipped data to path."""
    # On mac zipfile module cannot extract correctly, so use unzip instead.
    if curret_platform() == 'mac':
        import subprocess
        import shutil
        zip_path = path / 'chrome.zip'
        if not path.exists():
            path.mkdir(parents=True)
        with zip_path.open('wb') as f:
            f.write(data)
        if not shutil.which('unzip'):
            raise OSError('Failed to automatically extract chrome.zip.'
                          f'Please unzip {zip_path} manually.')
        subprocess.run(['unzip', str(zip_path)], cwd=str(path))
        if chromium_excutable().exists() and zip_path.exists():
            zip_path.unlink()
    else:
        with ZipFile(BytesIO(data)) as zf:
            zf.extractall(str(path))
    exec_path = chromium_excutable()
    if not exec_path.exists():
        raise IOError('Failed to extract chromium.')
    exec_path.chmod(exec_path.stat().st_mode | stat.S_IXOTH | stat.S_IXGRP |
                    stat.S_IXUSR)
    logger.warning(f'chromium extracted to: {path}')

项目:bob 作者:BobBuildTool 文件:test_utils.py |项目代码 |文档代码

def testPermission(self):
        with TemporaryDirectory() as tmp:
            d = os.path.join(tmp, "dir")
            os.mkdir(d)
            with open(os.path.join(d, "file"), "w") as f:
                f.write("data")
            os.chmod(d, stat.S_IRUSR | stat.S_IXUSR)
            self.assertRaises(BuildError, removePath, tmp)
            os.chmod(d, stat.S_IRWXU)

项目:bob 作者:BobBuildTool 文件:test_utils.py |项目代码 |文档代码

def testPermission(self):
        with TemporaryDirectory() as tmp:
            d = os.path.join(tmp, "dir")
            os.mkdir(d)
            with open(os.path.join(d, "file"), "w") as f:
                f.write("data")
            os.chmod(d, stat.S_IRUSR | stat.S_IXUSR)
            self.assertRaises(BuildError, emptyDirectory, tmp)
            os.chmod(d, stat.S_IRWXU)

项目:code 作者:ActiveState 文件:recipe-577848.py |项目代码 |文档代码

def set_executable(top):
    error_count=0
    def set_exec(name):
        mode = os.stat(name).st_mode
        new_mode = mode
        if new_mode & stat.S_IRUSR:
            new_mode = new_mode | stat.S_IXUSR
        if new_mode & stat.S_IRGRP:
            new_mode = new_mode | stat.S_IXGRP
        if new_mode & stat.S_IROTH:
            new_mode = new_mode | stat.S_IXOTH
        if (mode != new_mode):
            print "Setting exec for '%s' (mode %o => %o)" % (name, mode, new_mode)
            os.chmod(name, new_mode)
    def unset_exec(name):
        mode = os.stat(name).st_mode
        new_mode = mode & ~(stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
        if (mode != new_mode):
            print "Unsetting exec for '%s' (mode %o => %o)" % (name, mode, new_mode)
            os.chmod(name, new_mode)
    for root, dirs, files in os.walk(top):
        for name in files:
            complete_name = os.path.join(root, name)
            if os.path.islink(complete_name): continue
            try: 
                f = open(complete_name, 'r')
                header = f.read(4)
                f.close()
                if header[0:2] == '#!' or header[1:4] == 'ELF':
                    set_exec(complete_name)
                else:
                    unset_exec(complete_name)
            except Exception as e:
                print "%s: %s" %  (complete_name, e.__str__())
                error_count += 1
        for name in dirs:
            complete_name = os.path.join(root, name)
            set_exec(complete_name)
    return error_count

项目:hostapd-mana 作者:adde88 文件:util.py |项目代码 |文档代码

def is_executable(file):
    if not os.path.exists(file):
        return False
    st = os.stat(file)
    return bool(st.st_mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH))

python s.sendmail_python s ixusr_python %s

项目:QuitStore 作者:AKSW 文件:test_core.py |项目代码 |文档代码

def testRepoGarbageCollectionTrigger(self):
        self.getrepowithcommit()
        import os
        import stat
        import time
        with TemporaryDirectory() as execDir:
            execFile = os.path.join(execDir, "git")
            checkFile = os.path.join(execDir, "check")
            with open(execFile, 'w') as execFilePointer:
                execFilePointer.write("""#!/bin/sh
                if [ "$1" = "gc" ] ; then
                    touch """ + checkFile + """
                fi
                """)
            os.chmod(execFile, stat.S_IXUSR | stat.S_IRUSR)
            # configure PATH for Popen to contain dummy git gc, which should be triggered
            os.environ['PATH'] = ':'.join([execDir, os.getenv('PATH')])
            repo = GitRepo(self.dir.name)
            repo.garbagecollection()
            start = time.time()
            # check if mocked git was executed
            while not os.path.isfile(checkFile):
                if (time.time() - start) > 1:
                    self.fail("Git garbage collection was not triggered")


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/shumachanpin/article-119245-5.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...