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

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

项目:AmqpCode 作者:SVADemoAPP 文件:spec010.py |项目代码 |文档代码

def testXid(self):
    sc = StringCodec()
    xid = Xid(format=0, global_id="gid", branch_id="bid")
    sc.write_compound(xid)
    assert sc.encoded == '\x00\x00\x00\x10\x06\x04\x07\x00\x00\x00\x00\x00\x03gid\x03bid'
    dec = sc.read_compound(Xid)
    assert xid.__dict__ == dec.__dict__
#   def testLoadReadOnly(self):
#     spec = "amqp.0-10-qpid-errata.xml"
#     f = testrunner.get_spec_file(spec)
#     dest = tempfile.mkdtemp()
#     shutil.copy(f, dest)
#     shutil.copy(os.path.join(os.path.dirname(f), "amqp.0-10.dtd"), dest)
#     os.chmod(dest, stat.S_IRUSR | stat.S_IXUSR)
#     fname = os.path.join(dest, spec)
#     load(fname)
#     assert not os.path.exists("%s.pcl" % fname)

项目:qpid-python 作者:apache 文件:spec010.py |项目代码 |文档代码

def testXid(self):
    sc = StringCodec()
    xid = Xid(format=0, global_id="gid", branch_id="bid")
    sc.write_compound(xid)
    assert sc.encoded == '\x00\x00\x00\x10\x06\x04\x07\x00\x00\x00\x00\x00\x03gid\x03bid'
    dec = sc.read_compound(Xid)
    assert xid.__dict__ == dec.__dict__
#   def testLoadReadOnly(self):
#     spec = "amqp.0-10-qpid-errata.xml"
#     f = testrunner.get_spec_file(spec)
#     dest = tempfile.mkdtemp()
#     shutil.copy(f, dest)
#     shutil.copy(os.path.join(os.path.dirname(f), "amqp.0-10.dtd"), dest)
#     os.chmod(dest, stat.S_IRUSR | stat.S_IXUSR)
#     fname = os.path.join(dest, spec)
#     load(fname)
#     assert not os.path.exists("%s.pcl" % fname)

项目:machammer 作者:filipp 文件:decorators.py |项目代码 |文档代码

def login(func):
    """Install Python function as a LoginHook."""
    def func_wrapper(hook='login'):
        path = '/var/root/Library/mh_%shook.py' % hook
        writesource(func, path)
        # only root should read and execute
        os.chown(path, 0, 0)
        os.chmod(path, stat.S_IXUSR | stat.S_IRUSR)
        if hook == 'login':
            hooks.login(path)
        else:
            hooks.logout(path)
        return path
    return func_wrapper

项目:kubeque 作者:broadinstitute 文件:main.py |项目代码 |文档代码

def _write_local_script(job_id, spec, kubeque_command, kubequeconsume_exe_path, kubeque_exe_in_container):
    from kubeque.gcp import _gcloud_cmd
    import stat
    image = spec['image']
    cmd = _gcloud_cmd(
        ["docker", "--", "run",
         "-v", os.path.expanduser("~/.config/gcloud") + ":/google-creds",
         "-e", "GOOGLE_APPLICATION_CREDENTIALS=/google-creds/application_default_credentials.json",
         "-v", kubequeconsume_exe_path + ":" + kubeque_exe_in_container,
         image, 'bash -c "' + kubeque_command + ' --owner localhost"', ])
    script_name = "run-{}-locally.sh".format(job_id)
    with open(script_name, "wt") as fd:
        fd.write("#!/usr/bin/env bash\n")
        fd.write(" ".join(cmd) + "\n")
    # make script executable
    os.chmod(script_name, os.stat(script_name).st_mode | stat.S_IXUSR)
    return script_name

项目:SCMReplication 作者:wgsyd 文件:SubversionToPerforce.py |项目代码 |文档代码

def p4_edit_file(self, file_path):
        file_abspath, file_p4fixed = file_path
        p4cfg = self.target
        p4 = p4cfg.p4
        p4.run_sync('-k', file_p4fixed)
        f_st = os.lstat(file_abspath)
        is_executable = f_st.st_mode & (stat.S_IXGRP | stat.S_IXUSR)
        is_symlink = os.path.islink(file_abspath)
        if is_symlink:
            output = p4.run_edit('-t', 'symlink', file_p4fixed)
        elif is_executable:
            output = p4.run_edit('-t', '+x', file_p4fixed)
        else:
            output = p4.run_edit('-t', 'auto', file_p4fixed)
        # If the initial 'add' change was lost
        # an edit on a missing file will report
        # an error 'not on client'
        if p4cfg.inWarnings('not on client'):
            msg = '%s not on client. Changing P4 Edit to P4 Add' % file_abspath
            self.logger.warning(msg)
            output = p4.run_add('-f', file_abspath)

项目:pefile.pypy 作者:cloudtracer 文件:test_import.py |项目代码 |文档代码

def test_execute_bit_not_copied(self):
        # Issue 6070: under posix .pyc files got their execute bit set if
        # the .py file had the execute bit set, but they aren't executable.
        oldmask = os.umask(022)
        sys.path.insert(0, os.curdir)
        try:
            fname = TESTFN + os.extsep + "py"
            f = open(fname, 'w').close()
            os.chmod(fname, (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH |
                             stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH))
            __import__(TESTFN)
            fn = fname + 'c'
            if not os.path.exists(fn):
                fn = fname + 'o'
                if not os.path.exists(fn):
                    self.fail("__import__ did not result in creation of "
                              "either a .pyc or .pyo file")
            s = os.stat(fn)
            self.assertEqual(stat.S_IMODE(s.st_mode),
                             stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
        finally:
            os.umask(oldmask)
            remove_files(TESTFN)
            unload(TESTFN)
            del sys.path[0]


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

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

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