本文整理汇总了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)
示例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
示例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)
示例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
示例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,
)
示例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))
示例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)
示例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())
示例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)
示例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)
示例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)
示例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
示例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
示例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")
示例15: test_fchmod
# 需要导入模块: import os [as 别名]
# 或者: from os import fchmod [as 别名]
def test_fchmod(self):
self.check(os.fchmod, 0)