Skip to content

Commit

Permalink
[RM-15016] Change syntax to be compatible with Python 3
Browse files Browse the repository at this point in the history
Signed-off-by: Oleh Prypin <oleh@pryp.in>
  • Loading branch information
oprypin committed May 23, 2016
1 parent 34d5c17 commit e2a60a3
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion ceph_deploy/admin.py
Expand Up @@ -37,7 +37,7 @@ def admin(args):
distro.conn.remote_module.write_file(
'/etc/ceph/%s.client.admin.keyring' % args.cluster,
keyring,
0600,
0o600,
)

distro.conn.exit()
Expand Down
2 changes: 1 addition & 1 deletion ceph_deploy/cli.py
Expand Up @@ -90,7 +90,7 @@ def get_parser():
for ep in pkg_resources.iter_entry_points('ceph_deploy.cli')
]
entry_points.sort(
key=lambda (name, fn): getattr(fn, 'priority', 100),
key=lambda name_fn: getattr(name_fn[1], 'priority', 100),
)
for (name, fn) in entry_points:
p = sub.add_parser(
Expand Down
2 changes: 1 addition & 1 deletion ceph_deploy/forgetkeys.py
Expand Up @@ -21,7 +21,7 @@ def forgetkeys(args):
cluster=args.cluster,
what=f,
))
except OSError, e:
except OSError as e:
if e.errno == errno.ENOENT:
pass
else:
Expand Down
2 changes: 1 addition & 1 deletion ceph_deploy/gatherkeys.py
Expand Up @@ -30,7 +30,7 @@ def fetch_file(args, frompath, topath, _hosts):


