Improve logging of set_configs.py
Remove duplicate logging for file copying, and clarify some log messages. Change-Id: I4dfaffa62f79a32a7fd6060b92ccb119f657f854
This commit is contained in:
parent
f26b1ba0b3
commit
39daa5a452
|
@ -74,16 +74,16 @@ class ConfigFile(object):
|
||||||
def _copy_file(self, source, dest):
|
def _copy_file(self, source, dest):
|
||||||
self._delete_path(dest)
|
self._delete_path(dest)
|
||||||
# dest endswith / means copy the <source> to <dest> folder
|
# dest endswith / means copy the <source> to <dest> folder
|
||||||
LOG.info('Copying file from %s to %s', source, dest)
|
LOG.info('Copying %s to %s', source, dest)
|
||||||
shutil.copy(source, dest)
|
shutil.copy(source, dest)
|
||||||
self._set_properties(source, dest)
|
self._set_properties(source, dest)
|
||||||
|
|
||||||
def _merge_directories(self, source, dest):
|
def _merge_directories(self, source, dest):
|
||||||
LOG.info('Copying %s to %s', source, dest)
|
|
||||||
if os.path.isdir(source):
|
if os.path.isdir(source):
|
||||||
if os.path.exists(dest) and not os.path.isdir(dest):
|
if os.path.exists(dest) and not os.path.isdir(dest):
|
||||||
self._delete_path(dest)
|
self._delete_path(dest)
|
||||||
if not os.path.isdir(dest):
|
if not os.path.isdir(dest):
|
||||||
|
LOG.info('Creating directory %s', dest)
|
||||||
os.makedirs(dest)
|
os.makedirs(dest)
|
||||||
self._set_properties(source, dest)
|
self._set_properties(source, dest)
|
||||||
|
|
||||||
|
@ -97,11 +97,10 @@ class ConfigFile(object):
|
||||||
def _delete_path(self, path):
|
def _delete_path(self, path):
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
return
|
return
|
||||||
|
LOG.info('Deleting %s', path)
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
LOG.info('Deleting dir %s', path)
|
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
else:
|
else:
|
||||||
LOG.info('Deleting file %s', path)
|
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
|
|
||||||
def _create_parent_dirs(self, path):
|
def _create_parent_dirs(self, path):
|
||||||
|
@ -188,7 +187,7 @@ class ConfigFile(object):
|
||||||
actual_perm = oct(dir_stat.st_mode)[-4:]
|
actual_perm = oct(dir_stat.st_mode)[-4:]
|
||||||
if self.perm != actual_perm:
|
if self.perm != actual_perm:
|
||||||
LOG.error('Dest dir does not have expected perm: %s,'
|
LOG.error('Dest dir does not have expected perm: %s,'
|
||||||
' acutal %s', self.perm, actual_perm)
|
' actual %s', self.perm, actual_perm)
|
||||||
return False
|
return False
|
||||||
for file_ in files:
|
for file_ in files:
|
||||||
full_path = os.path.join(root, file_)
|
full_path = os.path.join(root, file_)
|
||||||
|
@ -334,13 +333,14 @@ def handle_permissions(config):
|
||||||
def set_perms(path, uid, gid, perm):
|
def set_perms(path, uid, gid, perm):
|
||||||
LOG.info('Setting permission for %s', path)
|
LOG.info('Setting permission for %s', path)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
LOG.warning('file %s do not exist', path)
|
LOG.warning('%s does not exist', path)
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.chown(path, uid, gid)
|
os.chown(path, uid, gid)
|
||||||
except OSError:
|
except OSError:
|
||||||
LOG.exception('Set permission failed for %s', path)
|
LOG.exception('Failed to change ownership of %s to %s:%s',
|
||||||
|
path, uid, gid)
|
||||||
|
|
||||||
if perm:
|
if perm:
|
||||||
# NOTE(Jeffrey4l): py3 need '0oXXX' format for octal literals,
|
# NOTE(Jeffrey4l): py3 need '0oXXX' format for octal literals,
|
||||||
|
@ -352,7 +352,8 @@ def handle_permissions(config):
|
||||||
try:
|
try:
|
||||||
os.chmod(path, perm)
|
os.chmod(path, perm)
|
||||||
except OSError:
|
except OSError:
|
||||||
LOG.exception('Set permission failed for %s', path)
|
LOG.exception('Failed to set permission of %s to %s',
|
||||||
|
path, perm)
|
||||||
|
|
||||||
for dest in glob.glob(path):
|
for dest in glob.glob(path):
|
||||||
set_perms(dest, uid, gid, perm)
|
set_perms(dest, uid, gid, perm)
|
||||||
|
|
Loading…
Reference in New Issue