本文整理汇总了Python中shutil.chown函数的典型用法代码示例。如果您正苦于以下问题:Python chown函数的具体用法?Python chown怎么用?Python chown使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了chown函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: add_directory
def add_directory():
add_group()
if not os.path.isdir(WEBPLEASE_PATH):
os.mkdir(WEBPLEASE_PATH)
shutil.chown(WEBPLEASE_PATH, user=WEBPLEASE_OWNER, group=WEBPLEASE_GROUP)
os.chmod(WEBPLEASE_PATH, mode=(stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
| stat.S_IRGRP | stat.S_IXGRP | stat.S_ISVTX))
开发者ID:dubov94,项目名称:please,代码行数:7,代码来源:linux_user.py
示例2: upgrade_charm
def upgrade_charm():
apt_install(filter_installed_packages(determine_packages()),
fatal=True)
# NOTE: ensure psutil install for hugepages configuration
status_set('maintenance', 'Installing apt packages')
apt_install(filter_installed_packages(['python-psutil']))
packages_removed = remove_old_packages()
if packages_removed and not is_unit_paused_set():
log("Package purge detected, restarting services", "INFO")
for s in services():
service_restart(s)
for r_id in relation_ids('amqp'):
amqp_joined(relation_id=r_id)
if is_relation_made('nrpe-external-master'):
update_nrpe_config()
# Fix previously wrongly created path permissions
# LP: https://bugs.launchpad.net/charm-cinder-ceph/+bug/1779676
asok_path = '/var/run/ceph/'
gid = grp.getgrnam("kvm").gr_gid
if gid and os.path.isdir(asok_path) and gid != os.stat(asok_path).st_gid:
log("{} not owned by group 'kvm', fixing permissions."
.format(asok_path))
shutil.chown(asok_path, group='kvm')
开发者ID:openstack,项目名称:charm-nova-compute,代码行数:26,代码来源:nova_compute_hooks.py
示例3: __init__
def __init__(self, logger, config):
self.logger = logger
self.config = config
self._shutdown = threading.Event()
config.event_manager = EventManager(logger, config)
sm = SensorManager(logger, config)
sm.start()
self.threads.append(sm)
#dbweb = DispatchBuddyWebUI(logger, config)
#th = threading.Thread(target=dbweb.run_app, name='DB WebUI')
#th.start()
#self.threads.append((th,dbweb))
for p in ('/var/db/DispatchBuddy',
'/var/db/DispatchBuddy/celery.results',
'/var/db/DispatchBuddy/evdata',
'/var/db/DispatchBuddy/pcap',
'/var/db/DispatchBuddy/tmp',
):
try:
os.stat(p)
except FileNotFoundError:
os.mkdir(p, 0o700)
shutil.chown(p,
user=config.get('main', 'run as user'),
group=config.get('main', 'run as group')
)
except:
traceback.print_exc()
开发者ID:Blue-Labs,项目名称:DispatchBuddy,代码行数:33,代码来源:dispatchbuddy.py
示例4: set_mode
def set_mode(path, mode):
if mode is None:
# Keep mode unchanged
return
if (mode.perms_s or mode.owner or mode.group) is None:
# Nothing to set
return
# No chown() on Windows, and must set one of owner/group
if not is_windows() and (mode.owner or mode.group) is not None:
try:
shutil.chown(path, mode.owner, mode.group)
except PermissionError as e:
msg = '{!r}: Unable to set owner {!r} and group {!r}: {}, ignoring...'
print(msg.format(path, mode.owner, mode.group, e.strerror))
except LookupError:
msg = '{!r}: Non-existent owner {!r} or group {!r}: ignoring...'
print(msg.format(path, mode.owner, mode.group))
except OSError as e:
if e.errno == errno.EINVAL:
msg = '{!r}: Non-existent numeric owner {!r} or group {!r}: ignoring...'
print(msg.format(path, mode.owner, mode.group))
else:
raise
# Must set permissions *after* setting owner/group otherwise the
# setuid/setgid bits will get wiped by chmod
# NOTE: On Windows you can set read/write perms; the rest are ignored
if mode.perms_s is not None:
try:
os.chmod(path, mode.perms)
except PermissionError as e:
msg = '{!r}: Unable to set permissions {!r}: {}, ignoring...'
print(msg.format(path, mode.perms_s, e.strerror))
开发者ID:centricular,项目名称:meson,代码行数:32,代码来源:meson_install.py
示例5: chown_dir
def chown_dir(directory, username):
"""Set owner and group of directory to username."""
shutil.chown(directory, username, username)
for root, dirs, files in os.walk(directory):
for child in dirs + files:
shutil.chown(os.path.join(root, child), username, username)
logger.info("{} chown'd to {}".format(directory, username))
开发者ID:data-8,项目名称:DS8-Interact,代码行数:7,代码来源:util.py
示例6: handle_manual
def handle_manual(torrent):
auto_processed = False
def handle_media(path, move):
nonlocal auto_processed
guess = guessit.guessit(path)
if guess['type'] == 'episode':
move_episode(path, guess, move)
auto_processed = True
elif guess['type'] == 'movie':
move_movie(path, guess, move)
auto_processed = True
part_regex = re.compile('.*part(\d+).rar', re.IGNORECASE)
for index, file in torrent.files().items():
file_path = os.path.join(torrent.downloadDir, file['name'])
if check_extension(file_path) and 'sample' not in file_path.lower():
# Log and ignore mkv files of less than ~92MiB
try:
if os.path.getsize(file_path) >= 96811278:
handle_media(file_path, False)
else:
syslog.syslog(
syslog.LOG_ERR, 'Detected false media file, skipping'
)
except FileNotFoundError:
syslog.syslog(syslog.LOG_ERR, 'Torrent file missing, skipping')
elif file_path.endswith('rar'):
# Ignore parts beyond the first in a rar series
match = part_regex.match(file_path)
if match and int(match.group(1)) > 1:
continue
with tempfile.TemporaryDirectory() as temp_dir:
paths = extract(file_path, temp_dir)
if paths:
for path in paths:
shutil.chown(path, group=plex_group)
os.chmod(path, 0o664)
handle_media(path, True)
if auto_processed:
pb_notify(
textwrap.dedent(
'''
Manually added torrent {0} finished downloading
and was auto-processed
'''.format(torrent.name)
).strip()
)
else:
pb_notify(
'Manually added torrent {0} finished downloading'.format(
torrent.name
)
)
开发者ID:hborawski,项目名称:axel,代码行数:60,代码来源:core.py
示例7: post
def post():
username = request.forms.get('username')
pubkey = request.forms.get('pubkey')
authorized_keys = "/etc/ssh/authorized_keys/" + username
print(username)
# TODO: Actual input validation and error handling
if len(username) < 2:
return "Username must be at least two characters long."
if not len(pubkey):
return "You should really include a public key."
if username == "root":
return "Nice try."
useradd = run(["useradd", "--shell", shell, "-g", groupname,
"-d", home, username])
if useradd.returncode == 9:
return HTTPResponse(status=409,
body="Sorry, but that user already exists.")
with open(authorized_keys, 'a+') as f:
f.write(pubkey)
chown(authorized_keys, username, groupname)
chmod(authorized_keys, 0o600)
return "Registered " + username
开发者ID:nivekuil,项目名称:conf.host,代码行数:28,代码来源:reception.py
示例8: save_data
def save_data(self, data):
# Age data
if hasattr(data, '__len__') and len(data) > self.GROOM_THRESHOLD:
for i, e in enumerate(data):
data[i] = ZEntry(e.path, int(e.rank * self.GROOM_LEVEL), e.time)
# Use a temporary file to minimize time the file is open and minimize clobbering
# Use delete=False so the file can be closed without removing it. On Windows
# you can not copy an open file.
from tempfile import NamedTemporaryFile
with NamedTemporaryFile('wt', encoding=sys.getfilesystemencoding(),
delete=False) as f:
for e in data:
f.write("{}|{}|{}\n".format(e.path, int(e.rank), int(e.time.timestamp())))
f.flush()
if self.Z_OWNER:
shutil.chown(f.name, user=self.Z_OWNER)
# On POSIX, rename() is atomic and will clobber
# On Windows, neither of these is true, so remove first.
from xonsh.platform import ON_WINDOWS
if ON_WINDOWS and os.path.exists(self.Z_DATA):
os.remove(self.Z_DATA)
shutil.copy(f.name, self.Z_DATA)
os.remove(f.name)
开发者ID:astronouth7303,项目名称:xontrib-z,代码行数:26,代码来源:z.py
示例9: add_user
def add_user(username, home_base='/home', clean_user=True):
user_folder=home_base+"/"+username
try:
user_check=pwd.getpwnam(username)
if clean_user==True:
return False
else:
return True
except KeyError:
if not os.path.isdir(home_base):
os.mkdir(home_base, 0o755)
if not os.path.isdir(user_folder):
os.mkdir(user_folder, 0o755)
if subprocess.call("sudo useradd -M -d "+user_folder+" -s /usr/sbin/nologin "+username, shell=True) > 0:
return False
else:
shutil.chown(user_folder, username, username)
return True
开发者ID:chorizon,项目名称:virus,代码行数:28,代码来源:basic.py
示例10: merge_overlay
def merge_overlay(self,path,overlay_path):
for f in os.listdir(overlay_path):
original_file = os.path.join(path,f)
final_file = os.path.join(overlay_path,f)
status = os.lstat(final_file)
# if it is a character device with 0 as major number, the original file/folder must be deleted
if (stat.S_ISCHR(status.st_mode) is True) and (os.major(status.st_rdev) == 0):
self.full_delete(original_file)
continue
# if it is a newly created file or folder, we just move it. That way it is faster and everything is preserved
if os.path.exists(original_file) is False:
self.run_external_program('mv "{:s}" "{:s}"'.format(final_file,original_file), False)
continue
ostatus = os.lstat(original_file)
# if it is a file, just copy it and overwrite
if (stat.S_ISDIR(status.st_mode) is False):
self.full_delete(original_file)
self.run_external_program('cp -a "{:s}" "{:s}"'.format(final_file,original_file), False)
continue
# if the new element is a folder, but the old is a file, delete the file and move the folder
if (stat.S_ISDIR(ostatus.st_mode) is False):
self.full_delete(original_file)
self.run_external_program('mv "{:s}" "{:s}"'.format(final_file,original_file), False)
continue
# if we reach here, both elements are folders, so let's check them recursively
shutil.copystat(final_file,original_file) # set permission bits
if (status.st_uid != ostatus.st_uid) or (status.st_gid != ostatus.st_gid):
shutil.chown(original_file,status.st_uid,status.st_gid)
self.merge_overlay(original_file,final_file)
开发者ID:rastersoft,项目名称:multipackager,代码行数:35,代码来源:package_base.py
示例11: _create_conf_dir
def _create_conf_dir(username):
conf_dir = '/home/{}/.openvpn_tunneler'.format(username)
# Use the following mode: u=rwx, g=rx, o-rwx
mode = stat.S_IRWXU | stat.S_IRGRP + stat.S_IXGRP | 00
if not os.path.exists(conf_dir):
os.mkdir(conf_dir, mode)
shutil.chown(conf_dir, user=username, group=username)
开发者ID:napperley,项目名称:OpenVPN_Tunneler,代码行数:8,代码来源:connections_model.py
示例12: create
def create(self, *args, **kwargs):
""" create the virtualenv if it doesn't exist """
if not os.path.exists(self.venv_path):
os.makedirs(self.venv_path, mode=0o755, exist_ok=True)
shutil.chown(self.venv_path, self.usr, self.usr)
return subprocess.call(self.init_cmd)
else:
return 0
开发者ID:bmoar,项目名称:lxc_dyn,代码行数:8,代码来源:lxc_dyn.py
示例13: makedirs
def makedirs(path, mode=0o750, user='root', group='root'):
if os.path.exists(path):
assert os.path.isdir(path), '{} is not a directory'
else:
# Don't specify mode here, to ensure parent dirs are traversable.
os.makedirs(path)
shutil.chown(path, user, group)
os.chmod(path, mode)
开发者ID:stub42,项目名称:postgresql-charm,代码行数:8,代码来源:helpers.py
示例14: fixperms
def fixperms(dirpath, user=None, group=None, umask=22):
for dirpath, dirnames, filenames in os.walk(dirpath):
shutil.chown(dirpath, user, group)
os.chmod(dirpath, 0o777 - umask)
for filename in filenames:
filepath = join(dirpath, filename)
shutil.chown(filepath, user, group)
os.chmod(filepath, 0o666 - umask)
开发者ID:ados1991,项目名称:botwitter,代码行数:8,代码来源:sudo.py
示例15: create_folder
def create_folder(folder):
if not os.path.isdir(folder):
os.makedirs(folder, mode=0o770)
os.chdir(folder)
os.system('git init --bare --shared')
for root, dirs, files in os.walk(folder):
for entry in files + dirs:
shutil.chown(os.path.join(root, entry), group=DAEMONCGI_GROUP)
开发者ID:Submitty,项目名称:Submitty,代码行数:8,代码来源:generate_repos.py
示例16: run
def run(self, distro, image):
# from now on we always cleanup ourselves after finishing
signal.signal(signal.SIGINT, sig_handler)
setup_device(image)
wipe_device()
self.create_partitions()
self.mount_partitions()
d = next(d for d in self.DISTROS if d.name == distro)
# set rootfs location and start installing
d.rootfs = self.part_mount['root']
log.info('Updating distro database')
d.update_database()
log.info('Bootstrap distro \'{}\''.format(d.long_name))
d.bootstrap()
log.info('Mounting kernel partitions')
self.mount_kernel_partitions()
log.info('Bootstrap distro (phase 2) \'{}\''.format(d.long_name))
d.bootstrap_phase2()
log.info('Setting up locale')
d.setup_locale()
log.info('Installing bootloader')
d.install_bootloader()
log.info('Installing kernel')
d.install_kernel()
log.info('Customizing image')
d.customize_image()
log.info('Setting up network')
d.setup_network()
# finish installation
log.info('Finishing installation')
os.sync()
uid = os.getenv('SUDO_UID', '')
guid = os.getenv('SUDO_GUID', '')
if os.path.isfile(image) and uid != '':
uid = int(uid)
if guid == '':
guid = None
else:
guid = int(guid)
shutil.chown(image, uid, guid)
return 0
开发者ID:zidane1980slab,项目名称:toolbox,代码行数:57,代码来源:main.py
示例17: copy_client_configs_to_home
def copy_client_configs_to_home(clients):
for client in clients:
source = "/etc/openvpn/{}/download-configs/{}.ovpn".format(SERVERNAME,
client)
dest = "/home/ubuntu/{}.ovpn".format(client)
shutil.copy(source, dest)
shutil.chown(dest, user="ubuntu", group="ubuntu")
os.chmod(dest,
stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR)
开发者ID:IBCNServices,项目名称:tengu-charms,代码行数:9,代码来源:openvpn.py
示例18: main
def main():
""" Falk service launch """
cmd = argparse.ArgumentParser(
description="Kevin CI Falk - VM provider")
cmd.add_argument("-c", "--config", default="/etc/kevin/falk.conf",
help="file name of the configuration to use.")
args = cmd.parse_args()
CFG.load(args.config)
try:
os.unlink(CFG.control_socket)
except OSError:
if os.path.exists(CFG.control_socket):
raise
else:
sockdir = os.path.dirname(CFG.control_socket)
if not os.path.exists(sockdir):
try:
print("creating socket directory '%s'" % sockdir)
os.makedirs(sockdir, exist_ok=True)
except PermissionError as exc:
raise exc from None
loop = asyncio.get_event_loop()
# state storage
falk = Falk()
print("listening on '%s'..." % CFG.control_socket)
proto = lambda: FalkProto(falk)
srv_coro = loop.create_unix_server(proto, CFG.control_socket)
server = loop.run_until_complete(srv_coro)
if CFG.control_socket_group:
# this only works if the current user is a member of the
# target group!
shutil.chown(CFG.control_socket, None, CFG.control_socket_group)
if CFG.control_socket_permissions:
mode = int(CFG.control_socket_permissions, 8)
os.chmod(CFG.control_socket, mode)
try:
loop.run_forever()
except KeyboardInterrupt:
print("exiting...")
pass
server.close()
loop.run_until_complete(server.wait_closed())
loop.close()
print("cya!")
开发者ID:a1exmac,项目名称:kevin,代码行数:57,代码来源:__main__.py
示例19: changeOwnerAndGrpToLoggedInUser
def changeOwnerAndGrpToLoggedInUser(directory, raiseEx=False):
loggedInUser = getLoggedInUser()
try:
shutil.chown(directory, loggedInUser, loggedInUser)
except Exception as e:
if raiseEx:
raise e
else:
pass
开发者ID:evernym,项目名称:plenum,代码行数:9,代码来源:setup-dev.py
示例20: up
def up(config):
jobs_dir = Path(config.submitty['submitty_data_dir'], 'daemon_job_queue')
os.makedirs(str(jobs_dir), exist_ok=True)
daemon_user = config.submitty_users['daemon_user']
daemonphp_group = config.submitty_users['daemonphp_group']
shutil.chown(str(jobs_dir), daemon_user, daemonphp_group)
# sticky bit is the leading 2.
# equivalent to u+rwx,g+rws,o-rwx
os.chmod(str(jobs_dir),0o2770)
pass
开发者ID:Submitty,项目名称:Submitty,代码行数:10,代码来源:20180712185718_daemon_handler_queue.py
注:本文中的shutil.chown函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论