Commit 39b63e08 authored by Marco Mariani's avatar Marco Mariani

octal cleanup

parent ede11c8e
......@@ -50,7 +50,7 @@ from slapos.grid.exception import (BuildoutFailedError, WrongPermissionError,
from slapos.grid.networkcache import download_network_cached, upload_network_cached
from slapos.grid.watchdog import getWatchdogID
REQUIRED_COMPUTER_PARTITION_PERMISSION = '0750'
REQUIRED_COMPUTER_PARTITION_PERMISSION = 0o750
class Software(object):
......@@ -227,7 +227,7 @@ class Software(object):
if func == os.path.islink:
os.unlink(path)
else:
os.chmod(path, 0600)
os.chmod(path, 0o600)
func(path)
try:
if os.path.exists(self.software_path):
......@@ -297,7 +297,7 @@ class Partition(object):
open(self.key_file, 'w').write(partition_certificate['key'])
open(self.cert_file, 'w').write(partition_certificate['certificate'])
for f in [self.key_file, self.cert_file]:
os.chmod(f, 0400)
os.chmod(f, 0o400)
os.chown(f, *self.getUserGroupId())
def getUserGroupId(self):
......@@ -352,13 +352,12 @@ class Partition(object):
self.updateSymlink(sr_symlink, self.software_path)
instance_stat_info = os.stat(self.instance_path)
permission = oct(stat.S_IMODE(instance_stat_info.st_mode))
permission = stat.S_IMODE(instance_stat_info.st_mode)
if permission != REQUIRED_COMPUTER_PARTITION_PERMISSION:
raise WrongPermissionError('Wrong permissions in %s : actual ' \
'permissions are : %s, wanted ' \
'are %s' %
(self.instance_path, permission,
REQUIRED_COMPUTER_PARTITION_PERMISSION))
raise WrongPermissionError('Wrong permissions in %s: actual '
'permissions are: 0%o, wanted are 0%o' %
(self.instance_path, permission,
REQUIRED_COMPUTER_PARTITION_PERMISSION))
os.environ = getCleanEnvironment(pwd.getpwuid(
instance_stat_info.st_uid).pw_dir)
# Generates buildout part from template
......@@ -386,7 +385,7 @@ class Partition(object):
cert_file=self.cert_file
)
open(config_location, 'w').write(buildout_text)
os.chmod(config_location, 0640)
os.chmod(config_location, 0o640)
# Try to find the best possible buildout:
# *) if software_root/bin/bootstrap exists use this one to bootstrap
# locally
......@@ -444,7 +443,7 @@ class Partition(object):
# check if CP/etc/run exists and it is a directory
# iterate over each file in CP/etc/run
# iterate over each file in CP/etc/service adding WatchdogID to their name
# if at least one is not 0750 raise -- partition has something funny
# if at least one is not 0o750 raise -- partition has something funny
runner_list = []
service_list = []
if os.path.exists(self.run_path):
......
......@@ -41,7 +41,7 @@ from hashlib import md5
# Such umask by default will create paths with full permission
# for user, non writable by group and not accessible by others
SAFE_UMASK = 027
SAFE_UMASK = 0o27
PYTHON_ENVIRONMENT_REMOVE_LIST = [
'PYTHONHOME',
......@@ -331,7 +331,7 @@ def launchBuildout(path, buildout_binary,
logger.debug('Restore umask from %03o to %03o' % (old_umask, umask))
def updateFile(file_path, content, mode='0600'):
def updateFile(file_path, content, mode=0o600):
"""Creates an executable with "content" as content."""
altered = False
if not (os.path.isfile(file_path)) or \
......@@ -343,15 +343,15 @@ def updateFile(file_path, content, mode='0600'):
file_file.flush()
file_file.close()
os.chmod(file_path, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)
if oct(stat.S_IMODE(os.stat(file_path).st_mode)) != mode:
os.chmod(file_path, int(mode, 8))
if stat.S_IMODE(os.stat(file_path).st_mode) != mode:
os.chmod(file_path, mode)
altered = True
return altered
def updateExecutable(executable_path, content):
"""Creates an executable with "content" as content."""
return updateFile(executable_path, content, '0700')
return updateFile(executable_path, content, 0o700)
def createPrivateDirectory(path):
......@@ -359,8 +359,8 @@ def createPrivateDirectory(path):
if not os.path.isdir(path):
os.mkdir(path)
os.chmod(path, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)
permission = oct(stat.S_IMODE(os.stat(path).st_mode))
if permission not in ('0700'):
raise WrongPermissionError('Wrong permissions in %s ' \
': is %s, should be 0700'
% (path, permission))
permission = stat.S_IMODE(os.stat(path).st_mode)
if permission != 0o700:
raise WrongPermissionError('Wrong permissions in %s: ' \
'is 0%o, should be 0700'
% (path, permission))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment