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


Python os.fchmod方法代码示例

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


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

示例1: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import fchmod [as 别名]
def __init__(self, config, section):
        super(EncryptedOverlay, self).__init__(config, section)
        self.store_name = self.backing_store
        self.store = None
        self.protected_header = None

        if (not os.path.isfile(self.master_key)
                and self.autogen_master_key):
            # XXX https://github.com/latchset/jwcrypto/issues/50
            size = self.key_sizes.get(self.master_enctype, 512)
            key = JWK(generate='oct', size=size)
            with open(self.master_key, 'w') as f:
                os.fchmod(f.fileno(), 0o600)
                f.write(key.export())

        with open(self.master_key) as f:
            data = f.read()
            key = json_decode(data)
            self.mkey = JWK(**key) 
开发者ID:latchset,项目名称:custodia,代码行数:21,代码来源:encgen.py

示例2: client_command

# 需要导入模块: import os [as 别名]
# 或者: from os import fchmod [as 别名]
def client_command(self, handle, command):
        """Remotely called from uiconnection.py->Daemon.command."""
        if handle not in exchange.known_clients:
            LOG.e("Unknown client %s, can't execute %s" % (handle, command))
            # raise ValueError("Unknown client")
            return {'filename': '', 'result': b''}

        dfr = exchange.known_clients[handle].command(command)

        def send_result(result):
            """Callback for bashplex.py->DelimitedBashReceiver.command."""
            if len(result) < 65000:
                return {'filename': '', 'result': result}
            tmpf = tempfile.NamedTemporaryFile('wb', dir="/run/epoptes",
                                               delete=False)
            tmpf.write(result)
            os.fchmod(tmpf.file.fileno(), 0o660)
            return {'filename': tmpf.name, 'result': b''}

        dfr.addCallback(send_result)
        return dfr 
开发者ID:epoptes,项目名称:epoptes,代码行数:23,代码来源:guiplex.py

示例3: main

# 需要导入模块: import os [as 别名]
# 或者: from os import fchmod [as 别名]
def main():
    # Install the library.
    os.makedirs(os.path.join(INSTALL_PATH, 'lib'), exist_ok=True)

    with open(LIBRARY_PATH, 'wb') as fd:
        fd.write(gzip.decompress(base64.b85decode(ENCODED_LIB_CONTENTS)))
        os.fchmod(fd.fileno(), 0o755)

    # Install the wrapper script.
    os.makedirs(os.path.join(INSTALL_PATH, 'bin'), exist_ok=True)

    with open(SCRIPT_PATH, 'w') as fd:
        fd.write(DROPBOX_WRAPPER_CONTENTS)
        os.fchmod(fd.fileno(), 0o755)

    print("Installed the library and the wrapper script at:\n  %s\n  %s" % (LIBRARY_PATH, SCRIPT_PATH))
    print("(To uninstall, simply delete them.)")

    # Check that the correct 'dropbox' is in the $PATH.
    result = subprocess.check_output(['which', 'dropbox']).decode().rstrip()
    if result != SCRIPT_PATH:
        print()
        print("You will need to fix your $PATH! Currently, %r takes precedence." % result) 
开发者ID:dimaryaz,项目名称:dropbox_ext4,代码行数:25,代码来源:fix_dropbox.py

示例4: tmp_configuration_copy

# 需要导入模块: import os [as 别名]
# 或者: from os import fchmod [as 别名]
def tmp_configuration_copy(chmod=0o600):
    """
    Returns a path for a temporary file including a full copy of the configuration
    settings.
    :return: a path to a temporary file
    """
    cfg_dict = conf.as_dict(display_sensitive=True, raw=True)
    temp_fd, cfg_path = mkstemp()

    with os.fdopen(temp_fd, 'w') as temp_file:
        # Set the permissions before we write anything to it.
        if chmod is not None:
            os.fchmod(temp_fd, chmod)
        json.dump(cfg_dict, temp_file)

    return cfg_path 
开发者ID:apache,项目名称:airflow,代码行数:18,代码来源:configuration.py

示例5: make_app