def gatherkeys(args):
oldmask = os.umask(077)
oldmask = os.umask(0o77)
try:
# client.admin
keyring = '/etc/ceph/{cluster}.client.admin.keyring'.format(
Expand Down
16 changes: 8 additions & 8 deletions ceph_deploy/hosts/remotes.py
Expand Up @@ -41,7 +41,7 @@ def machine_type():
return platform.machine()


def write_sources_list(url, codename, filename='ceph.list', mode=0644):
def write_sources_list(url, codename, filename='ceph.list', mode=0o644):
"""add deb repo to /etc/apt/sources.list.d/"""
repo_path = os.path.join('/etc/apt/sources.list.d', filename)
content = 'deb {url} {codename} main\n'.format(
Expand Down Expand Up @@ -112,12 +112,12 @@ def write_conf(cluster, conf, overwrite):
tmp_file.write(conf)
tmp_file.close()
shutil.move(tmp_file.name, path)
os.chmod(path, 0644)
os.chmod(path, 0o644)
return
if os.path.exists('/etc/ceph'):
with open(path, 'w') as f:
f.write(conf)
os.chmod(path, 0644)
os.chmod(path, 0o644)
else:
err_msg = '/etc/ceph/ does not exist - could not write config'
raise RuntimeError(err_msg)
Expand Down Expand Up @@ -207,10 +207,10 @@ def unlink(_file):

def write_monitor_keyring(keyring, monitor_keyring, uid=-1, gid=-1):
"""create the monitor keyring file"""
write_file(keyring, monitor_keyring, 0600, None, uid, gid)
write_file(keyring, monitor_keyring, 0o600, None, uid, gid)


def write_file(path, content, mode=0644, directory=None, uid=-1, gid=-1):
def write_file(path, content, mode=0o644, directory=None, uid=-1, gid=-1):
if directory:
if path.startswith("/"):
path = path[1:]
Expand Down Expand Up @@ -297,7 +297,7 @@ def make_mon_removed_dir(path, file_name):
""" move old monitor data """
try:
os.makedirs('/var/lib/ceph/mon-removed')
except OSError, e:
except OSError as e:
if e.errno != errno.EEXIST:
raise
shutil.move(path, os.path.join('/var/lib/ceph/mon-removed/', file_name))
Expand All @@ -307,7 +307,7 @@ def safe_mkdir(path, uid=-1, gid=-1):
""" create path if it doesn't exist """
try:
os.mkdir(path)
except OSError, e:
except OSError as e:
if e.errno == errno.EEXIST:
pass
else:
Expand All @@ -319,7 +319,7 @@ def safe_makedirs(path, uid=-1, gid=-1):
""" create path recursively if it doesn't exist """
try:
os.makedirs(path)
except OSError, e:
except OSError as e:
if e.errno == errno.EEXIST:
pass
else:
Expand Down
4 changes: 2 additions & 2 deletions ceph_deploy/new.py
Expand Up @@ -216,11 +216,11 @@ def new_mon_keyring(args):
keypath = '{name}.mon.keyring'.format(
name=args.cluster,
)
oldmask = os.umask(077)
oldmask = os.umask(0o77)
LOG.debug('Writing monitor keyring to %s...', keypath)
try:
tmp = '%s.tmp' % keypath
with open(tmp, 'w', 0600) as f:
with open(tmp, 'w', 0o600) as f:
f.write(mon_keyring)
try:
os.rename(tmp, keypath)
Expand Down
6 changes: 3 additions & 3 deletions ceph_deploy/tests/test_cli_admin.py
Expand Up @@ -44,7 +44,7 @@ def test_write_keyring(tmpdir):

distro = MagicMock()
distro.conn = MagicMock()
remotes.write_file.func_defaults = (0644, str(tmpdir), -1, -1)
remotes.write_file.func_defaults = (0o644, str(tmpdir), -1, -1)
distro.conn.remote_module = remotes
distro.conn.remote_module.write_conf = Mock()

Expand All @@ -56,5 +56,5 @@ def test_write_keyring(tmpdir):
keyring_file = os.path.join(etc_ceph, 'ceph.client.admin.keyring')
assert os.path.exists(keyring_file)

file_mode = oct(os.stat(keyring_file).st_mode & 0777)
assert file_mode == oct(0600)
file_mode = oct(os.stat(keyring_file).st_mode & 0o777)
assert file_mode == oct(0o600)
4 changes: 2 additions & 2 deletions ceph_deploy/util/pkg_managers.py
Expand Up @@ -241,9 +241,9 @@ def add_repo(self, name, url, **kw):
self.add_repo_gpg_key(gpg_url)

safe_filename = '%s.list' % name.replace(' ', '-')
mode = 0644
mode = 0o644
if urlparse(url).password:
mode = 0600
mode = 0o600
self.remote_conn.logger.info(
"Creating repo file with mode 0600 due to presence of password"
)
Expand Down
16 changes: 9 additions & 7 deletions vendor.py
@@ -1,3 +1,5 @@
from __future__ import print_function

import subprocess
import os
from os import path
Expand All @@ -15,7 +17,7 @@


def run(cmd):
print '[vendoring] Running command: %s' % ' '.join(cmd)
print('[vendoring] Running command: %s' % ' '.join(cmd))
try:
result = subprocess.Popen(
cmd,
Expand All @@ -35,13 +37,13 @@ def run(cmd):


def print_error(stdout, stderr):
print '*'*80
print error_msg
print('*'*80)
print(error_msg)
for line in stdout:
print line
print(line)
for line in stderr:
print line
print '*'*80
print(line)
print('*'*80)


def vendor_library(name, version, cmd=None):
Expand All @@ -68,7 +70,7 @@ def vendor_library(name, version, cmd=None):
if not path.exists(vendor_dest):
rc = run(['git', 'clone', 'git://git.ceph.com/%s' % name])
if rc:
print "%s: git clone failed using ceph.com url with rc %s, trying github.com" % (path.basename(__file__), rc)
print("%s: git clone failed using ceph.com url with rc %s, trying github.com" % (path.basename(__file__), rc))
run(['git', 'clone', 'https://github.com/ceph/%s.git' % name])
os.chdir(vendor_src)
run(['git', 'checkout', version])
Expand Down

0 comments on commit e2a60a3

Please sign in to comment.