From: Travis Rhoden Date: Fri, 22 May 2015 14:49:28 +0000 (-0400) Subject: [RM-11694] Add file mode option to write_file() X-Git-Tag: v1.5.25~4^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5368d9d14d3bfbef480d1302511121768d557d5e;p=ceph-deploy.git [RM-11694] Add file mode option to write_file() You an now pass a file mode to write_file with "mode=" and it will set the file mode that after writing the file. Signed-off-by: Travis Rhoden --- diff --git a/ceph_deploy/hosts/remotes.py b/ceph_deploy/hosts/remotes.py index 19be3e4..ba3e7d8 100644 --- a/ceph_deploy/hosts/remotes.py +++ b/ceph_deploy/hosts/remotes.py @@ -200,12 +200,12 @@ def write_monitor_keyring(keyring, monitor_keyring): write_file(keyring, monitor_keyring) -def write_file(path, content, directory=None): +def write_file(path, content, mode=0644, directory=None): if directory: if path.startswith("/"): path = path[1:] path = os.path.join(directory, path) - with file(path, 'w') as f: + with os.fdopen(os.open(path, os.O_WRONLY | os.O_CREAT, mode), 'w') as f: f.write(content)