# 需要导入模块: import os [as 别名]
# 或者: from os import fchmod [as 别名]
def make_app(self):
        icon_path = ICON_PATH / "travel-white.svg"
        script_path = os.path.expanduser("~/.local/bin/traffic_gui.sh")

        with open(script_path, "w") as fh:
            fh.write(self.linux_script.format(python_exe=sys.executable))
            mode = os.fstat(fh.fileno()).st_mode
            mode |= 0o111
            os.fchmod(fh.fileno(), mode & 0o7777)

        with open("traffic.desktop", "w") as fh:
            fh.write(
                self.linux_desktop.format(
                    icon_path=icon_path, script_path=script_path
                )
            )
            mode = os.fstat(fh.fileno()).st_mode
            mode |= 0o111
            os.fchmod(fh.fileno(), mode & 0o7777)

        subprocess.call(
            "desktop-file-install --dir ~/.local/share/applications "
            "traffic.desktop --rebuild-mime-info-cache",
            shell=True,
        ) 
开发者ID:xoolive,项目名称:traffic,代码行数:27,代码来源:gui_button.py

示例6: server_bind

# 需要导入模块: import os [as 别名]
# 或者: from os import fchmod [as 别名]
def server_bind(self):
        """Called by constructor to bind the socket.

        May be overridden.

        """
        if self.allow_reuse_address:
            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.socket.setblocking(True)

        if not self.listen_fd:
            self.socket.bind(self.server_address)

        self.server_address = self.socket.getsockname()

        if self.server_address[0] == 0:
            self.server_address = '@' + self.server_address[1:].decode('utf-8')
            if self.mode:
                os.fchmod(self.socket.fileno(), mode=int(self.mode, 8))
        elif self.mode:
            os.chmod(self.server_address, mode=int(self.mode, 8)) 
开发者ID:varlink,项目名称:python,代码行数:23,代码来源:server.py

示例7: generate

# 需要导入模块: import os [as 别名]
# 或者: from os import fchmod [as 别名]
def generate(self, dest, config):
        plugins = {
            plugin.__name__: plugin for plugin in self.inventory_plugins}
        plugin = plugins[config.get('plugin')]

        inventory_json = plugin(config.get('args', {}))

        script_content = self.template.format(
            config=repr(config),
            plugin_path=plugin.__module__,
            json_content=inventory_json
        )
        script_dest = "%s/%s-%s.sh" % (dest, self.cluster_name, uuid.uuid4())

        with open(script_dest, 'w+') as f:
            f.write(script_content)
            os.fchmod(f.fileno(), 0o500) 
开发者ID:adobe,项目名称:ops-cli,代码行数:19,代码来源:generator.py

示例8: handle_begin_put

# 需要导入模块: import os [as 别名]
# 或者: from os import fchmod [as 别名]
def handle_begin_put(req_id, path, mode):
    prev_umask = os.umask(0o077)
    try:
        if path is None:
            f = tempfile.NamedTemporaryFile(delete=False)
            path = wpath = f.name
        else:
            path = force_str(path)
            if os.path.isdir(path):
                raise IOError('%s is a directory' % path)
            wpath = path + '~chopsticks-tmp'
            f = open(wpath, 'wb')
    finally:
        os.umask(prev_umask)
    os.fchmod(f.fileno(), mode)
    active_puts[req_id] = (f, wpath, path, sha1()) 
开发者ID:lordmauve,项目名称:chopsticks,代码行数:18,代码来源:bubble.py

示例9: flockExclusive

# 需要导入模块: import os [as 别名]
# 或者: from os import fchmod [as 别名]
def flockExclusive(self):
        """
        Block :py:func:`backup` from other profiles or users
        and run them serialized
        """
        if self.config.globalFlock():
            logger.debug('Set flock %s' %self.GLOBAL_FLOCK, self)
            self.flock = open(self.GLOBAL_FLOCK, 'w')
            fcntl.flock(self.flock, fcntl.LOCK_EX)
            #make it rw by all if that's not already done.
            perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | \
                    stat.S_IWGRP | stat.S_IROTH | stat.S_IWOTH
            s = os.fstat(self.flock.fileno())
            if not s.st_mode & perms == perms:
                logger.debug('Set flock permissions %s' %self.GLOBAL_FLOCK, self)
                os.fchmod(self.flock.fileno(), perms) 
开发者ID:bit-team,项目名称:backintime,代码行数:18,代码来源:snapshots.py

示例10: set_file_mode

# 需要导入模块: import os [as 别名]
# 或者: from os import fchmod [as 别名]
def set_file_mode(path, spec, fd=None):
    """
    Update the permissions of a file using the same syntax as chmod(1).
    """
    if isinstance(spec, int):
        new_mode = spec
    elif not mitogen.core.PY3 and isinstance(spec, long):
        new_mode = spec
    elif spec.isdigit():
        new_mode = int(spec, 8)
    else:
        mode = os.stat(path).st_mode
        new_mode = apply_mode_spec(spec, mode)

    if fd is not None and hasattr(os, 'fchmod'):
        os.fchmod(fd, new_mode)
    else:
        os.chmod(path, new_mode) 
开发者ID:dw,项目名称:mitogen,代码行数:20,代码来源:target.py

示例11: script_write

# 需要导入模块: import os [as 别名]
# 或者: from os import fchmod [as 别名]
def script_write(filename, script):
    """Write a script to a file.

    Proper execute permissions will be set.

    :param ``str`` filename:
        File to write to.
    :param ``iterable|unicode`` script:
        Unicode string or iterable.
    """
    if isinstance(script, six.string_types):
        # If the script is fully provided in a string, wrap it in a StringIO
        if hasattr(script, 'decode'):
            script = io.StringIO(script.decode())
        else:
            script = io.StringIO(script)

    def _chunks_write(f):
        for chunk in script:
            f.write(chunk)
        if os.name == 'posix':
            f.write('\n\n')
            os.fchmod(f.fileno(), 0o755)

    _write(filename, _chunks_write, mode='w', permission=0o755) 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:27,代码来源:_utils.py

示例12: write_data

# 需要导入模块: import os [as 别名]
# 或者: from os import fchmod [as 别名]
def write_data(fpath, data, modified, raise_err=True, tmp_dir=None):
    """Safely write data to file path.
    """
    tmp_dir = tmp_dir or os.path.dirname(fpath)
    with tempfile.NamedTemporaryFile(dir=tmp_dir,
                                     delete=False,
                                     prefix='.tmp') as temp:
        if data:
            temp.write(data)
        if os.name == 'posix':
            os.fchmod(temp.fileno(), 0o644)
    os.utime(temp.name, (modified, modified))
    try:
        os.rename(temp.name, fpath)
    except OSError:
        _LOGGER.error('Unable to rename: %s => %s', temp.name, fpath,
                      exc_info=True)
        if raise_err:
            raise 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:21,代码来源:utils.py

示例13: make_ezipfile

# 需要导入模块: import os [as 别名]
# 或者: from os import fchmod [as 别名]
def make_ezipfile(base_name, base_dir, verbose=0, dry_run=0, **kwargs):
    fname = archive_util.make_zipfile(base_name, base_dir, verbose, dry_run)
    ofname = fname+".old"
    os.rename(fname,ofname)
    of=open(ofname)
    f=open(fname,"w")
    f.write(EZIP_HEADER % base_dir)
    while True:
        data = of.read(8192)
        if not data:
            break
        f.write(data)
    f.close()
    os.system("zip -A '%s'" % fname)
    of.close()
    os.unlink(ofname)
    os.fchmod(fname,0o755)
    return fname 
开发者ID:phaethon,项目名称:kamene,代码行数:20,代码来源:setup.py

示例14: notify

# 需要导入模块: import os [as 别名]
# 或者: from os import fchmod [as 别名]
def notify(self):
        try:
            self.spinner = (self.spinner + 1) % 2
            os.fchmod(self._tmp.fileno(), self.spinner)
        except AttributeError:
            # python < 2.6
            self._tmp.truncate(0)
            os.write(self._tmp.fileno(), b"X") 
开发者ID:jpush,项目名称:jbox,代码行数:10,代码来源:workertmp.py

示例15: test_fchmod

# 需要导入模块: import os [as 别名]
# 或者: from os import fchmod [as 别名]
def test_fchmod(self):
        self.check(os.fchmod, 0) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_os.py


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